Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement proper theme changing logic #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/java/org/stratoemu/strato/StratoApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class StratoApplication : 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.stratoemu.strato.MainActivity
import org.stratoemu.strato.R
import org.stratoemu.strato.utils.GpuDriverHelper
import org.stratoemu.strato.utils.WindowInsetsHelper
import org.stratoemu.strato.StratoApplication
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -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
StratoApplication.setTheme(isMaterialYouEnabled)
requireActivity().recreate()
true
}

Expand Down