From 15aa81341636755e7d42c76366bcd112427c8722 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Wed, 17 Apr 2019 14:03:25 +0200 Subject: [PATCH] Migrated to compat shared prefs and fixed it not reacting to changes Added back dark theme --- app/src/main/java/com/topjohnwu/magisk/App.java | 0 app/src/main/java/com/topjohnwu/magisk/App.kt | 11 +++++------ .../com/topjohnwu/magisk/ui/base/MagiskActivity.kt | 13 +++++++++++++ .../magisk/ui/settings/SettingsFragment.java | 1 + app/src/main/res/values-night/styles_new.xml | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/App.java create mode 100644 app/src/main/res/values-night/styles_new.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/App.java b/app/src/main/java/com/topjohnwu/magisk/App.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/src/main/java/com/topjohnwu/magisk/App.kt b/app/src/main/java/com/topjohnwu/magisk/App.kt index bbe501fb9..164f8e219 100644 --- a/app/src/main/java/com/topjohnwu/magisk/App.kt +++ b/app/src/main/java/com/topjohnwu/magisk/App.kt @@ -9,8 +9,8 @@ import android.content.res.Configuration import android.os.AsyncTask import android.os.Build import android.os.Bundle -import android.preference.PreferenceManager import androidx.appcompat.app.AppCompatDelegate +import androidx.preference.PreferenceManager import com.topjohnwu.magisk.data.database.MagiskDB import com.topjohnwu.magisk.data.database.RepoDatabaseHelper import com.topjohnwu.magisk.di.koinModules @@ -26,7 +26,7 @@ import java.util.concurrent.ThreadPoolExecutor open class App : Application(), Application.ActivityLifecycleCallbacks { // Global resources - val prefs: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deContext) } + val prefs: SharedPreferences get() = PreferenceManager.getDefaultSharedPreferences(deContext) val DB: MagiskDB by lazy { MagiskDB(deContext) } @JvmField var repoDB: RepoDatabaseHelper? = null @@ -52,10 +52,7 @@ open class App : Application(), Application.ActivityLifecycleCallbacks { if (Build.VERSION.SDK_INT >= 24) { deContext = base.createDeviceProtectedStorageContext() - deContext.moveSharedPreferencesFrom( - base, - PreferenceManager.getDefaultSharedPreferencesName(base) - ) + deContext.moveSharedPreferencesFrom(base, base.defaultPrefsName) } Networking.init(base) @@ -89,6 +86,8 @@ open class App : Application(), Application.ActivityLifecycleCallbacks { override fun onActivityDestroyed(activity: Activity) {} //endregion + private val Context.defaultPrefsName get() = "${packageName}_preferences" + companion object { //fixme this should be at least weak reference, me no likey diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt index 5992a04e8..f145bde2a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt @@ -3,12 +3,14 @@ package com.topjohnwu.magisk.ui.base import android.content.Intent import android.os.Bundle import androidx.annotation.CallSuper +import androidx.appcompat.app.AppCompatDelegate import androidx.core.net.toUri import androidx.databinding.ViewDataBinding import androidx.fragment.app.Fragment import com.ncapdevi.fragnav.FragNavController import com.ncapdevi.fragnav.FragNavTransactionOptions import com.skoumal.teanity.viewevents.ViewEvent +import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.model.navigation.MagiskAnimBuilder import com.topjohnwu.magisk.model.navigation.MagiskNavigationEvent import com.topjohnwu.magisk.model.navigation.Navigator @@ -31,6 +33,17 @@ abstract class MagiskActivity(Config.Key.DARK_THEME) + val theme = if (isDarkTheme) { + AppCompatDelegate.MODE_NIGHT_YES + } else { + AppCompatDelegate.MODE_NIGHT_NO + } + AppCompatDelegate.setDefaultNightMode(theme) + AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) navigationController.apply { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java index f5ec2f56d..4ea7162d1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java @@ -42,6 +42,7 @@ public class SettingsFragment extends BasePreferenceFragment { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + getPreferenceManager().setStorageDeviceProtected(); setPreferencesFromResource(R.xml.app_settings, rootKey); requireActivity().setTitle(R.string.settings); diff --git a/app/src/main/res/values-night/styles_new.xml b/app/src/main/res/values-night/styles_new.xml new file mode 100644 index 000000000..5b0ea2a22 --- /dev/null +++ b/app/src/main/res/values-night/styles_new.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file