@@ -32,17 +32,22 @@ import androidx.compose.foundation.selection.toggleable
32
32
import androidx.compose.material.icons.Icons
33
33
import androidx.compose.material.icons.automirrored.outlined.Wysiwyg
34
34
import androidx.compose.material.icons.filled.Add
35
+ import androidx.compose.material.icons.filled.MoreVert
35
36
import androidx.compose.material.icons.outlined.PlayArrow
36
37
import androidx.compose.material.icons.outlined.Download
37
38
import androidx.compose.material.icons.outlined.Delete
38
39
import androidx.compose.material3.Button
39
40
import androidx.compose.material3.ButtonDefaults
41
+ import androidx.compose.material3.Checkbox
42
+ import androidx.compose.material3.DropdownMenu
43
+ import androidx.compose.material3.DropdownMenuItem
40
44
import androidx.compose.material3.ElevatedCard
41
45
import androidx.compose.material3.ExperimentalMaterial3Api
42
46
import androidx.compose.material3.ExtendedFloatingActionButton
43
47
import androidx.compose.material3.FilledTonalButton
44
48
import androidx.compose.material3.HorizontalDivider
45
49
import androidx.compose.material3.Icon
50
+ import androidx.compose.material3.IconButton
46
51
import androidx.compose.material3.MaterialTheme
47
52
import androidx.compose.material3.Scaffold
48
53
import androidx.compose.material3.SnackbarDuration
@@ -110,9 +115,13 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
110
115
val viewModel = viewModel<ModuleViewModel >()
111
116
val context = LocalContext .current
112
117
val snackBarHost = LocalSnackbarHost .current
118
+ val scope = rememberCoroutineScope()
119
+ val prefs = context.getSharedPreferences(" settings" , Context .MODE_PRIVATE )
113
120
114
121
LaunchedEffect (Unit ) {
115
122
if (viewModel.moduleList.isEmpty() || viewModel.isNeedRefresh) {
123
+ viewModel.sortEnabledFirst = prefs.getBoolean(" module_sort_enabled_first" , false )
124
+ viewModel.sortActionFirst = prefs.getBoolean(" module_sort_action_first" , false )
116
125
viewModel.fetchModuleList()
117
126
}
118
127
}
@@ -127,6 +136,57 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
127
136
Scaffold (
128
137
topBar = {
129
138
TopAppBar (
139
+ actions = {
140
+ var showDropdown by remember { mutableStateOf(false ) }
141
+
142
+ IconButton (
143
+ onClick = { showDropdown = true },
144
+ ) {
145
+ Icon (
146
+ imageVector = Icons .Filled .MoreVert ,
147
+ contentDescription = stringResource(id = R .string.settings)
148
+ )
149
+
150
+ DropdownMenu (expanded = showDropdown, onDismissRequest = {
151
+ showDropdown = false
152
+ }) {
153
+ DropdownMenuItem (text = {
154
+ Text (stringResource(R .string.module_sort_action_first))
155
+ }, trailingIcon = {
156
+ Checkbox (viewModel.sortActionFirst, null )
157
+ }, onClick = {
158
+ viewModel.sortActionFirst =
159
+ ! viewModel.sortActionFirst
160
+ prefs.edit()
161
+ .putBoolean(
162
+ " module_sort_action_first" ,
163
+ viewModel.sortActionFirst
164
+ )
165
+ .apply ()
166
+ scope.launch {
167
+ viewModel.fetchModuleList()
168
+ }
169
+ })
170
+ DropdownMenuItem (text = {
171
+ Text (stringResource(R .string.module_sort_enabled_first))
172
+ }, trailingIcon = {
173
+ Checkbox (viewModel.sortEnabledFirst, null )
174
+ }, onClick = {
175
+ viewModel.sortEnabledFirst =
176
+ ! viewModel.sortEnabledFirst
177
+ prefs.edit()
178
+ .putBoolean(
179
+ " module_sort_enabled_first" ,
180
+ viewModel.sortEnabledFirst
181
+ )
182
+ .apply ()
183
+ scope.launch {
184
+ viewModel.fetchModuleList()
185
+ }
186
+ })
187
+ }
188
+ }
189
+ },
130
190
scrollBehavior = scrollBehavior,
131
191
title = { Text (stringResource(R .string.module)) },
132
192
windowInsets = WindowInsets .safeDrawing.only(WindowInsetsSides .Top + WindowInsetsSides .Horizontal )
@@ -493,8 +553,8 @@ fun ModuleItem(
493
553
onValueChange = { onClick(module) }
494
554
)
495
555
} else {
496
- this
497
- }
556
+ this
557
+ }
498
558
}
499
559
.padding(22 .dp, 18 .dp, 22 .dp, 12 .dp)
500
560
) {
@@ -577,24 +637,24 @@ fun ModuleItem(
577
637
FilledTonalButton (
578
638
modifier = Modifier .defaultMinSize(52 .dp, 32 .dp),
579
639
onClick = {
580
- navigator.navigate(ExecuteModuleActionScreenDestination (module.id))
581
- viewModel.markNeedRefresh()
640
+ navigator.navigate(ExecuteModuleActionScreenDestination (module.id))
641
+ viewModel.markNeedRefresh()
582
642
},
583
643
contentPadding = ButtonDefaults .TextButtonContentPadding
584
644
) {
585
645
Icon (
586
- modifier = Modifier .size(20 .dp),
646
+ modifier = Modifier .size(20 .dp),
587
647
imageVector = Icons .Outlined .PlayArrow ,
588
648
contentDescription = null
589
649
)
590
- if (! module.hasWebUi && updateUrl.isEmpty()) {
650
+ if (! module.hasWebUi && updateUrl.isEmpty()) {
591
651
Text (
592
- modifier = Modifier .padding(start = 7 .dp),
652
+ modifier = Modifier .padding(start = 7 .dp),
593
653
text = stringResource(R .string.action),
594
654
fontFamily = MaterialTheme .typography.labelMedium.fontFamily,
595
655
fontSize = MaterialTheme .typography.labelMedium.fontSize
596
656
)
597
- }
657
+ }
598
658
}
599
659
600
660
Spacer (modifier = Modifier .weight(0.1f , true ))
@@ -608,16 +668,16 @@ fun ModuleItem(
608
668
contentPadding = ButtonDefaults .TextButtonContentPadding
609
669
) {
610
670
Icon (
611
- modifier = Modifier .size(20 .dp),
671
+ modifier = Modifier .size(20 .dp),
612
672
imageVector = Icons .AutoMirrored .Outlined .Wysiwyg ,
613
673
contentDescription = null
614
674
)
615
675
if (! module.hasActionScript && updateUrl.isEmpty()) {
616
676
Text (
617
- modifier = Modifier .padding(start = 7 .dp),
618
- fontFamily = MaterialTheme .typography.labelMedium.fontFamily,
619
- fontSize = MaterialTheme .typography.labelMedium.fontSize,
620
- text = stringResource(R .string.open)
677
+ modifier = Modifier .padding(start = 7 .dp),
678
+ fontFamily = MaterialTheme .typography.labelMedium.fontFamily,
679
+ fontSize = MaterialTheme .typography.labelMedium.fontSize,
680
+ text = stringResource(R .string.open)
621
681
)
622
682
}
623
683
}
@@ -632,19 +692,19 @@ fun ModuleItem(
632
692
shape = ButtonDefaults .textShape,
633
693
contentPadding = ButtonDefaults .TextButtonContentPadding
634
694
) {
635
- Icon (
636
- modifier = Modifier .size(20 .dp),
637
- imageVector = Icons .Outlined .Download ,
638
- contentDescription = null
639
- )
640
- if (! module.hasActionScript || ! module.hasWebUi) {
695
+ Icon (
696
+ modifier = Modifier .size(20 .dp),
697
+ imageVector = Icons .Outlined .Download ,
698
+ contentDescription = null
699
+ )
700
+ if (! module.hasActionScript || ! module.hasWebUi) {
641
701
Text (
642
- modifier = Modifier .padding(start = 7 .dp),
702
+ modifier = Modifier .padding(start = 7 .dp),
643
703
fontFamily = MaterialTheme .typography.labelMedium.fontFamily,
644
704
fontSize = MaterialTheme .typography.labelMedium.fontSize,
645
705
text = stringResource(R .string.module_update)
646
706
)
647
- }
707
+ }
648
708
}
649
709
650
710
Spacer (modifier = Modifier .weight(0.1f , true ))
@@ -656,19 +716,19 @@ fun ModuleItem(
656
716
onClick = { onUninstall(module) },
657
717
contentPadding = ButtonDefaults .TextButtonContentPadding
658
718
) {
659
- Icon (
660
- modifier = Modifier .size(20 .dp),
661
- imageVector = Icons .Outlined .Delete ,
662
- contentDescription = null
663
- )
664
- if (! module.hasActionScript && ! module.hasWebUi && updateUrl.isEmpty()) {
665
- Text (
666
- modifier = Modifier .padding(start = 7 .dp),
719
+ Icon (
720
+ modifier = Modifier .size(20 .dp),
721
+ imageVector = Icons .Outlined .Delete ,
722
+ contentDescription = null
723
+ )
724
+ if (! module.hasActionScript && ! module.hasWebUi && updateUrl.isEmpty()) {
725
+ Text (
726
+ modifier = Modifier .padding(start = 7 .dp),
667
727
fontFamily = MaterialTheme .typography.labelMedium.fontFamily,
668
728
fontSize = MaterialTheme .typography.labelMedium.fontSize,
669
729
text = stringResource(R .string.uninstall)
670
730
)
671
- }
731
+ }
672
732
}
673
733
}
674
734
}
0 commit comments