Fix crash and color theme selection for none pro users
This commit is contained in:
parent
f40a8e2d3e
commit
e4a4874edc
3 changed files with 59 additions and 53 deletions
|
@ -23,7 +23,6 @@ import androidx.preference.Preference
|
||||||
import androidx.preference.TwoStatePreference
|
import androidx.preference.TwoStatePreference
|
||||||
import code.name.monkey.appthemehelper.*
|
import code.name.monkey.appthemehelper.*
|
||||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference
|
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference
|
||||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||||
import code.name.monkey.retromusic.App
|
import code.name.monkey.retromusic.App
|
||||||
|
@ -42,68 +41,72 @@ import com.afollestad.materialdialogs.color.colorChooser
|
||||||
class ThemeSettingsFragment : AbsSettingsFragment() {
|
class ThemeSettingsFragment : AbsSettingsFragment() {
|
||||||
|
|
||||||
override fun invalidateSettings() {
|
override fun invalidateSettings() {
|
||||||
val primaryColorPref: ATEColorPreference = findPreference("primary_color")!!
|
val primaryColorPref: ATEColorPreference? = findPreference("primary_color")
|
||||||
primaryColorPref.isVisible = PreferenceUtil.getInstance().generalTheme == R.style.Theme_RetroMusic_Color
|
primaryColorPref?.let {
|
||||||
val primaryColor = ThemeStore.primaryColor(activity!!)
|
it.isVisible = PreferenceUtil.getInstance().generalTheme == R.style.Theme_RetroMusic_Color
|
||||||
primaryColorPref.setColor(primaryColor, ColorUtil.darkenColor(primaryColor))
|
val primaryColor = ThemeStore.primaryColor(activity!!)
|
||||||
primaryColorPref.setOnPreferenceClickListener {
|
it.setColor(primaryColor, ColorUtil.darkenColor(primaryColor))
|
||||||
MaterialDialog(activity!!, BottomSheet()).show {
|
it.setOnPreferenceClickListener {
|
||||||
title(code.name.monkey.retromusic.R.string.primary_color)
|
MaterialDialog(activity!!, BottomSheet()).show {
|
||||||
positiveButton(R.string.set)
|
title(R.string.primary_color)
|
||||||
colorChooser(initialSelection = BLUE, allowCustomArgb = true, colors = PRIMARY_COLORS, subColors = PRIMARY_COLORS_SUB) { _, color ->
|
positiveButton(R.string.set)
|
||||||
val theme = if (ColorUtil.isColorLight(color))
|
colorChooser(initialSelection = BLUE,
|
||||||
PreferenceUtil.getThemeResFromPrefValue("light")
|
allowCustomArgb = true,
|
||||||
else
|
colors = PRIMARY_COLORS,
|
||||||
PreferenceUtil.getThemeResFromPrefValue("dark")
|
subColors = PRIMARY_COLORS_SUB) { _, color ->
|
||||||
|
|
||||||
ThemeStore.editTheme(context).activityTheme(theme).primaryColor(color).commit()
|
val theme = if (ColorUtil.isColorLight(color))
|
||||||
|
PreferenceUtil.getThemeResFromPrefValue("light")
|
||||||
|
else
|
||||||
|
PreferenceUtil.getThemeResFromPrefValue("dark")
|
||||||
|
|
||||||
if (VersionUtils.hasNougatMR())
|
ThemeStore.editTheme(context).activityTheme(theme).primaryColor(color).commit()
|
||||||
DynamicShortcutManager(context).updateDynamicShortcuts()
|
|
||||||
activity!!.recreate()
|
if (VersionUtils.hasNougatMR())
|
||||||
|
DynamicShortcutManager(context).updateDynamicShortcuts()
|
||||||
|
activity!!.recreate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val generalTheme: Preference = findPreference("general_theme")!!
|
val generalTheme: Preference? = findPreference("general_theme")
|
||||||
setSummary(generalTheme)
|
|
||||||
generalTheme.setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
val theme = newValue as String
|
|
||||||
|
|
||||||
if (theme == "color" && !App.isProVersion) {
|
generalTheme?.let {
|
||||||
primaryColorPref.isVisible = false
|
setSummary(it)
|
||||||
showProToastAndNavigate("Color theme")
|
it.setOnPreferenceChangeListener { _, newValue ->
|
||||||
return@setOnPreferenceChangeListener false
|
val theme = newValue as String
|
||||||
} else {
|
println(newValue)
|
||||||
primaryColorPref.isVisible = true
|
if (theme == "color" && !App.isProVersion) {
|
||||||
}
|
showProToastAndNavigate("Color theme")
|
||||||
|
return@setOnPreferenceChangeListener false
|
||||||
setSummary(generalTheme, newValue)
|
|
||||||
|
|
||||||
|
|
||||||
when (theme) {
|
|
||||||
"light" -> ThemeStore.editTheme(context!!).primaryColor(Color.WHITE).commit()
|
|
||||||
"black" -> ThemeStore.editTheme(context!!).primaryColor(Color.BLACK).commit()
|
|
||||||
"dark" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, R.color.md_grey_900)).commit()
|
|
||||||
"daynight" -> {
|
|
||||||
val color = ATHUtil.resolveColor(context!!, android.R.attr.colorPrimary)
|
|
||||||
ThemeStore.editTheme(context!!).primaryColor(color).commit()
|
|
||||||
}
|
}
|
||||||
"color" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, R.color.md_blue_grey_800)).commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
ThemeStore.editTheme(activity!!)
|
if (theme == "color") {
|
||||||
.activityTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
primaryColorPref?.isVisible = true
|
||||||
.commit()
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
setSummary(generalTheme, newValue)
|
||||||
activity!!.setTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
|
||||||
DynamicShortcutManager(activity!!).updateDynamicShortcuts()
|
when (theme) {
|
||||||
|
"light" -> ThemeStore.editTheme(context!!).primaryColor(Color.WHITE).commit()
|
||||||
|
"black" -> ThemeStore.editTheme(context!!).primaryColor(Color.BLACK).commit()
|
||||||
|
"dark" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, R.color.md_grey_900)).commit()
|
||||||
|
"color" -> ThemeStore.editTheme(context!!).primaryColor(ContextCompat.getColor(context!!, R.color.md_blue_grey_800)).commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeStore.editTheme(activity!!)
|
||||||
|
.activityTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
||||||
|
.commit()
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||||
|
activity?.setTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
||||||
|
DynamicShortcutManager(activity!!).updateDynamicShortcuts()
|
||||||
|
}
|
||||||
|
activity?.recreate()
|
||||||
|
true
|
||||||
}
|
}
|
||||||
activity!!.recreate()
|
|
||||||
//invalidateSettings();
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val accentColorPref: ATEColorPreference = findPreference("accent_color")!!
|
val accentColorPref: ATEColorPreference = findPreference("accent_color")!!
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_general">
|
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_general">
|
||||||
<code.name.monkey.retromusic.preferences.MaterialListPreference
|
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
|
||||||
android:defaultValue="dark"
|
android:defaultValue="dark"
|
||||||
android:entries="@array/pref_general_theme_list_titles"
|
android:entries="@array/pref_general_theme_list_titles"
|
||||||
android:entryValues="@array/pref_general_theme_list_values"
|
android:entryValues="@array/pref_general_theme_list_values"
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package code.name.monkey.appthemehelper.common.prefs.supportv7
|
package code.name.monkey.appthemehelper.common.prefs.supportv7
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.PorterDuff
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import code.name.monkey.appthemehelper.R
|
import code.name.monkey.appthemehelper.R
|
||||||
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Aidan Follestad (afollestad)
|
* @author Aidan Follestad (afollestad)
|
||||||
|
@ -27,6 +29,7 @@ class ATEListPreference : ListPreference {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun init() {
|
private fun init() {
|
||||||
|
icon?.setColorFilter(ThemeStore.textColorSecondary(context), PorterDuff.Mode.SRC_IN)
|
||||||
layoutResource = R.layout.ate_preference_custom_support
|
layoutResource = R.layout.ate_preference_custom_support
|
||||||
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty())
|
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty())
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
Loading…
Reference in a new issue