Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/java/pm/antani/resentin/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ class MainActivity : ComponentActivity() {
val lineHeightScale by container.appPreferences.lineHeightScale.collectAsState(initial = 1f)
val messageDensity by container.appPreferences.messageDensity.collectAsState(initial = MessageDensity.NORMAL)
val themeMode by container.appPreferences.themeMode.collectAsState(initial = ThemeMode.SYSTEM)
val dynamicColor by container.appPreferences.dynamicColor.collectAsState(initial = false)
val useDarkTheme = when (themeMode) {
ThemeMode.LIGHT -> false
ThemeMode.DARK -> true
ThemeMode.SYSTEM -> isSystemInDarkTheme()
}
ResentinTheme(
darkTheme = useDarkTheme,
dynamicColor = dynamicColor,
fontScale = fontScale,
lineHeightScale = lineHeightScale,
fontFamilyChoice = fontFamily,
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/pm/antani/resentin/data/prefs/AppPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class AppPreferences(private val context: Context) {
private val keyLineSpacing = stringPreferencesKey("line_spacing")
private val keyLineHeightScale = floatPreferencesKey("line_height_scale")
private val keyDismissedUpdateVersion = stringPreferencesKey("dismissed_update_version")
private val keyDynamicColor = booleanPreferencesKey("dynamic_color")

val pinnedChannels: Flow<Set<String>> = context.dataStore.data.map { it[keyPinnedChannels] ?: emptySet() }

Expand Down Expand Up @@ -349,4 +350,13 @@ class AppPreferences(private val context: Context) {
if (epochMillis != null) it[keyPushDecryptionFailureAt] = epochMillis else it.remove(keyPushDecryptionFailureAt)
}
}

/** Material You dynamic color (Android 12+): system palette derived from
* the wallpaper instead of the hand-tuned Resentin palette. Off by
* default to preserve the app's visual identity. */
val dynamicColor: Flow<Boolean> = context.dataStore.data.map { it[keyDynamicColor] ?: false }

suspend fun setDynamicColor(value: Boolean) {
context.dataStore.edit { it[keyDynamicColor] = value }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ fun AppSettingsScreen(viewModel: AppSettingsViewModel, onBack: () -> Unit, onAdm
val unreadFirst by viewModel.unreadFirst.collectAsState()
val fontScale by viewModel.fontScale.collectAsState()
val themeMode by viewModel.themeMode.collectAsState()
val dynamicColor by viewModel.dynamicColor.collectAsState()
val fontFamily by viewModel.fontFamily.collectAsState()
val chatFontFamily by viewModel.chatFontFamily.collectAsState()
val fontFamilyOptions = appFontFamilyOptions()
Expand Down Expand Up @@ -398,6 +399,17 @@ fun AppSettingsScreen(viewModel: AppSettingsViewModel, onBack: () -> Unit, onAdm
),
onSelected = viewModel::setThemeMode,
)
// Material You esiste solo da Android 12 (API 31): sotto,
// la voce non viene mostrata proprio.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
SettingsRowDivider()
SettingsSwitchRow(
title = stringResource(R.string.settings_dynamic_color),
description = stringResource(R.string.settings_dynamic_color_desc),
checked = dynamicColor,
onCheckedChange = viewModel::setDynamicColor,
)
}
SettingsRowDivider()
SettingsBlockLabel(
text = stringResource(R.string.settings_language),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ class AppSettingsViewModel(
viewModelScope.launch { appPreferences.setReplyStyle(style) }
}

val dynamicColor: StateFlow<Boolean> = appPreferences.dynamicColor
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)

fun setDynamicColor(enabled: Boolean) {
viewModelScope.launch { appPreferences.setDynamicColor(enabled) }
}

fun onReplyCustomTemplateChange(value: String) =
_uiState.update { it.copy(replyCustomTemplate = value, replyCustomTemplateSaved = false) }

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/pm/antani/resentin/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fun HomeScreen(
Surface(
modifier = Modifier.size(40.dp),
shape = MaterialTheme.shapes.extraSmall,
color = Color(0xFF4E342E),
color = MaterialTheme.colorScheme.primaryContainer,
) {
androidx.compose.foundation.Image(
painter = androidx.compose.ui.res.painterResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fun LoginScreen(viewModel: LoginViewModel) {
Surface(
modifier = Modifier.size(72.dp),
shape = MaterialTheme.shapes.large,
color = androidx.compose.ui.graphics.Color(0xFF4E342E),
color = MaterialTheme.colorScheme.primaryContainer,
) {
androidx.compose.foundation.Image(
painter = androidx.compose.ui.res.painterResource(
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/pm/antani/resentin/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Shapes
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import pm.antani.resentin.data.prefs.AppFontFamily
Expand Down Expand Up @@ -108,7 +111,14 @@ fun ResentinTheme(
chatFontFamilyChoice: AppFontFamily = AppFontFamily.SYSTEM,
content: @Composable () -> Unit,
) {
// Material You: palette generata dal sistema dai colori dello sfondo
// (Android 12+). Sotto API 31, o a toggle spento, resta la palette
// Resentin curata a mano. Forme, tipografia e scale non cambiano mai.
val colorScheme = when {
dynamicColor && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
<string name="settings_theme_system">System</string>
<string name="settings_theme_light">Light</string>
<string name="settings_theme_dark">Dark</string>
<string name="settings_dynamic_color">Dynamic colors</string>
<string name="settings_dynamic_color_desc">Match your wallpaper colors (Material You, Android 12+)</string>
<string name="settings_font_family">App font</string>
<string name="settings_font_family_desc">Applies across the app interface.</string>
<string name="settings_chat_font_family">Chat font</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@
<string name="settings_theme_system">Sistema</string>
<string name="settings_theme_light">Chiaro</string>
<string name="settings_theme_dark">Scuro</string>
<string name="settings_dynamic_color">Colori dinamici</string>
<string name="settings_dynamic_color_desc">Usa i colori dello sfondo del telefono (Material You, Android 12+)</string>
<string name="settings_font_family">Font dell’app</string>
<string name="settings_font_family_desc">Si applica a tutta l’interfaccia.</string>
<string name="settings_chat_font_family">Font della chat</string>
Expand Down