From 447ea85333df87632d90165d7230342a6e819ba5 Mon Sep 17 00:00:00 2001 From: bemusementpark Date: Mon, 29 Jul 2024 17:35:55 +0930 Subject: [PATCH] Improve naming --- .../appearance/AppearanceSettingsViewModel.kt | 4 ++-- ...ybeFollowSystemColors.kt => ThemeColorsProvider.kt} | 6 +++--- .../securesms/ui/theme/ThemeFromPreferences.kt | 10 ++++------ .../java/org/thoughtcrime/securesms/ui/theme/Themes.kt | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) rename app/src/main/java/org/thoughtcrime/securesms/ui/theme/{MaybeFollowSystemColors.kt => ThemeColorsProvider.kt} (60%) diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsViewModel.kt index c662a7a772..47cc9f69bf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsViewModel.kt @@ -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) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/MaybeFollowSystemColors.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeColorsProvider.kt similarity index 60% rename from app/src/main/java/org/thoughtcrime/securesms/ui/theme/MaybeFollowSystemColors.kt rename to app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeColorsProvider.kt index 6bb0d3c2ad..0713254afc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/MaybeFollowSystemColors.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeColorsProvider.kt @@ -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 } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeFromPreferences.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeFromPreferences.kt index 3b111526c7..403235ef79 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeFromPreferences.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeFromPreferences.kt @@ -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)) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/Themes.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/Themes.kt index ec19b3b100..9b83028ec8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/Themes.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/Themes.kt @@ -20,7 +20,7 @@ import org.session.libsession.utilities.AppTextSecurePreferences val LocalColors = compositionLocalOf { 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(),