mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: add high-contrast theme with accessible message bubbles (#5135)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
f48fc61729
commit
fa63a4ac50
19 changed files with 328 additions and 65 deletions
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2025-2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.domain.usecase.settings
|
||||
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.repository.UiPrefs
|
||||
|
||||
@Single
|
||||
open class SetContrastLevelUseCase constructor(private val uiPrefs: UiPrefs) {
|
||||
operator fun invoke(value: Int) {
|
||||
uiPrefs.setContrastLevel(value)
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,13 @@ class UiPrefsImpl(
|
|||
scope.launch { dataStore.edit { it[KEY_THEME] = value } }
|
||||
}
|
||||
|
||||
override val contrastLevel: StateFlow<Int> =
|
||||
dataStore.data.map { it[KEY_CONTRAST_LEVEL] ?: 0 }.stateIn(scope, SharingStarted.Lazily, 0)
|
||||
|
||||
override fun setContrastLevel(value: Int) {
|
||||
scope.launch { dataStore.edit { it[KEY_CONTRAST_LEVEL] = value } }
|
||||
}
|
||||
|
||||
override val locale: StateFlow<String> =
|
||||
dataStore.data.map { it[KEY_LOCALE] ?: "" }.stateIn(scope, SharingStarted.Eagerly, "")
|
||||
|
||||
|
|
@ -152,6 +159,7 @@ class UiPrefsImpl(
|
|||
|
||||
val KEY_APP_INTRO_COMPLETED = booleanPreferencesKey("app_intro_completed")
|
||||
val KEY_THEME = intPreferencesKey("theme")
|
||||
val KEY_CONTRAST_LEVEL = intPreferencesKey("contrast-level")
|
||||
val KEY_LOCALE = stringPreferencesKey("locale")
|
||||
val KEY_NODE_SORT = intPreferencesKey("node-sort-option")
|
||||
val KEY_INCLUDE_UNKNOWN = booleanPreferencesKey("include-unknown")
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ interface UiPrefs {
|
|||
|
||||
fun setTheme(value: Int)
|
||||
|
||||
val contrastLevel: StateFlow<Int>
|
||||
|
||||
fun setContrastLevel(value: Int)
|
||||
|
||||
val locale: StateFlow<String>
|
||||
|
||||
fun setLocale(languageTag: String)
|
||||
|
|
|
|||
|
|
@ -278,10 +278,15 @@
|
|||
<string name="reset_to_defaults">Reset to defaults</string>
|
||||
<string name="apply">Apply</string>
|
||||
<string name="theme">Theme</string>
|
||||
<string name="contrast">Contrast</string>
|
||||
<string name="theme_light">Light</string>
|
||||
<string name="theme_dark">Dark</string>
|
||||
<string name="theme_system">System default</string>
|
||||
<string name="choose_theme">Choose theme</string>
|
||||
<string name="choose_contrast">Contrast level</string>
|
||||
<string name="contrast_standard">Standard</string>
|
||||
<string name="contrast_medium">Medium</string>
|
||||
<string name="contrast_high">High</string>
|
||||
<string name="provide_location_to_mesh">Provide phone location to mesh</string>
|
||||
<string name="use_homoglyph_characters_encoding">Compact encoding for Cyrillic</string>
|
||||
<plurals name="delete_messages">
|
||||
|
|
|
|||
|
|
@ -84,6 +84,12 @@ class FakeUiPrefs : UiPrefs {
|
|||
theme.value = value
|
||||
}
|
||||
|
||||
override val contrastLevel = MutableStateFlow(0)
|
||||
|
||||
override fun setContrastLevel(value: Int) {
|
||||
contrastLevel.value = value
|
||||
}
|
||||
|
||||
override val locale = MutableStateFlow("en")
|
||||
|
||||
override fun setLocale(languageTag: String) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2025-2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.ui.theme
|
||||
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
|
||||
/**
|
||||
* Application-wide contrast level for accessibility.
|
||||
*
|
||||
* [STANDARD] keeps the default Material 3 color scheme. [MEDIUM] uses Material 3 medium-contrast color tokens and
|
||||
* increases message bubble opacity. [HIGH] uses Material 3 high-contrast color tokens, forces `onSurface` text in
|
||||
* message bubbles, and replaces translucent node-color fills with opaque theme surfaces plus accent borders.
|
||||
*/
|
||||
enum class ContrastLevel(val value: Int) {
|
||||
STANDARD(0),
|
||||
MEDIUM(1),
|
||||
HIGH(2),
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun fromValue(value: Int): ContrastLevel = entries.firstOrNull { it.value == value } ?: STANDARD
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Composition local providing the current [ContrastLevel].
|
||||
*
|
||||
* Read by components that need to adapt their rendering for accessibility (e.g. message bubbles, signal indicators).
|
||||
*/
|
||||
val LocalContrastLevel = staticCompositionLocalOf { ContrastLevel.STANDARD }
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@file:Suppress("UnusedPrivateProperty")
|
||||
@file:Suppress("MatchingDeclarationName")
|
||||
|
||||
package org.meshtastic.core.ui.theme
|
||||
|
||||
|
|
@ -25,6 +25,7 @@ import androidx.compose.material3.MotionScheme.Companion.expressive
|
|||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
|
|
@ -272,19 +273,33 @@ val unspecified_scheme = ColorFamily(Color.Unspecified, Color.Unspecified, Color
|
|||
fun AppTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
dynamicColor: Boolean = true,
|
||||
contrastLevel: ContrastLevel = ContrastLevel.STANDARD,
|
||||
content:
|
||||
@Composable()
|
||||
() -> Unit,
|
||||
) {
|
||||
val dynamicScheme = if (dynamicColor) dynamicColorScheme(darkTheme) else null
|
||||
val colorScheme = dynamicScheme ?: if (darkTheme) darkScheme else lightScheme
|
||||
val dynamicScheme =
|
||||
if (dynamicColor && contrastLevel == ContrastLevel.STANDARD) {
|
||||
dynamicColorScheme(darkTheme)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val colorScheme =
|
||||
dynamicScheme
|
||||
?: when (contrastLevel) {
|
||||
ContrastLevel.MEDIUM -> if (darkTheme) mediumContrastDarkColorScheme else mediumContrastLightColorScheme
|
||||
ContrastLevel.HIGH -> if (darkTheme) highContrastDarkColorScheme else highContrastLightColorScheme
|
||||
else -> if (darkTheme) darkScheme else lightScheme
|
||||
}
|
||||
|
||||
MaterialExpressiveTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = AppTypography,
|
||||
motionScheme = expressive(),
|
||||
content = content,
|
||||
)
|
||||
CompositionLocalProvider(LocalContrastLevel provides contrastLevel) {
|
||||
MaterialExpressiveTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = AppTypography,
|
||||
motionScheme = expressive(),
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const val MODE_DYNAMIC = 6969420
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ class UIViewModel(
|
|||
}
|
||||
|
||||
val theme: StateFlow<Int> = uiPrefs.theme
|
||||
val contrastLevel: StateFlow<Int> = uiPrefs.contrastLevel
|
||||
|
||||
val firmwareEdition = meshLogRepository.getMyNodeInfo().map { nodeInfo -> nodeInfo?.firmware_edition }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue