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 code.name.monkey.appthemehelper.*
|
||||
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.VersionUtils
|
||||
import code.name.monkey.retromusic.App
|
||||
|
@ -42,15 +41,20 @@ import com.afollestad.materialdialogs.color.colorChooser
|
|||
class ThemeSettingsFragment : AbsSettingsFragment() {
|
||||
|
||||
override fun invalidateSettings() {
|
||||
val primaryColorPref: ATEColorPreference = findPreference("primary_color")!!
|
||||
primaryColorPref.isVisible = PreferenceUtil.getInstance().generalTheme == R.style.Theme_RetroMusic_Color
|
||||
val primaryColorPref: ATEColorPreference? = findPreference("primary_color")
|
||||
primaryColorPref?.let {
|
||||
it.isVisible = PreferenceUtil.getInstance().generalTheme == R.style.Theme_RetroMusic_Color
|
||||
val primaryColor = ThemeStore.primaryColor(activity!!)
|
||||
primaryColorPref.setColor(primaryColor, ColorUtil.darkenColor(primaryColor))
|
||||
primaryColorPref.setOnPreferenceClickListener {
|
||||
it.setColor(primaryColor, ColorUtil.darkenColor(primaryColor))
|
||||
it.setOnPreferenceClickListener {
|
||||
MaterialDialog(activity!!, BottomSheet()).show {
|
||||
title(code.name.monkey.retromusic.R.string.primary_color)
|
||||
title(R.string.primary_color)
|
||||
positiveButton(R.string.set)
|
||||
colorChooser(initialSelection = BLUE, allowCustomArgb = true, colors = PRIMARY_COLORS, subColors = PRIMARY_COLORS_SUB) { _, color ->
|
||||
colorChooser(initialSelection = BLUE,
|
||||
allowCustomArgb = true,
|
||||
colors = PRIMARY_COLORS,
|
||||
subColors = PRIMARY_COLORS_SUB) { _, color ->
|
||||
|
||||
val theme = if (ColorUtil.isColorLight(color))
|
||||
PreferenceUtil.getThemeResFromPrefValue("light")
|
||||
else
|
||||
|
@ -65,31 +69,30 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
|
|||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
val generalTheme: Preference = findPreference("general_theme")!!
|
||||
setSummary(generalTheme)
|
||||
generalTheme.setOnPreferenceChangeListener { _, newValue ->
|
||||
val generalTheme: Preference? = findPreference("general_theme")
|
||||
|
||||
generalTheme?.let {
|
||||
setSummary(it)
|
||||
it.setOnPreferenceChangeListener { _, newValue ->
|
||||
val theme = newValue as String
|
||||
|
||||
println(newValue)
|
||||
if (theme == "color" && !App.isProVersion) {
|
||||
primaryColorPref.isVisible = false
|
||||
showProToastAndNavigate("Color theme")
|
||||
return@setOnPreferenceChangeListener false
|
||||
} else {
|
||||
primaryColorPref.isVisible = true
|
||||
}
|
||||
|
||||
if (theme == "color") {
|
||||
primaryColorPref?.isVisible = true
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -98,13 +101,13 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
|
|||
.commit()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
activity!!.setTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
||||
activity?.setTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
||||
DynamicShortcutManager(activity!!).updateDynamicShortcuts()
|
||||
}
|
||||
activity!!.recreate()
|
||||
//invalidateSettings();
|
||||
activity?.recreate()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
val accentColorPref: ATEColorPreference = findPreference("accent_color")!!
|
||||
val accentColor = ThemeStore.accentColor(activity!!)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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.retromusic.preferences.MaterialListPreference
|
||||
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
|
||||
android:defaultValue="dark"
|
||||
android:entries="@array/pref_general_theme_list_titles"
|
||||
android:entryValues="@array/pref_general_theme_list_values"
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package code.name.monkey.appthemehelper.common.prefs.supportv7
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.PorterDuff
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.ListPreference
|
||||
import code.name.monkey.appthemehelper.R
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad)
|
||||
|
@ -27,6 +29,7 @@ class ATEListPreference : ListPreference {
|
|||
}
|
||||
|
||||
private fun init() {
|
||||
icon?.setColorFilter(ThemeStore.textColorSecondary(context), PorterDuff.Mode.SRC_IN)
|
||||
layoutResource = R.layout.ate_preference_custom_support
|
||||
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty())
|
||||
summary = "%s"
|
||||
|
|
Loading…
Reference in a new issue