You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
manager: proper alphabetical module list sorting
This commit is contained in:
@@ -120,8 +120,8 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (viewModel.moduleList.isEmpty() || viewModel.isNeedRefresh) {
|
||||
viewModel.sortEnabledFirst = prefs.getBoolean("module_sort_enabled_first", false)
|
||||
viewModel.sortActionFirst = prefs.getBoolean("module_sort_action_first", false)
|
||||
viewModel.sortAToZ = prefs.getBoolean("module_sort_a_to_z", true)
|
||||
viewModel.sortZToA = prefs.getBoolean("module_sort_z_to_a", false)
|
||||
viewModel.fetchModuleList()
|
||||
}
|
||||
}
|
||||
@@ -152,43 +152,56 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
imageVector = Icons.Filled.MoreVert,
|
||||
contentDescription = stringResource(id = R.string.settings)
|
||||
)
|
||||
DropdownMenu(expanded = showDropdown, onDismissRequest = {
|
||||
showDropdown = false
|
||||
}) {
|
||||
DropdownMenuItem(text = {
|
||||
Text(stringResource(R.string.module_sort_action_first))
|
||||
}, trailingIcon = {
|
||||
Checkbox(viewModel.sortActionFirst, null)
|
||||
}, onClick = {
|
||||
viewModel.sortActionFirst =
|
||||
!viewModel.sortActionFirst
|
||||
prefs.edit()
|
||||
.putBoolean(
|
||||
"module_sort_action_first",
|
||||
viewModel.sortActionFirst
|
||||
)
|
||||
.apply()
|
||||
scope.launch {
|
||||
viewModel.fetchModuleList()
|
||||
DropdownMenu(
|
||||
expanded = showDropdown,
|
||||
onDismissRequest = {
|
||||
showDropdown = false
|
||||
}
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text(stringResource(R.string.module_sort_a_to_z))
|
||||
},
|
||||
trailingIcon = {
|
||||
Checkbox(checked = viewModel.sortAToZ, onCheckedChange = null)
|
||||
},
|
||||
onClick = {
|
||||
if (viewModel.sortAToZ) {
|
||||
viewModel.sortAToZ = false
|
||||
} else {
|
||||
viewModel.sortAToZ = true
|
||||
viewModel.sortZToA = false
|
||||
}
|
||||
prefs.edit()
|
||||
.putBoolean("module_sort_a_to_z", viewModel.sortAToZ)
|
||||
.apply()
|
||||
scope.launch {
|
||||
viewModel.fetchModuleList()
|
||||
}
|
||||
}
|
||||
})
|
||||
DropdownMenuItem(text = {
|
||||
Text(stringResource(R.string.module_sort_enabled_first))
|
||||
}, trailingIcon = {
|
||||
Checkbox(viewModel.sortEnabledFirst, null)
|
||||
}, onClick = {
|
||||
viewModel.sortEnabledFirst =
|
||||
!viewModel.sortEnabledFirst
|
||||
prefs.edit()
|
||||
.putBoolean(
|
||||
"module_sort_enabled_first",
|
||||
viewModel.sortEnabledFirst
|
||||
)
|
||||
.apply()
|
||||
scope.launch {
|
||||
viewModel.fetchModuleList()
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text(stringResource(R.string.module_sort_z_to_a))
|
||||
},
|
||||
trailingIcon = {
|
||||
Checkbox(checked = viewModel.sortZToA, onCheckedChange = null)
|
||||
},
|
||||
onClick = {
|
||||
if (viewModel.sortZToA) {
|
||||
viewModel.sortZToA = false
|
||||
} else {
|
||||
viewModel.sortZToA = true
|
||||
viewModel.sortAToZ = false
|
||||
}
|
||||
prefs.edit()
|
||||
.putBoolean("module_sort_z_to_a", viewModel.sortZToA)
|
||||
.apply()
|
||||
scope.launch {
|
||||
viewModel.fetchModuleList()
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -574,7 +587,7 @@ private fun ModuleList(
|
||||
}
|
||||
},
|
||||
onClick = {
|
||||
onClickModule(it.id, it.name, it.hasWebUi)
|
||||
onClickModule(it.dirId, it.name, it.hasWebUi)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -51,19 +51,21 @@ class ModuleViewModel : ViewModel() {
|
||||
var isRefreshing by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
var sortEnabledFirst by mutableStateOf(false)
|
||||
var sortActionFirst by mutableStateOf(false)
|
||||
var sortAToZ by mutableStateOf(false)
|
||||
var sortZToA by mutableStateOf(false)
|
||||
|
||||
val moduleList by derivedStateOf {
|
||||
val comparator =
|
||||
compareBy<ModuleInfo>(
|
||||
{ if (sortEnabledFirst) !it.enabled else 0 },
|
||||
{ if (sortActionFirst) !it.hasWebUi && !it.hasActionScript else 0 },
|
||||
{ it.id })
|
||||
val comparator = when {
|
||||
sortAToZ -> compareBy<ModuleInfo> { it.name.lowercase() }
|
||||
sortZToA -> compareByDescending<ModuleInfo> { it.name.lowercase() }
|
||||
else -> compareBy<ModuleInfo> { it.dirId }
|
||||
}
|
||||
modules.sortedWith(comparator).also {
|
||||
isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isNeedRefresh by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
<string name="module">Modul</string>
|
||||
<string name="confirm_module_installation">Yakin instal</string>
|
||||
<string name="module_install_prompt_with_name">Anda ingin melanjutkan pemasangan modul %1$s?</string>
|
||||
<string name="module_sort_a_to_z">Menyortir (A - Z)</string>
|
||||
<string name="module_sort_z_to_a">Menyortir (Z - A)</string>
|
||||
<string name="uninstall">Hapus</string>
|
||||
<string name="restore">Pulihkan</string>
|
||||
<string name="module_install">Instal</string>
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
<string name="module">模块</string>
|
||||
<string name="confirm_module_installation">确认安装</string>
|
||||
<string name="module_install_prompt_with_name">是否要继续安装模块 %1$s ?</string>
|
||||
<string name="module_sort_action_first">可执行优先</string>
|
||||
<string name="module_sort_enabled_first">已启用优先</string>
|
||||
<string name="module_sort_a_to_z">种类 (A - Z)</string>
|
||||
<string name="module_sort_z_to_a">种类 (Z - A)</string>
|
||||
<string name="uninstall">卸载</string>
|
||||
<string name="restore">重启</string>
|
||||
<string name="module_install">安装</string>
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
<string name="module">Module</string>
|
||||
<string name="confirm_module_installation">Confirm Installation</string>
|
||||
<string name="module_install_prompt_with_name">Do you want to continue installing module %1$s?</string>
|
||||
<string name="module_sort_action_first">Sort (Action First)</string>
|
||||
<string name="module_sort_enabled_first">Sort (Enabled First)</string>
|
||||
<string name="module_sort_a_to_z">Sort (A - Z)</string>
|
||||
<string name="module_sort_z_to_a">Sort (Z - A)</string>
|
||||
<string name="uninstall">Uninstall</string>
|
||||
<string name="restore">Restore</string>
|
||||
<string name="module_install">Install</string>
|
||||
|
||||
Reference in New Issue
Block a user