Skip to content

Commit

Permalink
chore: remove dark theme toggle
Browse files Browse the repository at this point in the history
Instead prefer to follow the device-wide theme setting.
  • Loading branch information
ajmeese7 committed Sep 17, 2024
1 parent aa2cd11 commit d3cfa7f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ class MainActivity : ComponentActivity() {

@Composable
fun WhiteroseApp(viewModel: ViewModel = viewModel()) {
val isDarkTheme by viewModel.isDarkTheme.collectAsState()
val ticksEnabled by viewModel.ticksEnabled.collectAsState()
val speechEnabled by viewModel.speechEnabled.collectAsState()
var showSettings by remember { mutableStateOf(false) }

WhiteroseTheme(darkTheme = isDarkTheme) {
WhiteroseTheme() {
Box(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier.fillMaxSize(),
Expand All @@ -62,11 +61,9 @@ fun WhiteroseApp(viewModel: ViewModel = viewModel()) {

if (showSettings) {
SettingsDialog(
isDarkTheme = isDarkTheme,
ticksEnabled = ticksEnabled,
speechEnabled = speechEnabled,
onDismiss = { showSettings = false },
onThemeChanged = viewModel::setDarkTheme,
onTicksChanged = viewModel::setTicksEnabled,
onSpeechChanged = viewModel::setSpeechEnabled
)
Expand Down Expand Up @@ -95,11 +92,9 @@ fun Clock() {

@Composable
fun SettingsDialog(
isDarkTheme: Boolean,
ticksEnabled: Boolean,
speechEnabled: Boolean,
onDismiss: () -> Unit,
onThemeChanged: (Boolean) -> Unit,
onTicksChanged: (Boolean) -> Unit,
onSpeechChanged: (Boolean) -> Unit
) {
Expand All @@ -108,17 +103,6 @@ fun SettingsDialog(
title = { Text("Settings") },
text = {
Column {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Text("Dark Theme", modifier = Modifier.weight(1f))
Switch(
checked = isDarkTheme,
onCheckedChange = onThemeChanged
)
}
Spacer(modifier = Modifier.height(8.dp))
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import java.util.concurrent.TimeUnit
class ViewModel(application: Application) : AndroidViewModel(application) {
private val prefs = application.getSharedPreferences("whiterose_prefs", Application.MODE_PRIVATE)

private val _isDarkTheme = MutableStateFlow(prefs.getBoolean("dark_theme", false))
val isDarkTheme = _isDarkTheme.asStateFlow()

private val _ticksEnabled = MutableStateFlow(prefs.getBoolean("ticks_enabled", true))
val ticksEnabled = _ticksEnabled.asStateFlow()

Expand All @@ -25,13 +22,6 @@ class ViewModel(application: Application) : AndroidViewModel(application) {
updateWorkManager()
}

fun setDarkTheme(isDark: Boolean) {
viewModelScope.launch {
_isDarkTheme.emit(isDark)
prefs.edit().putBoolean("dark_theme", isDark).apply()
}
}

fun setTicksEnabled(enabled: Boolean) {
viewModelScope.launch {
_ticksEnabled.emit(enabled)
Expand Down Expand Up @@ -67,7 +57,7 @@ class ViewModel(application: Application) : AndroidViewModel(application) {

workManager.enqueueUniquePeriodicWork(
"timeUpdate",
ExistingPeriodicWorkPolicy.REPLACE,
ExistingPeriodicWorkPolicy.UPDATE,
timeUpdateWork
)
}
Expand Down
3 changes: 1 addition & 2 deletions android/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Whiterose" parent="android:Theme.Material.Light.NoActionBar" />
</resources>
</resources>

0 comments on commit d3cfa7f

Please sign in to comment.