Manager: Refactoring of hidden messages and display of KPM settings status management
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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状态开关状态
|
||||
|
||||
Reference in New Issue
Block a user