mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
perf: 显示隐藏应用/存储筛选项
This commit is contained in:
parent
8e0c892e55
commit
fe6b49abc2
|
@ -14,6 +14,7 @@ data class AppInfo(
|
|||
val versionName: String?,
|
||||
val isSystem: Boolean,
|
||||
val mtime: Long,
|
||||
val hidden: Boolean,
|
||||
)
|
||||
|
||||
fun PackageInfo.toAppInfo(): AppInfo? {
|
||||
|
@ -30,6 +31,7 @@ fun PackageInfo.toAppInfo(): AppInfo? {
|
|||
},
|
||||
versionName = versionName,
|
||||
isSystem = (ApplicationInfo.FLAG_SYSTEM and applicationInfo.flags) != 0,
|
||||
mtime = lastUpdateTime
|
||||
mtime = lastUpdateTime,
|
||||
hidden = app.packageManager.getLaunchIntentForPackage(packageName) == null
|
||||
)
|
||||
}
|
|
@ -87,6 +87,7 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
|
|||
val showAppInfos = vm.showAppInfosFlow.collectAsState().value
|
||||
val searchStr by vm.searchStrFlow.collectAsState()
|
||||
val showSystemApp by vm.showSystemAppFlow.collectAsState()
|
||||
val showHiddenApp by vm.showHiddenAppFlow.collectAsState()
|
||||
val sortType by vm.sortTypeFlow.collectAsState()
|
||||
|
||||
var showEditDlg by remember {
|
||||
|
@ -209,6 +210,24 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
|
|||
vm.showSystemAppFlow.value = !vm.showSystemAppFlow.value
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Checkbox(
|
||||
checked = showHiddenApp,
|
||||
onCheckedChange = {
|
||||
vm.showHiddenAppFlow.value =
|
||||
!vm.showHiddenAppFlow.value
|
||||
})
|
||||
Text("显示隐藏应用")
|
||||
}
|
||||
},
|
||||
onClick = {
|
||||
vm.showHiddenAppFlow.value = !vm.showHiddenAppFlow.value
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,9 +44,16 @@ class GlobalRuleExcludeVm @Inject constructor(stateHandle: SavedStateHandle) : V
|
|||
appIds.mapIndexed { index, appId -> appId to index }.toMap()
|
||||
}
|
||||
val sortTypeFlow = MutableStateFlow<SortTypeOption>(SortTypeOption.SortByName)
|
||||
val showSystemAppFlow = MutableStateFlow(false)
|
||||
val showSystemAppFlow = MutableStateFlow(true)
|
||||
val showHiddenAppFlow = MutableStateFlow(false)
|
||||
val showAppInfosFlow =
|
||||
combine(orderedAppInfosFlow.combine(showSystemAppFlow) { apps, showSystemApp ->
|
||||
combine(orderedAppInfosFlow.combine(showHiddenAppFlow) { appInfos, showHiddenApp ->
|
||||
if (showHiddenApp) {
|
||||
appInfos
|
||||
} else {
|
||||
appInfos.filter { a -> !a.hidden }
|
||||
}
|
||||
}.combine(showSystemAppFlow) { apps, showSystemApp ->
|
||||
if (showSystemApp) {
|
||||
apps
|
||||
} else {
|
||||
|
|
|
@ -53,12 +53,14 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
||||
import kotlinx.coroutines.flow.update
|
||||
import li.songe.gkd.ui.component.AppBarTextField
|
||||
import li.songe.gkd.ui.destinations.AppConfigPageDestination
|
||||
import li.songe.gkd.util.LocalNavController
|
||||
import li.songe.gkd.util.SortTypeOption
|
||||
import li.songe.gkd.util.navigate
|
||||
import li.songe.gkd.util.ruleSummaryFlow
|
||||
import li.songe.gkd.util.storeFlow
|
||||
|
||||
val appListNav = BottomNavItem(
|
||||
label = "应用", icon = Icons.Default.Apps
|
||||
|
@ -70,6 +72,7 @@ fun useAppListPage(): ScaffoldExt {
|
|||
|
||||
val vm = hiltViewModel<HomeVm>()
|
||||
val showSystemApp by vm.showSystemAppFlow.collectAsState()
|
||||
val showHiddenApp by vm.showHiddenAppFlow.collectAsState()
|
||||
val sortType by vm.sortTypeFlow.collectAsState()
|
||||
val orderedAppInfos by vm.appInfosFlow.collectAsState()
|
||||
val searchStr by vm.searchStrFlow.collectAsState()
|
||||
|
@ -158,14 +161,14 @@ fun useAppListPage(): ScaffoldExt {
|
|||
) {
|
||||
RadioButton(selected = sortType == sortOption,
|
||||
onClick = {
|
||||
vm.sortTypeFlow.value = sortOption
|
||||
storeFlow.update { s -> s.copy(sortType = sortOption.value) }
|
||||
}
|
||||
)
|
||||
Text(sortOption.label)
|
||||
}
|
||||
},
|
||||
onClick = {
|
||||
vm.sortTypeFlow.value = sortOption
|
||||
storeFlow.update { s -> s.copy(sortType = sortOption.value) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -188,6 +191,24 @@ fun useAppListPage(): ScaffoldExt {
|
|||
vm.showSystemAppFlow.value = !vm.showSystemAppFlow.value
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Checkbox(
|
||||
checked = showHiddenApp,
|
||||
onCheckedChange = {
|
||||
vm.showHiddenAppFlow.value =
|
||||
!vm.showHiddenAppFlow.value
|
||||
})
|
||||
Text("显示隐藏应用")
|
||||
}
|
||||
},
|
||||
onClick = {
|
||||
vm.showHiddenAppFlow.value = !vm.showHiddenAppFlow.value
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,8 +36,10 @@ import li.songe.gkd.util.appInfoCacheFlow
|
|||
import li.songe.gkd.util.clickCountFlow
|
||||
import li.songe.gkd.util.client
|
||||
import li.songe.gkd.util.launchTry
|
||||
import li.songe.gkd.util.map
|
||||
import li.songe.gkd.util.orderedAppInfosFlow
|
||||
import li.songe.gkd.util.ruleSummaryFlow
|
||||
import li.songe.gkd.util.storeFlow
|
||||
import li.songe.gkd.util.subsIdToRawFlow
|
||||
import li.songe.gkd.util.subsItemsFlow
|
||||
import li.songe.gkd.util.toast
|
||||
|
@ -229,13 +231,22 @@ class HomeVm @Inject constructor() : ViewModel() {
|
|||
appIds.mapIndexed { index, appId -> appId to index }.toMap()
|
||||
}
|
||||
|
||||
val sortTypeFlow = MutableStateFlow<SortTypeOption>(SortTypeOption.SortByName)
|
||||
val showSystemAppFlow = MutableStateFlow(false)
|
||||
val sortTypeFlow = storeFlow.map(viewModelScope) { s ->
|
||||
SortTypeOption.allSubObject.find { o -> o.value == s.sortType } ?: SortTypeOption.SortByName
|
||||
}
|
||||
val showSystemAppFlow = MutableStateFlow(true)
|
||||
val showHiddenAppFlow = MutableStateFlow(false)
|
||||
val searchStrFlow = MutableStateFlow("")
|
||||
private val debounceSearchStrFlow = searchStrFlow.debounce(200)
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, searchStrFlow.value)
|
||||
val appInfosFlow =
|
||||
combine(orderedAppInfosFlow.combine(showSystemAppFlow) { appInfos, showSystemApp ->
|
||||
combine(orderedAppInfosFlow.combine(showHiddenAppFlow) { appInfos, showHiddenApp ->
|
||||
if (showHiddenApp) {
|
||||
appInfos
|
||||
} else {
|
||||
appInfos.filter { a -> !a.hidden }
|
||||
}
|
||||
}.combine(showSystemAppFlow) { appInfos, showSystemApp ->
|
||||
if (showSystemApp) {
|
||||
appInfos
|
||||
} else {
|
||||
|
|
|
@ -26,17 +26,7 @@ val systemAppsFlow = systemAppInfoCacheFlow.map(appScope) { c -> c.keys }
|
|||
|
||||
val orderedAppInfosFlow = appInfoCacheFlow.map(appScope) { c ->
|
||||
c.values.sortedWith { a, b ->
|
||||
collator.compare(
|
||||
if (a.isSystem) {
|
||||
"\uFFFF${a.name}"
|
||||
} else {
|
||||
a.name
|
||||
}, if (b.isSystem) {
|
||||
"\uFFFF${b.name}"
|
||||
} else {
|
||||
b.name
|
||||
}
|
||||
)
|
||||
collator.compare(a.name, b.name)
|
||||
}.toImmutableList()
|
||||
}
|
||||
|
||||
|
@ -107,8 +97,7 @@ fun initAppState() {
|
|||
appScope.launchTry(Dispatchers.IO) {
|
||||
updateAppMutex.withLock {
|
||||
val appMap = mutableMapOf<String, AppInfo>()
|
||||
app.packageManager.getInstalledPackages(0)
|
||||
.forEach { packageInfo ->
|
||||
app.packageManager.getInstalledPackages(0).forEach { packageInfo ->
|
||||
val info = packageInfo.toAppInfo()
|
||||
if (info != null) {
|
||||
appMap[packageInfo.packageName] = info
|
||||
|
|
|
@ -3,7 +3,7 @@ package li.songe.gkd.util
|
|||
sealed class SortTypeOption(val value: Int, val label: String) {
|
||||
data object SortByName : SortTypeOption(0, "按名称")
|
||||
data object SortByAppMtime : SortTypeOption(1, "按更新时间")
|
||||
data object SortByTriggerTime : SortTypeOption(0, "按触发时间")
|
||||
data object SortByTriggerTime : SortTypeOption(2, "按触发时间")
|
||||
|
||||
companion object {
|
||||
// https://stackoverflow.com/questions/47648689
|
||||
|
|
|
@ -56,6 +56,7 @@ data class Store(
|
|||
val log2FileSwitch: Boolean = true,
|
||||
val enableDarkTheme: Boolean? = null,
|
||||
val enableAbFloatWindow: Boolean = true,
|
||||
val sortType: Int = SortTypeOption.SortByName.value,
|
||||
)
|
||||
|
||||
val storeFlow by lazy {
|
||||
|
|
Loading…
Reference in New Issue
Block a user