mirror of
https://github.com/Ishan09811/pine.git
synced 2025-04-24 08:55:10 +00:00
Implement proper theme changing logic (#35)
recreate the activity when turning on or off material colors instead of restarting the entire application
This commit is contained in:
parent
4cc4981d08
commit
3d9df8b827
@ -29,6 +29,12 @@ class SkylineApplication : Application() {
|
||||
private set
|
||||
|
||||
val context : Context get() = instance.applicationContext
|
||||
|
||||
fun setTheme(newValue: Boolean) {
|
||||
val dynamicColorsOptions = DynamicColorsOptions.Builder().setPrecondition { _, _ -> newValue }.build()
|
||||
DynamicColors.applyToActivitiesIfAvailable(instance, dynamicColorsOptions)
|
||||
if (newValue == false) { instance.setTheme(R.style.AppTheme) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
|
@ -20,6 +20,7 @@ import emu.skyline.MainActivity
|
||||
import emu.skyline.R
|
||||
import emu.skyline.utils.GpuDriverHelper
|
||||
import emu.skyline.utils.WindowInsetsHelper
|
||||
import emu.skyline.SkylineApplication
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -45,9 +46,10 @@ class GlobalSettingsFragment : PreferenceFragmentCompat() {
|
||||
addPreferencesFromResource(R.xml.credits_preferences)
|
||||
|
||||
// Re-launch the app if Material You is toggled
|
||||
findPreference<Preference>("use_material_you")?.setOnPreferenceChangeListener { _, _ ->
|
||||
requireActivity().finishAffinity()
|
||||
startActivity(Intent(requireContext(), MainActivity::class.java))
|
||||
findPreference<Preference>("use_material_you")?.setOnPreferenceChangeListener { _, newValue ->
|
||||
val isMaterialYouEnabled = newValue as Boolean
|
||||
SkylineApplication.setTheme(isMaterialYouEnabled)
|
||||
requireActivity().recreate()
|
||||
true
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user