forked from melod1n/fast-messenger
clean up settings and some other things
This commit is contained in:
+109
-94
@@ -6,17 +6,18 @@ import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.view.HapticFeedbackConstantsCompat
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.meloda.app.fast.common.UiText
|
||||
import com.meloda.app.fast.common.LongPollController
|
||||
import com.meloda.app.fast.common.UserConfig
|
||||
import com.meloda.app.fast.common.extensions.findWithIndex
|
||||
import com.meloda.app.fast.common.extensions.isSdkAtLeast
|
||||
import com.meloda.app.fast.common.extensions.setValue
|
||||
import com.meloda.app.fast.common.model.DarkMode
|
||||
import com.meloda.app.fast.common.model.LongPollState
|
||||
import com.meloda.app.fast.common.model.UiText
|
||||
import com.meloda.app.fast.data.db.AccountsRepository
|
||||
import com.meloda.app.fast.datastore.SettingsController
|
||||
import com.meloda.app.fast.datastore.AppSettings
|
||||
import com.meloda.app.fast.datastore.SettingsKeys
|
||||
import com.meloda.app.fast.datastore.UserSettings
|
||||
import com.meloda.app.fast.datastore.isDebugSettingsShown
|
||||
import com.meloda.app.fast.datastore.model.LongPollState
|
||||
import com.meloda.app.fast.model.database.AccountEntity
|
||||
import com.meloda.app.fast.settings.model.SettingsItem
|
||||
import com.meloda.app.fast.settings.model.SettingsScreenState
|
||||
@@ -32,8 +33,7 @@ import com.meloda.app.fast.ui.R as UiR
|
||||
interface SettingsViewModel {
|
||||
|
||||
val screenState: StateFlow<SettingsScreenState>
|
||||
|
||||
val isLongPollBackgroundEnabled: StateFlow<Boolean?>
|
||||
val hapticType: StateFlow<HapticType?>
|
||||
|
||||
fun onLogOutAlertDismissed()
|
||||
fun onLogOutAlertPositiveClick()
|
||||
@@ -46,22 +46,20 @@ interface SettingsViewModel {
|
||||
fun onSettingsItemChanged(key: String, newValue: Any?)
|
||||
|
||||
fun onHapticPerformed()
|
||||
|
||||
fun onNotificationsPermissionRequested()
|
||||
}
|
||||
|
||||
class SettingsViewModelImpl(
|
||||
private val accountsRepository: AccountsRepository,
|
||||
private val userSettings: UserSettings,
|
||||
private val resources: Resources
|
||||
private val resources: Resources,
|
||||
private val longPollController: LongPollController
|
||||
) : SettingsViewModel, ViewModel() {
|
||||
|
||||
override val screenState = MutableStateFlow(SettingsScreenState.EMPTY)
|
||||
override val hapticType = MutableStateFlow<HapticType?>(null)
|
||||
|
||||
private val settings = MutableStateFlow<List<SettingsItem<*>>>(emptyList())
|
||||
|
||||
override val isLongPollBackgroundEnabled = MutableStateFlow<Boolean?>(null)
|
||||
|
||||
init {
|
||||
createSettings()
|
||||
}
|
||||
@@ -106,22 +104,15 @@ class SettingsViewModelImpl(
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_DEBUG_HIDE_DEBUG_LIST -> {
|
||||
val showDebugCategory = isDebugSettingsShown()
|
||||
val showDebugCategory = AppSettings.Debug.showDebugCategory
|
||||
if (!showDebugCategory) return
|
||||
|
||||
SettingsController.put(
|
||||
SettingsKeys.KEY_SHOW_DEBUG_CATEGORY,
|
||||
false
|
||||
)
|
||||
onSettingsItemChanged(key, false)
|
||||
|
||||
createSettings()
|
||||
|
||||
screenState.setValue { old ->
|
||||
old.copy(
|
||||
useHaptics = HapticType.REJECT,
|
||||
showDebugOptions = false
|
||||
)
|
||||
}
|
||||
hapticType.update { HapticType.REJECT }
|
||||
screenState.setValue { old -> old.copy(showDebugOptions = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,18 +120,14 @@ class SettingsViewModelImpl(
|
||||
override fun onSettingsItemLongClicked(key: String) {
|
||||
when (key) {
|
||||
SettingsKeys.KEY_ACTIVITY_SEND_ONLINE_STATUS -> {
|
||||
if (isDebugSettingsShown()) return
|
||||
if (AppSettings.Debug.showDebugCategory) return
|
||||
|
||||
SettingsController.put(SettingsKeys.KEY_SHOW_DEBUG_CATEGORY, true)
|
||||
onSettingsItemChanged(key, true)
|
||||
|
||||
createSettings()
|
||||
|
||||
screenState.setValue { old ->
|
||||
old.copy(
|
||||
useHaptics = HapticType.LONG_PRESS,
|
||||
showDebugOptions = true
|
||||
)
|
||||
}
|
||||
hapticType.update { HapticType.LONG_PRESS }
|
||||
screenState.setValue { old -> old.copy(showDebugOptions = true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,70 +147,98 @@ class SettingsViewModelImpl(
|
||||
}
|
||||
|
||||
when (key) {
|
||||
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND -> {
|
||||
val isEnabled = (newValue as? Boolean) == true
|
||||
userSettings.setLongPollStateToApply(
|
||||
userSettings.longPollStateToApply.value.let { state ->
|
||||
if (state.isLaunched()) {
|
||||
if (isEnabled) LongPollState.Background
|
||||
else LongPollState.InApp
|
||||
} else state
|
||||
}
|
||||
)
|
||||
|
||||
if (isEnabled) {
|
||||
// TODO: 26/11/2023, Danil Nikolaev: implement
|
||||
val isNotificationsPermissionGranted = false
|
||||
|
||||
if (!isNotificationsPermissionGranted) {
|
||||
// TODO: 26/11/2023, Danil Nikolaev: implement restart
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_MULTILINE -> {
|
||||
val isUsing = newValue as? Boolean ?: false
|
||||
userSettings.useMultiline(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_AMOLED_THEME -> {
|
||||
val isUsing = newValue as? Boolean ?: false
|
||||
userSettings.useAmoledThemeChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_USE_DYNAMIC_COLORS -> {
|
||||
val isUsing = newValue as? Boolean ?: false
|
||||
userSettings.useDynamicColorsChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_BLUR -> {
|
||||
val isUsing = newValue as? Boolean ?: false
|
||||
userSettings.useBlurChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_ACTIVITY_SEND_ONLINE_STATUS -> {
|
||||
val isUsing = newValue as? Boolean ?: false
|
||||
userSettings.setOnline(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_USE_CONTACT_NAMES -> {
|
||||
val isUsing = newValue as? Boolean ?: false
|
||||
val isUsing = newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_USE_CONTACT_NAMES
|
||||
userSettings.onUseContactNamesChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_ENABLE_PULL_TO_REFRESH -> {
|
||||
val enable = newValue as? Boolean ?: false
|
||||
val enable =
|
||||
newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_ENABLE_PULL_TO_REFRESH
|
||||
userSettings.onEnablePullToRefreshChanged(enable)
|
||||
}
|
||||
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_MULTILINE -> {
|
||||
val isUsing = newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_MULTILINE
|
||||
userSettings.onEnableMultilineChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_DARK_MODE -> {
|
||||
val newMode = newValue as? Int ?: SettingsKeys.DEFAULT_VALUE_APPEARANCE_DARK_MODE
|
||||
AppCompatDelegate.setDefaultNightMode(newMode)
|
||||
userSettings.onDarkModeChanged(DarkMode.parse(newMode))
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_AMOLED_THEME -> {
|
||||
val isUsing =
|
||||
newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_APPEARANCE_AMOLED_THEME
|
||||
userSettings.onEnableAmoledDarkChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_USE_DYNAMIC_COLORS -> {
|
||||
val isUsing = newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_USE_DYNAMIC_COLORS
|
||||
userSettings.onEnableDynamicColorsChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_LANGUAGE -> {
|
||||
val newLanguage = newValue as? String ?: SettingsKeys.DEFAULT_APPEARANCE_LANGUAGE
|
||||
userSettings.onAppLanguageChanged(newLanguage)
|
||||
}
|
||||
|
||||
|
||||
SettingsKeys.DEFAULT_VALUE_FEATURES_FAST_TEXT -> {
|
||||
val newText = newValue as? String ?: SettingsKeys.DEFAULT_VALUE_FEATURES_FAST_TEXT
|
||||
userSettings.onFastTextChanged(newText)
|
||||
}
|
||||
|
||||
|
||||
SettingsKeys.KEY_ACTIVITY_SEND_ONLINE_STATUS -> {
|
||||
val isUsing = newValue as? Boolean
|
||||
?: SettingsKeys.DEFAULT_VALUE_KEY_ACTIVITY_SEND_ONLINE_STATUS
|
||||
userSettings.onSendOnlineStatusChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_DEBUG_SHOW_CRASH_ALERT -> {
|
||||
val show = newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_KEY_SHOW_EMOJI_BUTTON
|
||||
userSettings.onShowAlertAfterCrashChanged(show)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND -> {
|
||||
val inBackground = newValue as? Boolean
|
||||
?: SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
|
||||
userSettings.onLongPollInBackgroundChanged(inBackground)
|
||||
|
||||
longPollController.setStateToApply(
|
||||
longPollController.stateToApply.value.let { state ->
|
||||
if (state.isLaunched()) {
|
||||
if (inBackground) LongPollState.Background
|
||||
else LongPollState.InApp
|
||||
} else state
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_APPEARANCE_USE_BLUR -> {
|
||||
val isUsing =
|
||||
newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_KEY_APPEARANCE_USE_BLUR
|
||||
userSettings.onUseBlurChanged(isUsing)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_SHOW_EMOJI_BUTTON -> {
|
||||
val show = newValue as? Boolean ?: SettingsKeys.DEFAULT_VALUE_KEY_SHOW_EMOJI_BUTTON
|
||||
userSettings.onShowEmojiButtonChanged(show)
|
||||
}
|
||||
|
||||
SettingsKeys.KEY_SHOW_DEBUG_CATEGORY -> {
|
||||
val show = newValue as? Boolean ?: false
|
||||
userSettings.onShowDebugCategoryChanged(show)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onHapticPerformed() {
|
||||
screenState.setValue { old -> old.copy(useHaptics = null) }
|
||||
}
|
||||
|
||||
override fun onNotificationsPermissionRequested() {
|
||||
screenState.setValue { old -> old.copy(isNeedToRequestNotificationPermission = false) }
|
||||
hapticType.update { null }
|
||||
}
|
||||
|
||||
private fun emitShowOptions(function: (SettingsShowOptions) -> SettingsShowOptions) {
|
||||
@@ -273,22 +288,22 @@ class SettingsViewModelImpl(
|
||||
)
|
||||
|
||||
val darkThemeValues = listOf(
|
||||
AppCompatDelegate.MODE_NIGHT_YES to UiText.Resource(UiR.string.settings_dark_theme_value_enabled),
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM to UiText.Resource(UiR.string.settings_dark_theme_value_follow_system),
|
||||
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY to UiText.Resource(UiR.string.settings_dark_theme_value_battery_saver),
|
||||
AppCompatDelegate.MODE_NIGHT_NO to UiText.Resource(UiR.string.settings_dark_theme_value_disabled)
|
||||
DarkMode.ENABLED to UiText.Resource(UiR.string.settings_dark_theme_value_enabled),
|
||||
DarkMode.FOLLOW_SYSTEM to UiText.Resource(UiR.string.settings_dark_theme_value_follow_system),
|
||||
DarkMode.AUTO_BATTERY to UiText.Resource(UiR.string.settings_dark_theme_value_battery_saver),
|
||||
DarkMode.DISABLED to UiText.Resource(UiR.string.settings_dark_theme_value_disabled)
|
||||
).toMap()
|
||||
|
||||
val appearanceDarkTheme = SettingsItem.ListItem(
|
||||
key = SettingsKeys.KEY_APPEARANCE_DARK_THEME,
|
||||
key = SettingsKeys.KEY_APPEARANCE_DARK_MODE,
|
||||
title = UiText.Resource(UiR.string.settings_dark_theme),
|
||||
valueClass = Int::class,
|
||||
defaultValue = SettingsKeys.DEFAULT_VALUE_APPEARANCE_DARK_THEME,
|
||||
defaultValue = SettingsKeys.DEFAULT_VALUE_APPEARANCE_DARK_MODE,
|
||||
titles = darkThemeValues.values.toList(),
|
||||
values = darkThemeValues.keys.toList()
|
||||
values = darkThemeValues.keys.toList().map(DarkMode::value)
|
||||
).apply {
|
||||
textProvider = TextProvider { item ->
|
||||
val darkThemeValue = darkThemeValues[item.value]
|
||||
val darkThemeValue = darkThemeValues[DarkMode.parse(item.value)]
|
||||
|
||||
UiText.ResourceParams(
|
||||
value = UiR.string.settings_dark_theme_current_value,
|
||||
@@ -368,8 +383,8 @@ class SettingsViewModelImpl(
|
||||
text = UiText.Simple("Shows alert dialog with stacktrace after app crashed\n(it will be not shown if you perform crash manually)")
|
||||
)
|
||||
val debugUseBlur = SettingsItem.Switch(
|
||||
key = SettingsKeys.KEY_APPEARANCE_BLUR,
|
||||
defaultValue = SettingsKeys.DEFAULT_VALUE_KEY_APPEARANCE_BLUR,
|
||||
key = SettingsKeys.KEY_APPEARANCE_USE_BLUR,
|
||||
defaultValue = SettingsKeys.DEFAULT_VALUE_KEY_APPEARANCE_USE_BLUR,
|
||||
title = UiText.Simple("[WIP] Use blur"),
|
||||
text = UiText.Simple("Adds blur wherever possible\nOn android 11 and older will have transparency instead of blurring"),
|
||||
)
|
||||
@@ -432,7 +447,7 @@ class SettingsViewModelImpl(
|
||||
debugList,
|
||||
).forEach(settingsList::addAll)
|
||||
|
||||
if (!isDebugSettingsShown()) {
|
||||
if (!AppSettings.Debug.showDebugCategory) {
|
||||
settingsList.removeAll(debugList)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.meloda.app.fast.settings.model
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.meloda.app.fast.common.UiText
|
||||
import com.meloda.app.fast.common.parseString
|
||||
import com.meloda.app.fast.datastore.SettingsController
|
||||
import com.meloda.app.fast.common.model.UiText
|
||||
import com.meloda.app.fast.common.model.parseString
|
||||
import com.meloda.app.fast.datastore.AppSettings
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Immutable
|
||||
@@ -37,7 +37,7 @@ sealed class SettingsItem<T>(
|
||||
protected set(newValue) {
|
||||
field = newValue
|
||||
|
||||
SettingsController.put(key, newValue)
|
||||
AppSettings.put(key, newValue)
|
||||
}
|
||||
|
||||
var title: UiText? = null
|
||||
@@ -165,7 +165,7 @@ sealed class SettingsItem<T>(
|
||||
val values: List<T>
|
||||
) : SettingsItem<T>(
|
||||
key = key,
|
||||
value = selectedValue ?: SettingsController.get(valueClass, key, defaultValue),
|
||||
value = selectedValue ?: AppSettings.get(valueClass, key, defaultValue),
|
||||
defaultValue = defaultValue
|
||||
) {
|
||||
|
||||
@@ -245,6 +245,6 @@ private inline fun <reified T> getCurrentValue(key: String, defaultValue: T): T
|
||||
if (T::class == Nothing::class) {
|
||||
throw IllegalStateException("Items with Nothing does not have a value")
|
||||
} else {
|
||||
return SettingsController.get(key, defaultValue)
|
||||
return AppSettings.get(key, defaultValue)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-7
@@ -1,15 +1,12 @@
|
||||
package com.meloda.app.fast.settings.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.meloda.app.fast.datastore.isDebugSettingsShown
|
||||
import com.meloda.app.fast.settings.HapticType
|
||||
import com.meloda.app.fast.datastore.AppSettings
|
||||
|
||||
@Immutable
|
||||
data class SettingsScreenState(
|
||||
val showOptions: SettingsShowOptions,
|
||||
val settings: List<UiItem>,
|
||||
val useHaptics: HapticType?,
|
||||
val isNeedToRequestNotificationPermission: Boolean,
|
||||
val showDebugOptions: Boolean
|
||||
) {
|
||||
|
||||
@@ -17,9 +14,7 @@ data class SettingsScreenState(
|
||||
val EMPTY: SettingsScreenState = SettingsScreenState(
|
||||
showOptions = SettingsShowOptions.EMPTY,
|
||||
settings = emptyList(),
|
||||
useHaptics = null,
|
||||
isNeedToRequestNotificationPermission = false,
|
||||
showDebugOptions = isDebugSettingsShown()
|
||||
showDebugOptions = AppSettings.Debug.showDebugCategory
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.meloda.app.fast.settings.model
|
||||
|
||||
import com.meloda.app.fast.common.UiText
|
||||
import com.meloda.app.fast.common.model.UiText
|
||||
|
||||
fun interface TextProvider<T, S : SettingsItem<T>> {
|
||||
fun provideText(item: S): UiText?
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.meloda.app.fast.settings.model
|
||||
|
||||
import com.meloda.app.fast.common.UiText
|
||||
import com.meloda.app.fast.common.model.UiText
|
||||
|
||||
fun interface TitleProvider<T, S : SettingsItem<T>> {
|
||||
fun provideTitle(item: S): UiText?
|
||||
|
||||
+12
-40
@@ -1,7 +1,5 @@
|
||||
package com.meloda.app.fast.settings.presentation
|
||||
|
||||
import android.os.PowerManager
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.calculateEndPadding
|
||||
@@ -27,17 +25,14 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.meloda.app.fast.common.UserConfig
|
||||
import com.meloda.app.fast.datastore.SettingsKeys
|
||||
import com.meloda.app.fast.datastore.UserSettings
|
||||
import com.meloda.app.fast.datastore.isUsingDarkMode
|
||||
import com.meloda.app.fast.settings.HapticType
|
||||
import com.meloda.app.fast.settings.SettingsViewModel
|
||||
import com.meloda.app.fast.settings.SettingsViewModelImpl
|
||||
import com.meloda.app.fast.settings.model.SettingsScreenState
|
||||
@@ -49,14 +44,13 @@ import com.meloda.app.fast.settings.presentation.item.TitleItem
|
||||
import com.meloda.app.fast.settings.presentation.item.TitleTextItem
|
||||
import com.meloda.app.fast.ui.components.ActionInvokeDismiss
|
||||
import com.meloda.app.fast.ui.components.MaterialDialog
|
||||
import com.meloda.app.fast.ui.theme.LocalTheme
|
||||
import com.meloda.app.fast.ui.theme.LocalThemeConfig
|
||||
import dev.chrisbanes.haze.HazeState
|
||||
import dev.chrisbanes.haze.haze
|
||||
import dev.chrisbanes.haze.hazeChild
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
import org.koin.compose.koinInject
|
||||
import com.meloda.app.fast.ui.R as UiR
|
||||
|
||||
@Composable
|
||||
@@ -66,16 +60,12 @@ fun SettingsRoute(
|
||||
onLanguageItemClicked: () -> Unit,
|
||||
viewModel: SettingsViewModel = koinViewModel<SettingsViewModelImpl>()
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val screenState by viewModel.screenState.collectAsStateWithLifecycle()
|
||||
val hapticType by viewModel.hapticType.collectAsStateWithLifecycle()
|
||||
|
||||
val userSettings: UserSettings = koinInject()
|
||||
|
||||
LaunchedEffect(true) {
|
||||
userSettings.enableDebugSettings(screenState.showDebugOptions)
|
||||
}
|
||||
|
||||
SettingsScreen(screenState = screenState,
|
||||
SettingsScreen(
|
||||
screenState = screenState,
|
||||
hapticType = hapticType,
|
||||
onBack = onBack,
|
||||
onHapticPerformed = viewModel::onHapticPerformed,
|
||||
onSettingsItemClicked = { key ->
|
||||
@@ -88,25 +78,7 @@ fun SettingsRoute(
|
||||
}
|
||||
},
|
||||
onSettingsItemLongClicked = viewModel::onSettingsItemLongClicked,
|
||||
onSettingsItemValueChanged = { key, newValue ->
|
||||
viewModel.onSettingsItemChanged(key, newValue)
|
||||
|
||||
when (key) {
|
||||
SettingsKeys.KEY_APPEARANCE_DARK_THEME -> {
|
||||
val newMode = newValue as? Int ?: 0
|
||||
AppCompatDelegate.setDefaultNightMode(newMode)
|
||||
|
||||
val isUsing = context.getSystemService<PowerManager>()?.let { manager ->
|
||||
isUsingDarkMode(
|
||||
context.resources,
|
||||
manager
|
||||
)
|
||||
} ?: false
|
||||
|
||||
userSettings.useDarkThemeChanged(isUsing)
|
||||
}
|
||||
}
|
||||
}
|
||||
onSettingsItemValueChanged = viewModel::onSettingsItemChanged
|
||||
)
|
||||
|
||||
HandlePopups(
|
||||
@@ -128,6 +100,7 @@ fun SettingsRoute(
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
screenState: SettingsScreenState = SettingsScreenState.EMPTY,
|
||||
hapticType: HapticType? = null,
|
||||
onBack: () -> Unit = {},
|
||||
onHapticPerformed: () -> Unit = {},
|
||||
onSettingsItemClicked: (key: String) -> Unit = {},
|
||||
@@ -135,7 +108,6 @@ fun SettingsScreen(
|
||||
onSettingsItemValueChanged: (key: String, newValue: Any?) -> Unit = { _, _ -> }
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val hapticType = screenState.useHaptics
|
||||
|
||||
LaunchedEffect(hapticType) {
|
||||
if (hapticType != null) {
|
||||
@@ -144,7 +116,7 @@ fun SettingsScreen(
|
||||
}
|
||||
}
|
||||
|
||||
val currentTheme = LocalTheme.current
|
||||
val themeConfig = LocalThemeConfig.current
|
||||
|
||||
val hazeState = remember { HazeState() }
|
||||
|
||||
@@ -164,12 +136,12 @@ fun SettingsScreen(
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface.copy(
|
||||
alpha = if (currentTheme.usingBlur) 0f else 1f
|
||||
alpha = if (themeConfig.enableBlur) 0f else 1f
|
||||
)
|
||||
),
|
||||
modifier = Modifier
|
||||
.then(
|
||||
if (currentTheme.usingBlur) {
|
||||
if (themeConfig.enableBlur) {
|
||||
Modifier.hazeChild(
|
||||
state = hazeState,
|
||||
style = HazeMaterials.thick()
|
||||
@@ -185,7 +157,7 @@ fun SettingsScreen(
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.then(
|
||||
if (currentTheme.usingBlur) {
|
||||
if (themeConfig.enableBlur) {
|
||||
Modifier.haze(
|
||||
state = hazeState,
|
||||
style = HazeMaterials.thick()
|
||||
|
||||
+4
-4
@@ -32,7 +32,7 @@ import com.meloda.app.fast.ui.basic.LocalContentAlpha
|
||||
import com.meloda.app.fast.ui.components.ActionInvokeDismiss
|
||||
import com.meloda.app.fast.ui.components.MaterialDialog
|
||||
import com.meloda.app.fast.ui.components.SelectionType
|
||||
import com.meloda.app.fast.ui.theme.LocalTheme
|
||||
import com.meloda.app.fast.ui.theme.LocalThemeConfig
|
||||
import com.meloda.app.fast.ui.util.ImmutableList
|
||||
import com.meloda.app.fast.ui.util.ImmutableList.Companion.toImmutableList
|
||||
|
||||
@@ -51,7 +51,7 @@ fun ListItem(
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
val currentTheme = LocalTheme.current
|
||||
val currentTheme = LocalThemeConfig.current
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
@@ -81,7 +81,7 @@ fun ListItem(
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
@@ -94,7 +94,7 @@ fun ListItem(
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.meloda.app.fast.settings.model.UiItem
|
||||
import com.meloda.app.fast.ui.basic.ContentAlpha
|
||||
import com.meloda.app.fast.ui.basic.LocalContentAlpha
|
||||
import com.meloda.app.fast.ui.theme.LocalTheme
|
||||
import com.meloda.app.fast.ui.theme.LocalThemeConfig
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
@@ -35,7 +35,7 @@ fun SwitchItem(
|
||||
) {
|
||||
if (!item.isVisible) return
|
||||
|
||||
val currentTheme = LocalTheme.current
|
||||
val currentTheme = LocalThemeConfig.current
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
@@ -65,7 +65,7 @@ fun SwitchItem(
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
@@ -78,7 +78,7 @@ fun SwitchItem(
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
|
||||
+4
-4
@@ -38,7 +38,7 @@ import com.meloda.app.fast.ui.basic.ContentAlpha
|
||||
import com.meloda.app.fast.ui.basic.LocalContentAlpha
|
||||
import com.meloda.app.fast.ui.components.ActionInvokeDismiss
|
||||
import com.meloda.app.fast.ui.components.MaterialDialog
|
||||
import com.meloda.app.fast.ui.theme.LocalTheme
|
||||
import com.meloda.app.fast.ui.theme.LocalThemeConfig
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
@@ -51,7 +51,7 @@ fun TextFieldItem(
|
||||
) {
|
||||
if (!item.isVisible) return
|
||||
|
||||
val currentTheme = LocalTheme.current
|
||||
val currentTheme = LocalThemeConfig.current
|
||||
|
||||
var showDialog by rememberSaveable {
|
||||
mutableStateOf(false)
|
||||
@@ -93,7 +93,7 @@ fun TextFieldItem(
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
@@ -106,7 +106,7 @@ fun TextFieldItem(
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.meloda.app.fast.settings.model.UiItem
|
||||
import com.meloda.app.fast.ui.theme.LocalTheme
|
||||
import com.meloda.app.fast.ui.theme.LocalThemeConfig
|
||||
|
||||
@Composable
|
||||
fun TitleItem(
|
||||
@@ -18,7 +18,7 @@ fun TitleItem(
|
||||
) {
|
||||
if (!item.isVisible) return
|
||||
|
||||
val currentTheme = LocalTheme.current
|
||||
val currentTheme = LocalThemeConfig.current
|
||||
|
||||
Text(
|
||||
text = item.title,
|
||||
@@ -32,7 +32,7 @@ fun TitleItem(
|
||||
bottom = 4.dp
|
||||
)
|
||||
.animateContentSize(),
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
|
||||
+4
-4
@@ -21,7 +21,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.meloda.app.fast.settings.model.UiItem
|
||||
import com.meloda.app.fast.ui.basic.ContentAlpha
|
||||
import com.meloda.app.fast.ui.basic.LocalContentAlpha
|
||||
import com.meloda.app.fast.ui.theme.LocalTheme
|
||||
import com.meloda.app.fast.ui.theme.LocalThemeConfig
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
@@ -33,7 +33,7 @@ fun TitleTextItem(
|
||||
) {
|
||||
if (!item.isVisible) return
|
||||
|
||||
val currentTheme = LocalTheme.current
|
||||
val currentTheme = LocalThemeConfig.current
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
@@ -62,7 +62,7 @@ fun TitleTextItem(
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
@@ -75,7 +75,7 @@ fun TitleTextItem(
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = if (currentTheme.isMultiline) Int.MAX_VALUE else 1,
|
||||
maxLines = if (currentTheme.enableMultiline) Int.MAX_VALUE else 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user