Skip to content

Commit

Permalink
feat: 替换管理
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Aug 29, 2023
1 parent 8f8bebe commit 96d72cc
Show file tree
Hide file tree
Showing 37 changed files with 1,692 additions and 250 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

//noinspection GradleDependency
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
android:theme="@style/Theme.TtsServer"
android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute">
<activity
android:name=".compose.systts.replace.ReplaceManagerActivity"
android:exported="true"
android:label="@string/replace_rule_manager"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".compose.systts.directlink.LinkUploadRuleActivity"
android:exported="true"
Expand Down Expand Up @@ -160,16 +165,6 @@

</activity>

<activity
android:name=".ui.systts.replace.ReplaceManagerActivity"
android:exported="true"
android:label="@string/title_activity_replace_manager"
android:theme="@style/Theme.TtsServer.NoActionBar" />
<activity
android:name=".ui.systts.replace.ReplaceRuleEditActivity"
android:label="@string/title_activity_replace_edit"
android:launchMode="singleTask"
android:theme="@style/Theme.TtsServer.NoActionBar" />
<activity
android:name=".ui.forwarder.MsForwarderSwitchActivity"
android:taskAffinity="sc.switch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fun ConfigExportBottomSheet(
) {
Text(
text = json,
Modifier.width(1000.dp),
Modifier.size(2000.dp), // compose Can't represent a size of xxx in Constraints
style = MaterialTheme.typography.bodySmall,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.github.jing332.tts_server_android.compose.systts

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DeleteForever
import androidx.compose.material.icons.filled.ExpandCircleDown
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Output
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TriStateCheckbox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.state.ToggleableState
import androidx.compose.ui.unit.dp
import com.github.jing332.tts_server_android.R

fun Int.sizeToToggleableState(total:Int): ToggleableState = when (this) {
0 -> ToggleableState.Off
total -> ToggleableState.On
else -> ToggleableState.Indeterminate
}

@Composable
fun GroupItem(
modifier: Modifier,
isExpanded: Boolean,
name: String,
toggleableState: ToggleableState,
onToggleableStateChange: (Boolean) -> Unit,
onClick: () -> Unit,
onExport: () -> Unit,
onDelete: () -> Unit,
actions: @Composable ColumnScope.(() -> Unit) -> Unit,
) {
var showDeleteDialog by remember { mutableStateOf(false) }
if (showDeleteDialog)
ConfigDeleteDialog(
onDismissRequest = { showDeleteDialog = false }, name = name, onConfirm = onDelete
)


Row(
modifier = modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.surface)
.clickable(
onClickLabel = stringResource(
id = if (isExpanded) R.string.desc_collapse_group
else R.string.desc_expand_group, name
)
) { onClick() }
.padding(vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically
) {

val rotationAngle by animateFloatAsState(
targetValue = if (isExpanded) 0f else -45f,
label = ""
)
Icon(
Icons.Default.ExpandCircleDown,
contentDescription = stringResource(id = if (isExpanded) R.string.group_expanded else R.string.group_collapsed),
modifier = Modifier
.rotate(rotationAngle)
.graphicsLayer { rotationZ = rotationAngle }
)

Text(
name,
style = MaterialTheme.typography.titleLarge,
modifier = Modifier
.align(Alignment.CenterVertically)
.weight(1f)
)
Row {
TriStateCheckbox(state = toggleableState, onClick = {
onToggleableStateChange(toggleableState != ToggleableState.On)
})

var showOptions by remember { mutableStateOf(false) }
IconButton(onClick = { showOptions = true }) {
Icon(
Icons.Default.MoreVert,
contentDescription = stringResource(id = R.string.more_options)
)

DropdownMenu(expanded = showOptions, onDismissRequest = { showOptions = false }) {
actions { showOptions = false }

DropdownMenuItem(
text = { Text(stringResource(id = R.string.export_config)) },
onClick = onExport,
leadingIcon = {
Icon(Icons.Default.Output, null)
}
)

HorizontalDivider()

DropdownMenuItem(text = {
Text(
stringResource(id = R.string.delete),
color = MaterialTheme.colorScheme.error
)
},
leadingIcon = {
Icon(
Icons.Default.DeleteForever,
contentDescription = null,
tint = MaterialTheme.colorScheme.error
)
},
onClick = {
showOptions = false
showDeleteDialog = true
}
)
}
}
}

}
}
Loading

0 comments on commit 96d72cc

Please sign in to comment.