Skip to content

Commit

Permalink
show current theme in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sdex committed Aug 12, 2021
1 parent 7b43b8e commit 7b3a2c5
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ManifestViewerActivity : BaseActivity() {
}
}

private fun isNightTheme(theme: Int) =
private fun isNightTheme(@AppCompatDelegate.NightMode theme: Int) =
theme == AppCompatDelegate.MODE_NIGHT_YES ||
(theme == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM &&
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AppPreferences(context: Context) {
val isRootIntegrationEnabled: Boolean
get() = userPreferences.getBoolean(KEY_ROOT_INTEGRATION, false)

@AppCompatDelegate.NightMode
val theme: Int
get() = userPreferences.getString(KEY_THEME, null)?.toInt()
?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import com.sdex.commons.BaseActivity

class SettingsActivity : BaseActivity() {

override fun getLayout(): Int {
return R.layout.activity_settings
}
override fun getLayout() = R.layout.activity_settings

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ class SettingsFragment : PreferenceFragmentCompat() {
}

val themePreference = findPreference(KEY_THEME) as ListPreference?
themePreference?.setOnPreferenceChangeListener { _, newValue ->
AppCompatDelegate.setDefaultNightMode(newValue.toString().toInt())
return@setOnPreferenceChangeListener true
themePreference?.summary = getCurrentTheme(AppPreferences(requireContext()).theme)
themePreference?.setOnPreferenceChangeListener { _, newValue ->
AppCompatDelegate.setDefaultNightMode(newValue.toString().toInt())
themePreference.summary = getCurrentTheme(newValue.toString().toInt())
return@setOnPreferenceChangeListener true
}
}

private fun getCurrentTheme(@AppCompatDelegate.NightMode theme: Int): CharSequence? {
val values = resources.getStringArray(R.array.pref_appearance_theme_list_titles)
return when (theme) {
AppCompatDelegate.MODE_NIGHT_NO -> values[1]
AppCompatDelegate.MODE_NIGHT_YES -> values[2]
else -> values[0]
}
}

Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
<!-- settings -->
<string name="pref_header_appearance">Внешний вид</string>
<string name="pref_appearance_theme_title">Тема</string>
<string name="pref_appearance_theme_summary">Установить тему приложения</string>
<string name="pref_appearance_theme_black_title">Черный цвет</string>
<string name="pref_appearance_theme_black_summary">Для AMOLED экранов</string>

<string name="pref_header_advanced">Дополнительно</string>
<string name="pref_advanced_system_apps_title">Индикатор системных приложений</string>
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@
<!-- settings -->
<string name="pref_header_appearance">Appearance</string>
<string name="pref_appearance_theme_title">Theme</string>
<string name="pref_appearance_theme_summary">Set application theme</string>
<string name="pref_appearance_theme_black_title">True black color</string>
<string name="pref_appearance_theme_black_summary">For AMOLED screens</string>

<string name="pref_header_advanced">Advanced</string>
<string name="pref_advanced_system_apps_title">Show system app indicator</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/xml/pref_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
android:entries="@array/pref_appearance_theme_list_titles"
android:entryValues="@array/pref_appearance_theme_list_values"
android:key="appearance_theme"
android:summary="@string/pref_appearance_theme_summary"
android:title="@string/pref_appearance_theme_title" />

</androidx.preference.PreferenceCategory>
Expand Down

0 comments on commit 7b3a2c5

Please sign in to comment.