-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,692 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
app/src/main/java/com/github/jing332/tts_server_android/compose/systts/GroupItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.