mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Add sort/filter popup menus to DenyList screen
Replace inline filter chips with LSPosed-style TopAppBar action icons: sort (by name, package name, install time, update time with reverse toggle) and filter (show system/OS apps with linked state). Search bar is always visible. Process rows now use Checkbox instead of Switch. Made-with: Cursor
This commit is contained in:
@@ -130,6 +130,7 @@ class MainActivity : UIActivity(), SplashScreenHost {
|
||||
}
|
||||
entry<Route.DenyList> { _ ->
|
||||
val vm: DenyListViewModel = androidx.lifecycle.viewmodel.compose.viewModel(factory = VMFactory)
|
||||
LaunchedEffect(Unit) { vm.startLoading() }
|
||||
ObserveViewEvents(vm)
|
||||
DenyListScreen(vm, onBack = { navigator.pop() })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.topjohnwu.magisk.ui.component
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.IntRect
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import top.yukonga.miuix.kmp.basic.PopupPositionProvider
|
||||
|
||||
object ListPopupDefaults {
|
||||
val MenuPositionProvider = object : PopupPositionProvider {
|
||||
override fun calculatePosition(
|
||||
anchorBounds: IntRect,
|
||||
windowBounds: IntRect,
|
||||
layoutDirection: LayoutDirection,
|
||||
popupContentSize: IntSize,
|
||||
popupMargin: IntRect,
|
||||
alignment: PopupPositionProvider.Align,
|
||||
): IntOffset {
|
||||
val resolved = alignment.resolve(layoutDirection)
|
||||
val offsetX: Int
|
||||
val offsetY: Int
|
||||
when (resolved) {
|
||||
PopupPositionProvider.Align.TopStart -> {
|
||||
offsetX = anchorBounds.left + popupMargin.left
|
||||
offsetY = anchorBounds.bottom + popupMargin.top
|
||||
}
|
||||
PopupPositionProvider.Align.TopEnd -> {
|
||||
offsetX = anchorBounds.right - popupContentSize.width - popupMargin.right
|
||||
offsetY = anchorBounds.bottom + popupMargin.top
|
||||
}
|
||||
PopupPositionProvider.Align.BottomStart -> {
|
||||
offsetX = anchorBounds.left + popupMargin.left
|
||||
offsetY = anchorBounds.top - popupContentSize.height - popupMargin.bottom
|
||||
}
|
||||
PopupPositionProvider.Align.BottomEnd -> {
|
||||
offsetX = anchorBounds.right - popupContentSize.width - popupMargin.right
|
||||
offsetY = anchorBounds.top - popupContentSize.height - popupMargin.bottom
|
||||
}
|
||||
else -> {
|
||||
offsetX = if (resolved == PopupPositionProvider.Align.End) {
|
||||
anchorBounds.right - popupContentSize.width - popupMargin.right
|
||||
} else {
|
||||
anchorBounds.left + popupMargin.left
|
||||
}
|
||||
offsetY = if (windowBounds.bottom - anchorBounds.bottom > popupContentSize.height) {
|
||||
anchorBounds.bottom + popupMargin.bottom
|
||||
} else if (anchorBounds.top - windowBounds.top > popupContentSize.height) {
|
||||
anchorBounds.top - popupContentSize.height - popupMargin.top
|
||||
} else {
|
||||
anchorBounds.top + anchorBounds.height / 2 - popupContentSize.height / 2
|
||||
}
|
||||
}
|
||||
}
|
||||
return IntOffset(
|
||||
x = offsetX.coerceIn(
|
||||
windowBounds.left,
|
||||
(windowBounds.right - popupContentSize.width - popupMargin.right)
|
||||
.coerceAtLeast(windowBounds.left),
|
||||
),
|
||||
y = offsetY.coerceIn(
|
||||
(windowBounds.top + popupMargin.top)
|
||||
.coerceAtMost(windowBounds.bottom - popupContentSize.height - popupMargin.bottom),
|
||||
windowBounds.bottom - popupContentSize.height - popupMargin.bottom,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
override fun getMargins(): PaddingValues = PaddingValues(start = 20.dp)
|
||||
}
|
||||
}
|
||||
|
||||
private fun PopupPositionProvider.Align.resolve(layoutDirection: LayoutDirection): PopupPositionProvider.Align {
|
||||
if (layoutDirection == LayoutDirection.Ltr) return this
|
||||
return when (this) {
|
||||
PopupPositionProvider.Align.Start -> PopupPositionProvider.Align.End
|
||||
PopupPositionProvider.Align.End -> PopupPositionProvider.Align.Start
|
||||
PopupPositionProvider.Align.TopStart -> PopupPositionProvider.Align.TopEnd
|
||||
PopupPositionProvider.Align.TopEnd -> PopupPositionProvider.Align.TopStart
|
||||
PopupPositionProvider.Align.BottomStart -> PopupPositionProvider.Align.BottomEnd
|
||||
PopupPositionProvider.Align.BottomEnd -> PopupPositionProvider.Align.BottomStart
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,10 @@ class AppProcessInfo(
|
||||
val label = info.getLabel(pm)
|
||||
val iconImage: Drawable = runCatching { info.loadIcon(pm) }.getOrDefault(pm.defaultActivityIcon)
|
||||
val packageName: String get() = info.packageName
|
||||
var firstInstallTime: Long = 0L
|
||||
private set
|
||||
var lastUpdateTime: Long = 0L
|
||||
private set
|
||||
val processes = fetchProcesses(pm)
|
||||
|
||||
override fun compareTo(other: AppProcessInfo) = comparator.compare(this, other)
|
||||
@@ -92,6 +96,9 @@ class AppProcessInfo(
|
||||
pm.getPackageArchiveInfo(info.sourceDir, flag) ?: return emptyList()
|
||||
}
|
||||
|
||||
firstInstallTime = packageInfo.firstInstallTime
|
||||
lastUpdateTime = packageInfo.lastUpdateTime
|
||||
|
||||
val processSet = TreeSet<ProcessInfo>(compareBy({ it.name }, { it.isIsolated }))
|
||||
processSet += packageInfo.activities.toProcessList()
|
||||
processSet += packageInfo.services.toProcessList()
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -19,26 +20,33 @@ import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.topjohnwu.magisk.ui.component.ListPopupDefaults.MenuPositionProvider
|
||||
import com.topjohnwu.magisk.ui.util.rememberDrawablePainter
|
||||
import top.yukonga.miuix.kmp.basic.Card
|
||||
import top.yukonga.miuix.kmp.basic.Checkbox
|
||||
import top.yukonga.miuix.kmp.basic.CircularProgressIndicator
|
||||
import top.yukonga.miuix.kmp.basic.DropdownImpl
|
||||
import top.yukonga.miuix.kmp.basic.Icon
|
||||
import top.yukonga.miuix.kmp.basic.IconButton
|
||||
import top.yukonga.miuix.kmp.basic.LinearProgressIndicator
|
||||
import top.yukonga.miuix.kmp.basic.ListPopupColumn
|
||||
import top.yukonga.miuix.kmp.basic.MiuixScrollBehavior
|
||||
import top.yukonga.miuix.kmp.basic.PopupPositionProvider
|
||||
import top.yukonga.miuix.kmp.basic.Scaffold
|
||||
import top.yukonga.miuix.kmp.basic.Switch
|
||||
import top.yukonga.miuix.kmp.basic.Text
|
||||
import top.yukonga.miuix.kmp.basic.TopAppBar
|
||||
import top.yukonga.miuix.kmp.extra.SuperListPopup
|
||||
import top.yukonga.miuix.kmp.icon.MiuixIcons
|
||||
import top.yukonga.miuix.kmp.icon.extended.Back
|
||||
import top.yukonga.miuix.kmp.icon.extended.Sort
|
||||
import top.yukonga.miuix.kmp.icon.extended.Tune
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@@ -49,6 +57,11 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
val query by viewModel.query.collectAsState()
|
||||
val showSystem by viewModel.showSystem.collectAsState()
|
||||
val showOS by viewModel.showOS.collectAsState()
|
||||
val sortBy by viewModel.sortBy.collectAsState()
|
||||
val sortReverse by viewModel.sortReverse.collectAsState()
|
||||
|
||||
val showSortMenu = remember { mutableStateOf(false) }
|
||||
val showFilterMenu = remember { mutableStateOf(false) }
|
||||
|
||||
val scrollBehavior = MiuixScrollBehavior()
|
||||
Scaffold(
|
||||
@@ -67,6 +80,102 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
Box {
|
||||
IconButton(
|
||||
onClick = { showSortMenu.value = true },
|
||||
holdDownState = showSortMenu.value,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = MiuixIcons.Sort,
|
||||
contentDescription = stringResource(CoreR.string.menu_sort),
|
||||
)
|
||||
}
|
||||
SuperListPopup(
|
||||
show = showSortMenu,
|
||||
popupPositionProvider = MenuPositionProvider,
|
||||
alignment = PopupPositionProvider.Align.End,
|
||||
onDismissRequest = { showSortMenu.value = false }
|
||||
) {
|
||||
ListPopupColumn {
|
||||
val sortOptions = listOf(
|
||||
CoreR.string.sort_by_name to SortBy.NAME,
|
||||
CoreR.string.sort_by_package_name to SortBy.PACKAGE_NAME,
|
||||
CoreR.string.sort_by_install_time to SortBy.INSTALL_TIME,
|
||||
CoreR.string.sort_by_update_time to SortBy.UPDATE_TIME,
|
||||
)
|
||||
val totalSize = sortOptions.size + 1
|
||||
sortOptions.forEachIndexed { index, (resId, sort) ->
|
||||
DropdownImpl(
|
||||
text = stringResource(resId),
|
||||
optionSize = totalSize,
|
||||
isSelected = sortBy == sort,
|
||||
index = index,
|
||||
onSelectedIndexChange = {
|
||||
viewModel.setSortBy(sort)
|
||||
showSortMenu.value = false
|
||||
}
|
||||
)
|
||||
}
|
||||
DropdownImpl(
|
||||
text = stringResource(CoreR.string.sort_reverse),
|
||||
optionSize = totalSize,
|
||||
isSelected = sortReverse,
|
||||
index = sortOptions.size,
|
||||
onSelectedIndexChange = {
|
||||
viewModel.toggleSortReverse()
|
||||
showSortMenu.value = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box {
|
||||
IconButton(
|
||||
modifier = Modifier.padding(end = 16.dp),
|
||||
onClick = { showFilterMenu.value = true },
|
||||
holdDownState = showFilterMenu.value,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = MiuixIcons.Tune,
|
||||
contentDescription = stringResource(CoreR.string.hide_filter_hint),
|
||||
)
|
||||
}
|
||||
SuperListPopup(
|
||||
show = showFilterMenu,
|
||||
popupPositionProvider = MenuPositionProvider,
|
||||
alignment = PopupPositionProvider.Align.End,
|
||||
onDismissRequest = { showFilterMenu.value = false }
|
||||
) {
|
||||
ListPopupColumn {
|
||||
DropdownImpl(
|
||||
text = stringResource(CoreR.string.show_system_app),
|
||||
optionSize = 2,
|
||||
isSelected = showSystem,
|
||||
index = 0,
|
||||
onSelectedIndexChange = {
|
||||
viewModel.setShowSystem(!showSystem)
|
||||
showFilterMenu.value = false
|
||||
}
|
||||
)
|
||||
DropdownImpl(
|
||||
text = stringResource(CoreR.string.show_os_app),
|
||||
optionSize = 2,
|
||||
isSelected = showOS,
|
||||
index = 1,
|
||||
onSelectedIndexChange = {
|
||||
if (!showOS && !showSystem) {
|
||||
viewModel.setShowSystem(true)
|
||||
}
|
||||
viewModel.setShowOS(!showOS)
|
||||
showFilterMenu.value = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
@@ -81,27 +190,6 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
.padding(horizontal = 12.dp, vertical = 4.dp)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 12.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
FilterChip(
|
||||
label = stringResource(CoreR.string.show_system_app),
|
||||
checked = showSystem,
|
||||
onCheckedChange = viewModel::setShowSystem
|
||||
)
|
||||
FilterChip(
|
||||
label = stringResource(CoreR.string.show_os_app),
|
||||
checked = showOS,
|
||||
enabled = showSystem,
|
||||
onCheckedChange = viewModel::setShowOS
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
if (loading) {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
@@ -122,6 +210,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
.fillMaxSize()
|
||||
.nestedScroll(scrollBehavior.nestedScrollConnection)
|
||||
.padding(horizontal = 12.dp),
|
||||
contentPadding = PaddingValues(top = 8.dp, bottom = 88.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
items(
|
||||
@@ -130,7 +219,6 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
) { app ->
|
||||
DenyAppCard(app)
|
||||
}
|
||||
item { Spacer(Modifier.height(8.dp)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,34 +235,6 @@ private fun SearchInput(query: String, onQueryChange: (String) -> Unit, modifier
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilterChip(
|
||||
label: String,
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable(enabled = enabled) { onCheckedChange(!checked) }
|
||||
.padding(vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
Checkbox(
|
||||
checked = checked,
|
||||
onCheckedChange = if (enabled) onCheckedChange else null,
|
||||
enabled = enabled
|
||||
)
|
||||
Text(
|
||||
text = label,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = if (enabled) MiuixTheme.colorScheme.onSurface
|
||||
else MiuixTheme.colorScheme.disabledOnSecondaryVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DenyAppCard(app: DenyAppState) {
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
@@ -247,10 +307,9 @@ private fun ProcessRow(proc: DenyProcessState) {
|
||||
else MiuixTheme.colorScheme.onSurfaceVariantSummary,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Switch(
|
||||
Checkbox(
|
||||
checked = proc.isEnabled,
|
||||
onCheckedChange = { proc.toggle() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.toCollection
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
enum class SortBy { NAME, PACKAGE_NAME, INSTALL_TIME, UPDATE_TIME }
|
||||
|
||||
class DenyListViewModel : AsyncLoadViewModel() {
|
||||
|
||||
private val _loading = MutableStateFlow(true)
|
||||
@@ -38,10 +40,24 @@ class DenyListViewModel : AsyncLoadViewModel() {
|
||||
private val _showOS = MutableStateFlow(false)
|
||||
val showOS: StateFlow<Boolean> = _showOS.asStateFlow()
|
||||
|
||||
private val _sortBy = MutableStateFlow(SortBy.NAME)
|
||||
val sortBy: StateFlow<SortBy> = _sortBy.asStateFlow()
|
||||
|
||||
private val _sortReverse = MutableStateFlow(false)
|
||||
val sortReverse: StateFlow<Boolean> = _sortReverse.asStateFlow()
|
||||
|
||||
val filteredApps: StateFlow<List<DenyAppState>> = combine(
|
||||
_allApps, _query, _showSystem, _showOS
|
||||
) { apps, q, showSys, showOS ->
|
||||
apps.filter { app ->
|
||||
_allApps, _query, _showSystem, _showOS, _sortBy, _sortReverse
|
||||
) { args ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val apps = args[0] as List<DenyAppState>
|
||||
val q = args[1] as String
|
||||
val showSys = args[2] as Boolean
|
||||
val showOS = args[3] as Boolean
|
||||
val sort = args[4] as SortBy
|
||||
val reverse = args[5] as Boolean
|
||||
|
||||
val filtered = apps.filter { app ->
|
||||
val passFilter = app.isChecked ||
|
||||
((showSys || !app.info.isSystemApp()) &&
|
||||
((showSys && showOS) || app.info.isApp()))
|
||||
@@ -51,11 +67,26 @@ class DenyListViewModel : AsyncLoadViewModel() {
|
||||
app.processes.any { it.process.name.contains(q, true) }
|
||||
passFilter && passQuery
|
||||
}
|
||||
|
||||
val secondary: Comparator<DenyAppState> = when (sort) {
|
||||
SortBy.NAME -> compareBy(String.CASE_INSENSITIVE_ORDER) { it.info.label }
|
||||
SortBy.PACKAGE_NAME -> compareBy(String.CASE_INSENSITIVE_ORDER) { it.info.packageName }
|
||||
SortBy.INSTALL_TIME -> compareByDescending { it.info.firstInstallTime }
|
||||
SortBy.UPDATE_TIME -> compareByDescending { it.info.lastUpdateTime }
|
||||
}
|
||||
val comparator = compareBy<DenyAppState> { it.itemsChecked == 0 }
|
||||
.then(if (reverse) secondary.reversed() else secondary)
|
||||
filtered.sortedWith(comparator)
|
||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
|
||||
|
||||
fun setQuery(q: String) { _query.value = q }
|
||||
fun setShowSystem(v: Boolean) { _showSystem.value = v }
|
||||
fun setShowSystem(v: Boolean) {
|
||||
_showSystem.value = v
|
||||
if (!v) _showOS.value = false
|
||||
}
|
||||
fun setShowOS(v: Boolean) { _showOS.value = v }
|
||||
fun setSortBy(s: SortBy) { _sortBy.value = s }
|
||||
fun toggleSortReverse() { _sortReverse.value = !_sortReverse.value }
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override suspend fun doLoadWork() {
|
||||
|
||||
@@ -94,6 +94,12 @@
|
||||
<string name="show_system_app">Show system apps</string>
|
||||
<string name="show_os_app">Show OS apps</string>
|
||||
<string name="hide_filter_hint">Filter by name</string>
|
||||
<string name="sort_by_name">Sort by name</string>
|
||||
<string name="sort_by_package_name">Sort by package name</string>
|
||||
<string name="sort_by_install_time">Sort by install time</string>
|
||||
<string name="sort_by_update_time">Sort by update time</string>
|
||||
<string name="sort_reverse">Reverse order</string>
|
||||
<string name="menu_sort">Sort</string>
|
||||
<string name="hide_search">Search</string>
|
||||
|
||||
<!--Module-->
|
||||
|
||||
Reference in New Issue
Block a user