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
20 changes: 17 additions & 3 deletions app/src/main/java/moe/apex/breadboard/preferences/Pref.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ data object PrefNames {
const val INTERNAL_IGNORE_LIST = "internal_ignore_list"
const val AUTOPLAY_VIDEOS = "autoplay_videos"
const val UNIFIED_INFO_SHEET = "unified_info_sheet"
const val DARK_THEME = "dark_theme"
}


Expand Down Expand Up @@ -131,6 +132,7 @@ object PreferenceKeys {
val INTERNAL_IGNORE_LIST = stringSetPreferencesKey(PrefNames.INTERNAL_IGNORE_LIST)
val AUTOPLAY_VIDEOS = stringPreferencesKey(PrefNames.AUTOPLAY_VIDEOS)
val UNIFIED_INFO_SHEET = booleanPreferencesKey(PrefNames.UNIFIED_INFO_SHEET)
var DARK_THEME = stringPreferencesKey(PrefNames.DARK_THEME)
}


Expand Down Expand Up @@ -228,7 +230,8 @@ data class Prefs(
val internalIgnoreListTimestamp: Long,
val internalIgnoreList: Set<String>,
val autoplayVideos: AutoplayVideosMode,
val unifiedInfoSheet: Boolean
val unifiedInfoSheet: Boolean,
val darkTheme: DarkTheme,
) {
companion object {
val DEFAULT = Prefs(
Expand Down Expand Up @@ -262,6 +265,7 @@ data class Prefs(
internalIgnoreList = emptySet(),
autoplayVideos = AutoplayVideosMode.OFF,
unifiedInfoSheet = false, // Unified is called 'Classic' in the UI
darkTheme = DarkTheme.AUTO
)
}

Expand Down Expand Up @@ -325,7 +329,8 @@ class UserPreferencesRepository(private val dataStore: DataStore<Preferences>) {
PreferenceKeys.RECOMMENDATIONS_WEIGHTED_SELECTION to PrefMeta(PrefCategory.SETTING),
PreferenceKeys.INTERNAL_IGNORE_LIST_TIMESTAMP to PrefMeta(PrefCategory.SETTING, exportable = false),
PreferenceKeys.INTERNAL_IGNORE_LIST to PrefMeta(PrefCategory.SETTING, exportable = false),
PreferenceKeys.UNIFIED_INFO_SHEET to PrefMeta(PrefCategory.SETTING)
PreferenceKeys.UNIFIED_INFO_SHEET to PrefMeta(PrefCategory.SETTING),
PreferenceKeys.DARK_THEME to PrefMeta(PrefCategory.SETTING)
)
}

Expand Down Expand Up @@ -809,6 +814,8 @@ class UserPreferencesRepository(private val dataStore: DataStore<Preferences>) {
val autoplayVideos = preferences[PreferenceKeys.AUTOPLAY_VIDEOS]?.let { AutoplayVideosMode.valueOf(it) } ?: Prefs.DEFAULT.autoplayVideos
val unifiedInfoSheet = preferences[PreferenceKeys.UNIFIED_INFO_SHEET] ?: Prefs.DEFAULT.unifiedInfoSheet

val darkTheme = preferences[PreferenceKeys.DARK_THEME]?.let { DarkTheme.valueOf(it) } ?: Prefs.DEFAULT.darkTheme

return Prefs(
dataSaver,
storageLocation,
Expand Down Expand Up @@ -839,7 +846,8 @@ class UserPreferencesRepository(private val dataStore: DataStore<Preferences>) {
internalIgnoreListTimestamp,
internalIgnoreList,
autoplayVideos,
unifiedInfoSheet
unifiedInfoSheet,
darkTheme,
)
}
}
Expand All @@ -854,3 +862,9 @@ enum class ImageSource(override val label: String, val imageBoard: ImageBoard) :
YANDERE("Yande.re", Yandere),
R34("Rule34", Rule34)
}

enum class DarkTheme(override val label: String) : PrefEnum<DarkTheme> {
ON("Always"),
OFF("Never"),
AUTO("Follow system")
}
21 changes: 21 additions & 0 deletions app/src/main/java/moe/apex/breadboard/preferences/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,27 @@ fun PreferencesScreen(navController: NavHostController) {
}
}
}

item {
ExpressiveGroup(title = "Appearance") {
Comment thread
apex2504 marked this conversation as resolved.
item {
EnumPref(
title = "Dark theme",
summary = currentSettings.darkTheme.label,
enumItems = DarkTheme.entries,
selectedItem = currentSettings.darkTheme,
onSelection = {
scope.launch {
preferencesRepository.updatePref(
PreferenceKeys.DARK_THEME,
it
)
}
}
)
}
}
}

item {
ExpressiveGroup(title = "Content") {
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/moe/apex/breadboard/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import moe.apex.breadboard.preferences.LocalPreferences
import moe.apex.breadboard.preferences.DarkTheme


private val DarkColorScheme = darkColorScheme(
Expand Down Expand Up @@ -53,11 +55,20 @@ val LocalBreadboardColors = staticCompositionLocalOf {
)
}

@Composable
fun shouldUseDarkTheme(): Boolean {
val preferences = LocalPreferences.current

val userSelectedDarkMode = preferences.darkTheme == DarkTheme.ON
val followSystemDarkMode = preferences.darkTheme == DarkTheme.AUTO && isSystemInDarkTheme()

return userSelectedDarkMode || followSystemDarkMode
}

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun BreadboardTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
darkTheme: Boolean = shouldUseDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
Expand Down