Skip to content

Commit

Permalink
Merge branch 'master' into release_9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NUmeroAndDev authored Sep 5, 2019
2 parents 058c81b + 45f4739 commit 609c761
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.numero.sojodia.extension

import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import com.numero.sojodia.model.AppTheme

fun AppTheme.applyApplication() {
val mode = when (this) {
AppTheme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
AppTheme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
AppTheme.SYSTEM_DEFAULT -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
AppTheme.AUTO_BATTERY -> AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
AppTheme.SYSTEM_DEFAULT -> if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
} else {
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
}
AppCompatDelegate.setDefaultNightMode(mode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.numero.sojodia.ui.settings

import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -113,7 +114,7 @@ class SettingsActivity : AppCompatActivity() {
R.id.theme_light -> AppTheme.LIGHT
R.id.theme_dark -> AppTheme.DARK
R.id.theme_system -> AppTheme.SYSTEM_DEFAULT
R.id.theme_auto_battery -> AppTheme.AUTO_BATTERY
R.id.theme_auto_battery -> AppTheme.SYSTEM_DEFAULT
else -> throw Exception()
}
configRepository.appTheme = theme
Expand All @@ -130,8 +131,11 @@ class SettingsActivity : AppCompatActivity() {
return when (this) {
AppTheme.LIGHT -> R.string.theme_light
AppTheme.DARK -> R.string.theme_dark
AppTheme.SYSTEM_DEFAULT -> R.string.theme_system_default
AppTheme.AUTO_BATTERY -> R.string.theme_auto_battery
AppTheme.SYSTEM_DEFAULT -> if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
R.string.theme_auto_battery
} else {
R.string.theme_system_default
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions model/src/main/java/com/numero/sojodia/model/AppTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ enum class AppTheme(val key: String) {

LIGHT("LIGHT"),
DARK("DARK"),
SYSTEM_DEFAULT("SYSTEM_DEFAULT"),
AUTO_BATTERY("AUTO_BATTERY");
SYSTEM_DEFAULT("SYSTEM_DEFAULT");

companion object {
fun from(key: String): AppTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConfigRepositoryImpl(context: Context) : ConfigRepository {
}
}
get() {
val entry = sharedPreferences.getStringOrThrow(KEY_APP_THEME, AppTheme.LIGHT.key)
val entry = sharedPreferences.getStringOrThrow(KEY_APP_THEME, AppTheme.SYSTEM_DEFAULT.key)
return AppTheme.from(entry)
}

Expand Down

0 comments on commit 609c761

Please sign in to comment.