From 50631aade61c0482ad0be5b8ed690c00f7b3b63f Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Tue, 3 Jun 2025 00:00:39 +0800 Subject: [PATCH] Manager: Refactoring of hidden messages and display of KPM settings status management --- .../java/com/sukisu/ultra/ui/MainActivity.kt | 40 +++++++++++++++---- .../sukisu/ultra/ui/screen/MoreSettings.kt | 3 -- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/manager/app/src/main/java/com/sukisu/ultra/ui/MainActivity.kt b/manager/app/src/main/java/com/sukisu/ultra/ui/MainActivity.kt index 0a29713c..4eea49e2 100644 --- a/manager/app/src/main/java/com/sukisu/ultra/ui/MainActivity.kt +++ b/manager/app/src/main/java/com/sukisu/ultra/ui/MainActivity.kt @@ -54,10 +54,17 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow class MainActivity : ComponentActivity() { private lateinit var superUserViewModel: SuperUserViewModel private lateinit var homeViewModel: HomeViewModel + internal val settingsStateFlow = MutableStateFlow(SettingsState()) + + data class SettingsState( + val isHideOtherInfo: Boolean = false, + val showKpmInfo: Boolean = true + ) private inner class ThemeChangeContentObserver( handler: Handler, @@ -143,9 +150,16 @@ class MainActivity : ComponentActivity() { // 数据刷新协程 startDataRefreshCoroutine() + startSettingsMonitorCoroutine() + val prefs = getSharedPreferences("settings", MODE_PRIVATE) val isFirstRun = prefs.getBoolean("is_first_run", true) + settingsStateFlow.value = SettingsState( + isHideOtherInfo = prefs.getBoolean("is_hide_other_info", false), + showKpmInfo = prefs.getBoolean("show_kpm_info", true) + ) + if (isFirstRun) { ThemeConfig.preventBackgroundRefresh = false getSharedPreferences("theme_prefs", MODE_PRIVATE).edit { @@ -244,6 +258,19 @@ class MainActivity : ComponentActivity() { } } + private fun startSettingsMonitorCoroutine() { + lifecycleScope.launch(Dispatchers.IO) { + while (isActive) { + val prefs = getSharedPreferences("settings", MODE_PRIVATE) + settingsStateFlow.value = SettingsState( + isHideOtherInfo = prefs.getBoolean("is_hide_other_info", false), + showKpmInfo = prefs.getBoolean("show_kpm_info", true) + ) + delay(1000) + } + } + } + // 应用自定义DPI设置 private fun applyCustomDpi() { val prefs = getSharedPreferences("settings", MODE_PRIVATE) @@ -313,19 +340,18 @@ private fun BottomBar(navController: NavHostController) { val isFullFeatured = AppData.isFullFeatured(ksuApp.packageName) val kpmVersion = getKpmVersionUse() val cardColor = MaterialTheme.colorScheme.surfaceContainer - val context = LocalContext.current + val activity = LocalContext.current as MainActivity + val settings by activity.settingsStateFlow.collectAsState() + + // 检查是否隐藏红点 + val isHideOtherInfo = settings.isHideOtherInfo + val showKpmInfo = settings.showKpmInfo // 收集计数数据 val superuserCount by DataRefreshManager.superuserCount.collectAsState() val moduleCount by DataRefreshManager.moduleCount.collectAsState() val kpmModuleCount by DataRefreshManager.kpmModuleCount.collectAsState() - // 检查是否显示KPM - val showKpmInfo = context.getSharedPreferences("settings", Context.MODE_PRIVATE) - .getBoolean("show_kpm_info", true) - - val isHideOtherInfo = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE) - .getBoolean("is_hide_other_info", false) NavigationBar( modifier = Modifier.windowInsetsPadding( diff --git a/manager/app/src/main/java/com/sukisu/ultra/ui/screen/MoreSettings.kt b/manager/app/src/main/java/com/sukisu/ultra/ui/screen/MoreSettings.kt index 4047874b..8b6728cc 100644 --- a/manager/app/src/main/java/com/sukisu/ultra/ui/screen/MoreSettings.kt +++ b/manager/app/src/main/java/com/sukisu/ultra/ui/screen/MoreSettings.kt @@ -90,7 +90,6 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.unit.sp import com.ramcosta.composedestinations.navigation.DestinationsNavigator -import com.sukisu.ultra.ui.util.restartApp /** * @author ShirkNeko @@ -296,14 +295,12 @@ fun MoreSettingsScreen( val onHideOtherInfoChange = { newValue: Boolean -> prefs.edit { putBoolean("is_hide_other_info", newValue) } isHideOtherInfo = newValue - context.restartApp(MainActivity::class.java) } // 更新显示KPM开关状态 val onShowKpmInfoChange = { newValue: Boolean -> prefs.edit { putBoolean("show_kpm_info", newValue) } isShowKpmInfo = newValue - context.restartApp(MainActivity::class.java) } // 隐藏SuSFS状态开关状态