-
Notifications
You must be signed in to change notification settings - Fork 41
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
1 parent
562826c
commit 7dd1a5c
Showing
3 changed files
with
172 additions
and
3 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
111 changes: 111 additions & 0 deletions
111
...rc/main/kotlin/com/aliucord/manager/ui/components/dialogs/CustomComponentVersionPicker.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,111 @@ | ||
package com.aliucord.manager.ui.components.dialogs | ||
|
||
import androidx.compose.foundation.* | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.DialogProperties | ||
import com.aliucord.manager.R | ||
import com.aliucord.manager.network.utils.SemVer | ||
|
||
@Composable | ||
fun CustomComponentVersionPicker( | ||
componentTitle: String, | ||
versions: List<SemVer>, | ||
onConfirm: (SemVer) -> Unit, | ||
onDelete: (SemVer) -> Unit, | ||
onCancel: () -> Unit, | ||
) { | ||
var selectedVersion by remember { mutableStateOf<SemVer?>(null) } | ||
|
||
AlertDialog( | ||
properties = DialogProperties( | ||
dismissOnBackPress = true, | ||
dismissOnClickOutside = false, | ||
), | ||
onDismissRequest = onCancel, | ||
confirmButton = { | ||
FilledTonalButton( | ||
onClick = { onConfirm(selectedVersion!!) }, | ||
enabled = selectedVersion != null, | ||
colors = ButtonDefaults.filledTonalButtonColors( | ||
containerColor = MaterialTheme.colorScheme.primary, | ||
contentColor = MaterialTheme.colorScheme.onPrimary, | ||
), | ||
) { | ||
Text(stringResource(R.string.action_confirm)) | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton( | ||
onClick = onCancel, | ||
colors = ButtonDefaults.textButtonColors( | ||
contentColor = MaterialTheme.colorScheme.error, | ||
), | ||
) { | ||
Text(stringResource(R.string.action_dismiss)) | ||
} | ||
}, | ||
title = { Text("Custom Component") }, | ||
icon = { Icon(painterResource(R.drawable.ic_download), contentDescription = null) }, | ||
text = { | ||
Column { | ||
Text( | ||
text = "A custom local version for a patching component ($componentTitle) has been found. Would you like to use it?", | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier.padding(bottom = 6.dp), | ||
) | ||
|
||
Column( | ||
verticalArrangement = Arrangement.spacedBy(6.dp), | ||
modifier = Modifier.verticalScroll(rememberScrollState()) | ||
) { | ||
for (version in versions) key(version) { | ||
val clickSource = remember(::MutableInteractionSource) | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(12.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.clickable( | ||
interactionSource = clickSource, | ||
indication = LocalIndication.current, | ||
onClick = { selectedVersion = version }, | ||
), | ||
) { | ||
RadioButton( | ||
selected = selectedVersion == version, | ||
onClick = { selectedVersion = version }, | ||
interactionSource = clickSource, | ||
) | ||
|
||
Text( | ||
text = "v$version", | ||
style = MaterialTheme.typography.bodyLarge.copy(fontWeight = FontWeight.SemiBold), | ||
) | ||
|
||
Spacer(Modifier.weight(1f)) | ||
IconButton( | ||
onClick = { onDelete(version) }, | ||
) { | ||
Icon( | ||
painter = painterResource(R.drawable.ic_delete_forever), | ||
tint = MaterialTheme.colorScheme.error, | ||
contentDescription = null, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
) | ||
} |