mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-21 15:05:19 +00:00
Improve naming
This commit is contained in:
parent
7bb1a3a513
commit
447ea85333
@ -6,7 +6,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.ui.theme.cachedColors
|
||||
import org.thoughtcrime.securesms.ui.theme.cachedColorsProvider
|
||||
import org.thoughtcrime.securesms.util.ThemeState
|
||||
import org.thoughtcrime.securesms.util.themeState
|
||||
import javax.inject.Inject
|
||||
@ -19,7 +19,7 @@ class AppearanceSettingsViewModel @Inject constructor(private val prefs: TextSec
|
||||
|
||||
fun invalidateComposeThemeColors() {
|
||||
// invalidate compose theme colors
|
||||
cachedColors = null
|
||||
cachedColorsProvider = null
|
||||
}
|
||||
|
||||
fun setNewAccent(@StyleRes newAccentColorStyle: Int) {
|
||||
|
@ -3,13 +3,13 @@ package org.thoughtcrime.securesms.ui.theme
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
fun interface MaybeFollowSystemColors {
|
||||
fun interface ThemeColorsProvider {
|
||||
@Composable
|
||||
fun get(): ThemeColors
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun FollowSystemColors(light: ThemeColors, dark: ThemeColors) = MaybeFollowSystemColors {
|
||||
fun FollowSystemThemeColorsProvider(light: ThemeColors, dark: ThemeColors) = ThemeColorsProvider {
|
||||
when {
|
||||
isSystemInDarkTheme() -> dark
|
||||
else -> light
|
||||
@ -17,4 +17,4 @@ fun FollowSystemColors(light: ThemeColors, dark: ThemeColors) = MaybeFollowSyste
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun IgnoreSystemColors(colors: ThemeColors) = MaybeFollowSystemColors { colors }
|
||||
fun ThemeColorsProvider(colors: ThemeColors) = ThemeColorsProvider { colors }
|
@ -1,7 +1,5 @@
|
||||
package org.thoughtcrime.securesms.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.TextSecurePreferences.Companion.BLUE_ACCENT
|
||||
@ -17,7 +15,7 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.YELLOW_A
|
||||
* Some behaviour is hardcoded to cater for legacy usage of people with themes already set
|
||||
* But future themes will be picked and set directly from the "Appearance" screen
|
||||
*/
|
||||
val TextSecurePreferences.colors: MaybeFollowSystemColors get() {
|
||||
fun TextSecurePreferences.getColorsProvider(): ThemeColorsProvider {
|
||||
val selectedTheme = getThemeStyle()
|
||||
|
||||
// get the chosen primary color from the preferences
|
||||
@ -29,12 +27,12 @@ val TextSecurePreferences.colors: MaybeFollowSystemColors get() {
|
||||
val createDark = if (isOcean) ::OceanDark else ::ClassicDark
|
||||
|
||||
return when {
|
||||
getFollowSystemSettings() -> FollowSystemColors(
|
||||
getFollowSystemSettings() -> FollowSystemThemeColorsProvider(
|
||||
light = createLight(selectedPrimary),
|
||||
dark = createDark(selectedPrimary)
|
||||
)
|
||||
"light" in selectedTheme -> IgnoreSystemColors(createLight(selectedPrimary))
|
||||
else -> IgnoreSystemColors(createDark(selectedPrimary))
|
||||
"light" in selectedTheme -> ThemeColorsProvider(createLight(selectedPrimary))
|
||||
else -> ThemeColorsProvider(createDark(selectedPrimary))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import org.session.libsession.utilities.AppTextSecurePreferences
|
||||
val LocalColors = compositionLocalOf <ThemeColors> { ClassicDark() }
|
||||
val LocalType = compositionLocalOf { sessionTypography }
|
||||
|
||||
var cachedColors: MaybeFollowSystemColors? = null
|
||||
var cachedColorsProvider: ThemeColorsProvider? = null
|
||||
|
||||
/**
|
||||
* Apply a Material2 compose theme based on user selections in SharedPreferences.
|
||||
@ -32,7 +32,7 @@ fun SessionMaterialTheme(
|
||||
val context = LocalContext.current
|
||||
val preferences = AppTextSecurePreferences(context)
|
||||
|
||||
val cachedColors = cachedColors ?: preferences.colors.also { cachedColors = it }
|
||||
val cachedColors = cachedColorsProvider ?: preferences.getColorsProvider().also { cachedColorsProvider = it }
|
||||
|
||||
SessionMaterialTheme(
|
||||
colors = cachedColors.get(),
|
||||
|
Loading…
Reference in New Issue
Block a user