mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-28 11:22:14 +00:00
Fix follow light
This commit is contained in:
parent
2818552519
commit
80d08a5fb2
@ -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.selectedTheme
|
||||
import org.thoughtcrime.securesms.ui.theme.selectedColorSet
|
||||
import org.thoughtcrime.securesms.util.ThemeState
|
||||
import org.thoughtcrime.securesms.util.themeState
|
||||
import javax.inject.Inject
|
||||
@ -21,6 +21,9 @@ class AppearanceSettingsViewModel @Inject constructor(private val prefs: TextSec
|
||||
prefs.setAccentColorStyle(newAccentColorStyle)
|
||||
// update UI state
|
||||
_uiState.value = prefs.themeState()
|
||||
|
||||
// force compose to refresh its style reference
|
||||
selectedColorSet = null
|
||||
}
|
||||
|
||||
fun setNewStyle(newThemeStyle: String) {
|
||||
@ -29,7 +32,7 @@ class AppearanceSettingsViewModel @Inject constructor(private val prefs: TextSec
|
||||
_uiState.value = prefs.themeState()
|
||||
|
||||
// force compose to refresh its style reference
|
||||
selectedTheme = null
|
||||
selectedColorSet = null
|
||||
}
|
||||
|
||||
fun setNewFollowSystemSettings(followSystemSettings: Boolean) {
|
||||
@ -37,7 +40,7 @@ class AppearanceSettingsViewModel @Inject constructor(private val prefs: TextSec
|
||||
_uiState.value = prefs.themeState()
|
||||
|
||||
// force compose to refresh its style reference
|
||||
selectedTheme = null
|
||||
selectedColorSet = null
|
||||
}
|
||||
|
||||
}
|
@ -7,4 +7,6 @@ package org.thoughtcrime.securesms.ui.theme
|
||||
data class ThemeColorSet(
|
||||
val light: ThemeColors,
|
||||
val dark: ThemeColors
|
||||
)
|
||||
) {
|
||||
fun get(isDark: Boolean): ThemeColors = if (isDark) dark else light
|
||||
}
|
||||
|
@ -17,38 +17,28 @@ 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
|
||||
*/
|
||||
@Composable
|
||||
fun TextSecurePreferences.getComposeTheme(): ThemeColors {
|
||||
fun TextSecurePreferences.getColorSet(): ThemeColorSet {
|
||||
val selectedTheme = getThemeStyle()
|
||||
|
||||
// get the chosen primary color from the preferences
|
||||
val selectedPrimary = primaryColor()
|
||||
|
||||
// create a theme set with the appropriate primary
|
||||
val colorSet = when(selectedTheme){
|
||||
TextSecurePreferences.OCEAN_DARK,
|
||||
TextSecurePreferences.OCEAN_LIGHT -> ThemeColorSet(
|
||||
light = OceanLight(selectedPrimary),
|
||||
dark = OceanDark(selectedPrimary)
|
||||
)
|
||||
val createLight = if ("ocean" in selectedTheme) ::OceanLight else ::ClassicLight
|
||||
val createDark = if ("ocean" in selectedTheme) ::OceanDark else ::ClassicDark
|
||||
|
||||
else -> ThemeColorSet(
|
||||
light = ClassicLight(selectedPrimary),
|
||||
dark = ClassicDark(selectedPrimary)
|
||||
val followSystemSettings = getFollowSystemSettings()
|
||||
|
||||
return if (followSystemSettings) ThemeColorSet(
|
||||
light = createLight(selectedPrimary),
|
||||
dark = createDark(selectedPrimary)
|
||||
) else {
|
||||
val both = if ("light" in selectedTheme) createLight(selectedPrimary) else createDark(selectedPrimary)
|
||||
|
||||
ThemeColorSet(
|
||||
light = both,
|
||||
dark = both
|
||||
)
|
||||
}
|
||||
|
||||
// deliver the right set from the light/dark mode chosen
|
||||
val theme = when{
|
||||
getFollowSystemSettings() -> if(isSystemInDarkTheme()) colorSet.dark else colorSet.light
|
||||
|
||||
selectedTheme == TextSecurePreferences.CLASSIC_LIGHT ||
|
||||
selectedTheme == TextSecurePreferences.OCEAN_LIGHT -> colorSet.light
|
||||
|
||||
else -> colorSet.dark
|
||||
}
|
||||
|
||||
return theme
|
||||
}
|
||||
|
||||
fun TextSecurePreferences.primaryColor(): Color = when(getSelectedAccentColor()) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.ui.theme
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
|
||||
@ -15,12 +16,13 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.session.libsession.utilities.AppTextSecurePreferences
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
|
||||
// Globally accessible composition local objects
|
||||
val LocalColors = compositionLocalOf <ThemeColors> { ClassicDark() }
|
||||
val LocalType = compositionLocalOf { sessionTypography }
|
||||
|
||||
var selectedTheme: ThemeColors? = null
|
||||
var selectedColorSet: ThemeColorSet? = null
|
||||
|
||||
/**
|
||||
* Apply a Material2 compose theme based on user selections in SharedPreferences.
|
||||
@ -29,15 +31,15 @@ var selectedTheme: ThemeColors? = null
|
||||
fun SessionMaterialTheme(
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
// set the theme data if it hasn't been done yet
|
||||
if(selectedTheme == null) {
|
||||
// Some values can be set from the preferences, and if not should fallback to a default value
|
||||
val context = LocalContext.current
|
||||
val preferences = AppTextSecurePreferences(context)
|
||||
selectedTheme = preferences.getComposeTheme()
|
||||
}
|
||||
val context = LocalContext.current
|
||||
val preferences = AppTextSecurePreferences(context)
|
||||
|
||||
SessionMaterialTheme(colors = selectedTheme ?: ClassicDark()) { content() }
|
||||
val selectedColorSet = selectedColorSet ?: preferences.getColorSet().also { selectedColorSet = it }
|
||||
|
||||
SessionMaterialTheme(
|
||||
colors = selectedColorSet.get(isSystemInDarkTheme()),
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user