@@ -14,7 +14,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
1414import androidx.compose.foundation.layout.fillMaxWidth
1515import androidx.compose.foundation.layout.padding
1616import androidx.compose.foundation.lazy.LazyColumn
17- import androidx.compose.foundation.lazy.LazyListItemInfo
1817import androidx.compose.foundation.lazy.items
1918import androidx.compose.foundation.lazy.itemsIndexed
2019import androidx.compose.foundation.lazy.rememberLazyListState
@@ -74,13 +73,11 @@ import app.revanced.manager.util.saver.snapshotStateListSaver
7473import app.revanced.manager.util.saver.snapshotStateSetSaver
7574import app.revanced.manager.util.toast
7675import app.revanced.manager.util.transparentListItemColors
77- import kotlinx.coroutines.CoroutineScope
7876import kotlinx.parcelize.Parcelize
7977import org.koin.compose.koinInject
8078import org.koin.core.component.KoinComponent
8179import org.koin.core.component.get
8280import sh.calvin.reorderable.ReorderableItem
83- import sh.calvin.reorderable.rememberReorderableLazyColumnState
8481import sh.calvin.reorderable.rememberReorderableLazyListState
8582import java.io.Serializable
8683import kotlin.random.Random
@@ -91,15 +88,28 @@ private class OptionEditorScope<T : Any>(
9188 val option : Option <T >,
9289 val openDialog : () -> Unit ,
9390 val dismissDialog : () -> Unit ,
91+ val selectionWarningEnabled : Boolean ,
92+ val showSelectionWarning : () -> Unit ,
9493 val value : T ? ,
95- val setValue : (T ? ) -> Unit ,
94+ val setValue : (T ? ) -> Unit
9695) {
9796 fun submitDialog (value : T ? ) {
9897 setValue(value)
9998 dismissDialog()
10099 }
101100
102- fun clickAction () = editor.clickAction(this )
101+ fun checkSafeguard (block : () -> Unit ) {
102+ if (! option.required && selectionWarningEnabled)
103+ showSelectionWarning()
104+ else
105+ block()
106+ }
107+
108+ fun clickAction () {
109+ checkSafeguard {
110+ editor.clickAction(this )
111+ }
112+ }
103113
104114 @Composable
105115 fun ListItemTrailingContent () = editor.ListItemTrailingContent (this )
@@ -113,7 +123,7 @@ private interface OptionEditor<T : Any> {
113123
114124 @Composable
115125 fun ListItemTrailingContent (scope : OptionEditorScope <T >) {
116- IconButton (onClick = { clickAction(scope) }) {
126+ IconButton (onClick = { scope.checkSafeguard { clickAction(scope) } }) {
117127 Icon (Icons .Outlined .Edit , stringResource(R .string.edit))
118128 }
119129 }
@@ -141,11 +151,14 @@ private inline fun <T : Any> WithOptionEditor(
141151 option : Option <T >,
142152 value : T ? ,
143153 noinline setValue : (T ? ) -> Unit ,
154+ selectionWarningEnabled : Boolean ,
144155 crossinline onDismissDialog : @DisallowComposableCalls () -> Unit = {},
145156 block : OptionEditorScope <T >.() -> Unit
146157) {
147158 var showDialog by rememberSaveable { mutableStateOf(false ) }
148- val scope = remember(editor, option, value, setValue) {
159+ var showSelectionWarningDialog by rememberSaveable { mutableStateOf(false ) }
160+
161+ val scope = remember(editor, option, value, setValue, selectionWarningEnabled) {
149162 OptionEditorScope (
150163 editor,
151164 option,
@@ -154,11 +167,18 @@ private inline fun <T : Any> WithOptionEditor(
154167 showDialog = false
155168 onDismissDialog()
156169 },
170+ selectionWarningEnabled,
171+ showSelectionWarning = { showSelectionWarningDialog = true },
157172 value,
158173 setValue
159174 )
160175 }
161176
177+ if (showSelectionWarningDialog)
178+ SelectionWarningDialog (
179+ onDismiss = { showSelectionWarningDialog = false }
180+ )
181+
162182 if (showDialog) scope.Dialog ()
163183
164184 scope.block()
@@ -169,6 +189,7 @@ fun <T : Any> OptionItem(
169189 option : Option <T >,
170190 value : T ? ,
171191 setValue : (T ? ) -> Unit ,
192+ selectionWarningEnabled : Boolean
172193) {
173194 val editor = remember(option.type, option.presets) {
174195 @Suppress(" UNCHECKED_CAST" )
@@ -181,7 +202,7 @@ fun <T : Any> OptionItem(
181202 else baseOptionEditor
182203 }
183204
184- WithOptionEditor (editor, option, value, setValue) {
205+ WithOptionEditor (editor, option, value, setValue, selectionWarningEnabled ) {
185206 ListItem (
186207 modifier = Modifier .clickable(onClick = ::clickAction),
187208 headlineContent = { Text (option.title) },
@@ -300,7 +321,7 @@ private object StringOptionEditor : OptionEditor<String> {
300321
301322private abstract class NumberOptionEditor <T : Number > : OptionEditor <T > {
302323 @Composable
303- protected abstract fun NumberDialog (
324+ abstract fun NumberDialog (
304325 title : String ,
305326 current : T ? ,
306327 validator : (T ? ) -> Boolean ,
@@ -354,7 +375,14 @@ private object BooleanOptionEditor : OptionEditor<Boolean> {
354375
355376 @Composable
356377 override fun ListItemTrailingContent (scope : OptionEditorScope <Boolean >) {
357- HapticSwitch (checked = scope.current, onCheckedChange = scope.setValue)
378+ HapticSwitch (
379+ checked = scope.current,
380+ onCheckedChange = { value ->
381+ scope.checkSafeguard {
382+ scope.setValue(value)
383+ }
384+ }
385+ )
358386 }
359387
360388 @Composable
@@ -393,6 +421,7 @@ private class PresetOptionEditor<T : Any>(private val innerEditor: OptionEditor<
393421 scope.option,
394422 scope.value,
395423 scope.setValue,
424+ scope.selectionWarningEnabled,
396425 onDismissDialog = scope.dismissDialog
397426 ) inner@{
398427 var hidePresetsDialog by rememberSaveable {
@@ -614,7 +643,8 @@ private class ListOptionEditor<T : Serializable>(private val elementEditor: Opti
614643 elementEditor,
615644 elementOption,
616645 value = item.value,
617- setValue = { items[index] = item.copy(value = it) }
646+ setValue = { items[index] = item.copy(value = it) },
647+ selectionWarningEnabled = scope.selectionWarningEnabled
618648 ) {
619649 ListItem (
620650 modifier = Modifier .combinedClickable(
0 commit comments