From 1f74953b844b5e0f19784af37d1f45024ece20c1 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 3 Mar 2026 15:43:59 +0800 Subject: [PATCH] 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 --- .../com/topjohnwu/magisk/ui/MainActivity.kt | 1 + .../ui/component/MenuPositionProvider.kt | 84 +++++++++ .../magisk/ui/deny/AppProcessInfo.kt | 7 + .../magisk/ui/deny/DenyListScreen.kt | 165 ++++++++++++------ .../magisk/ui/deny/DenyListViewModel.kt | 39 ++++- app/core/src/main/res/values/strings.xml | 6 + 6 files changed, 245 insertions(+), 57 deletions(-) create mode 100644 app/apk/src/main/java/com/topjohnwu/magisk/ui/component/MenuPositionProvider.kt diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index 2ea61681d..8484d05bf 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -130,6 +130,7 @@ class MainActivity : UIActivity(), SplashScreenHost { } entry { _ -> val vm: DenyListViewModel = androidx.lifecycle.viewmodel.compose.viewModel(factory = VMFactory) + LaunchedEffect(Unit) { vm.startLoading() } ObserveViewEvents(vm) DenyListScreen(vm, onBack = { navigator.pop() }) } diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/component/MenuPositionProvider.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/component/MenuPositionProvider.kt new file mode 100644 index 000000000..6763878bc --- /dev/null +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/component/MenuPositionProvider.kt @@ -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 + } +} diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/AppProcessInfo.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/AppProcessInfo.kt index 9863279d0..23cfae038 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/AppProcessInfo.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/AppProcessInfo.kt @@ -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(compareBy({ it.name }, { it.isIsolated })) processSet += packageInfo.activities.toProcessList() processSet += packageInfo.services.toProcessList() diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListScreen.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListScreen.kt index 406ceb350..7a9d7c233 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListScreen.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListScreen.kt @@ -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() } ) } } - diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt index ce31d8fba..f4e2547ab 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt @@ -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 = _showOS.asStateFlow() + private val _sortBy = MutableStateFlow(SortBy.NAME) + val sortBy: StateFlow = _sortBy.asStateFlow() + + private val _sortReverse = MutableStateFlow(false) + val sortReverse: StateFlow = _sortReverse.asStateFlow() + val filteredApps: StateFlow> = 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 + 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 = 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 { 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() { diff --git a/app/core/src/main/res/values/strings.xml b/app/core/src/main/res/values/strings.xml index 19c56810c..7838e3c14 100644 --- a/app/core/src/main/res/values/strings.xml +++ b/app/core/src/main/res/values/strings.xml @@ -94,6 +94,12 @@ Show system apps Show OS apps Filter by name + Sort by name + Sort by package name + Sort by install time + Sort by update time + Reverse order + Sort Search