mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 12:47:38 +00:00
Migrated to compat shared prefs and fixed it not reacting to changes
Added back dark theme
This commit is contained in:
parent
605faccffd
commit
15aa813416
@ -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
|
||||
|
@ -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<ViewModel : MagiskViewModel, Binding : ViewDataBin
|
||||
FragNavController(supportFragmentManager, navHostId)
|
||||
}
|
||||
|
||||
init {
|
||||
val isDarkTheme = Config.get<Boolean>(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 {
|
||||
|
@ -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);
|
||||
|
||||
|
14
app/src/main/res/values-night/styles_new.xml
Normal file
14
app/src/main/res/values-night/styles_new.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="ThemeFoundation" parent="Theme.MaterialComponents.NoActionBar" />
|
||||
|
||||
<style name="MagiskTheme" parent="ThemeFoundation.Colored.ExtraProps">
|
||||
<!--All of these attributes are deprecated and will be removed-->
|
||||
<item name="cardStyle">@style/CardViewStyle.Dark</item>
|
||||
<item name="imageColorTint">@color/dark_secondary_text</item>
|
||||
<item name="colorControl">?android:attr/textColorSecondary</item>
|
||||
<item name="colorAccentFallback">@color/accentFallback</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user