Use default shared preferences for UI mode utils.

This commit is contained in:
Anton Chekulaev 2020-08-27 14:52:57 +10:00
parent 1cc1afb8bf
commit 83a36b327a
2 changed files with 4 additions and 4 deletions

View File

@ -11,7 +11,7 @@ import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
class ChangeUiModeDialog : DialogFragment() { class ChangeUiModeDialog : DialogFragment() {
companion object { companion object {
public const val TAG = "ChangeUiModeDialog" const val TAG = "ChangeUiModeDialog"
} }
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

View File

@ -3,18 +3,18 @@ package org.thoughtcrime.securesms.loki.utilities
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceManager
/** /**
* Day/night UI mode related utilities. * Day/night UI mode related utilities.
* @see <a href="https://developer.android.com/guide/topics/ui/look-and-feel/darktheme">Official Documentation</a> * @see <a href="https://developer.android.com/guide/topics/ui/look-and-feel/darktheme">Official Documentation</a>
*/ */
object UiModeUtilities { object UiModeUtilities {
private const val PREF_FILE_NAME = "UiModeUtilities"
private const val PREF_KEY_SELECTED_UI_MODE = "SELECTED_UI_MODE" private const val PREF_KEY_SELECTED_UI_MODE = "SELECTED_UI_MODE"
@JvmStatic @JvmStatic
public fun setUserSelectedUiMode(context: Context, uiMode: UiMode) { public fun setUserSelectedUiMode(context: Context, uiMode: UiMode) {
val prefs = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs.edit() prefs.edit()
.putString(PREF_KEY_SELECTED_UI_MODE, uiMode.name) .putString(PREF_KEY_SELECTED_UI_MODE, uiMode.name)
.apply() .apply()
@ -23,7 +23,7 @@ object UiModeUtilities {
@JvmStatic @JvmStatic
public fun getUserSelectedUiMode(context: Context): UiMode { public fun getUserSelectedUiMode(context: Context): UiMode {
val prefs = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val selectedUiModeName = prefs.getString(PREF_KEY_SELECTED_UI_MODE, UiMode.SYSTEM_DEFAULT.name)!! val selectedUiModeName = prefs.getString(PREF_KEY_SELECTED_UI_MODE, UiMode.SYSTEM_DEFAULT.name)!!
var selectedUiMode: UiMode var selectedUiMode: UiMode
try { try {