Improve naming

This commit is contained in:
bemusementpark 2024-07-29 17:35:55 +09:30
parent 7bb1a3a513
commit 447ea85333
4 changed files with 11 additions and 13 deletions

View File

@ -6,7 +6,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import org.session.libsession.utilities.TextSecurePreferences 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 org.thoughtcrime.securesms.util.themeState import org.thoughtcrime.securesms.util.themeState
import javax.inject.Inject import javax.inject.Inject
@ -19,7 +19,7 @@ class AppearanceSettingsViewModel @Inject constructor(private val prefs: TextSec
fun invalidateComposeThemeColors() { fun invalidateComposeThemeColors() {
// invalidate compose theme colors // invalidate compose theme colors
cachedColors = null cachedColorsProvider = null
} }
fun setNewAccent(@StyleRes newAccentColorStyle: Int) { fun setNewAccent(@StyleRes newAccentColorStyle: Int) {

View File

@ -3,13 +3,13 @@ package org.thoughtcrime.securesms.ui.theme
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
fun interface MaybeFollowSystemColors { fun interface ThemeColorsProvider {
@Composable @Composable
fun get(): ThemeColors fun get(): ThemeColors
} }
@Suppress("FunctionName") @Suppress("FunctionName")
fun FollowSystemColors(light: ThemeColors, dark: ThemeColors) = MaybeFollowSystemColors { fun FollowSystemThemeColorsProvider(light: ThemeColors, dark: ThemeColors) = ThemeColorsProvider {
when { when {
isSystemInDarkTheme() -> dark isSystemInDarkTheme() -> dark
else -> light else -> light
@ -17,4 +17,4 @@ fun FollowSystemColors(light: ThemeColors, dark: ThemeColors) = MaybeFollowSyste
} }
@Suppress("FunctionName") @Suppress("FunctionName")
fun IgnoreSystemColors(colors: ThemeColors) = MaybeFollowSystemColors { colors } fun ThemeColorsProvider(colors: ThemeColors) = ThemeColorsProvider { colors }

View File

@ -1,7 +1,5 @@
package org.thoughtcrime.securesms.ui.theme package org.thoughtcrime.securesms.ui.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.TextSecurePreferences.Companion.BLUE_ACCENT 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 * 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 * 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() val selectedTheme = getThemeStyle()
// get the chosen primary color from the preferences // get the chosen primary color from the preferences
@ -29,12 +27,12 @@ val TextSecurePreferences.colors: MaybeFollowSystemColors get() {
val createDark = if (isOcean) ::OceanDark else ::ClassicDark val createDark = if (isOcean) ::OceanDark else ::ClassicDark
return when { return when {
getFollowSystemSettings() -> FollowSystemColors( getFollowSystemSettings() -> FollowSystemThemeColorsProvider(
light = createLight(selectedPrimary), light = createLight(selectedPrimary),
dark = createDark(selectedPrimary) dark = createDark(selectedPrimary)
) )
"light" in selectedTheme -> IgnoreSystemColors(createLight(selectedPrimary)) "light" in selectedTheme -> ThemeColorsProvider(createLight(selectedPrimary))
else -> IgnoreSystemColors(createDark(selectedPrimary)) else -> ThemeColorsProvider(createDark(selectedPrimary))
} }
} }

View File

@ -20,7 +20,7 @@ import org.session.libsession.utilities.AppTextSecurePreferences
val LocalColors = compositionLocalOf <ThemeColors> { ClassicDark() } val LocalColors = compositionLocalOf <ThemeColors> { ClassicDark() }
val LocalType = compositionLocalOf { sessionTypography } val LocalType = compositionLocalOf { sessionTypography }
var cachedColors: MaybeFollowSystemColors? = null var cachedColorsProvider: ThemeColorsProvider? = null
/** /**
* Apply a Material2 compose theme based on user selections in SharedPreferences. * Apply a Material2 compose theme based on user selections in SharedPreferences.
@ -32,7 +32,7 @@ fun SessionMaterialTheme(
val context = LocalContext.current val context = LocalContext.current
val preferences = AppTextSecurePreferences(context) val preferences = AppTextSecurePreferences(context)
val cachedColors = cachedColors ?: preferences.colors.also { cachedColors = it } val cachedColors = cachedColorsProvider ?: preferences.getColorsProvider().also { cachedColorsProvider = it }
SessionMaterialTheme( SessionMaterialTheme(
colors = cachedColors.get(), colors = cachedColors.get(),