2019-05-11 13:53:20 +00:00
|
|
|
/*
|
2020-10-06 08:46:04 +00:00
|
|
|
* Copyright (c) 2020 Hemanth Savarla.
|
2019-05-11 13:53:20 +00:00
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License v3
|
|
|
|
*
|
2020-10-06 08:46:04 +00:00
|
|
|
* This is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
2019-05-11 13:53:20 +00:00
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
2020-10-06 08:46:04 +00:00
|
|
|
*
|
2019-05-11 13:53:20 +00:00
|
|
|
*/
|
2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.fragments.settings
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
2019-03-25 12:43:43 +00:00
|
|
|
import androidx.preference.Preference
|
2018-12-06 08:52:57 +00:00
|
|
|
import androidx.preference.TwoStatePreference
|
2021-09-08 18:30:20 +00:00
|
|
|
import code.name.monkey.appthemehelper.ACCENT_COLORS
|
|
|
|
import code.name.monkey.appthemehelper.ACCENT_COLORS_SUB
|
2019-09-03 17:54:14 +00:00
|
|
|
import code.name.monkey.appthemehelper.ThemeStore
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference
|
2019-09-28 17:52:49 +00:00
|
|
|
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
|
|
|
import code.name.monkey.appthemehelper.util.VersionUtils
|
2020-09-24 20:21:32 +00:00
|
|
|
import code.name.monkey.retromusic.*
|
2018-12-08 03:33:02 +00:00
|
|
|
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
2020-06-06 18:57:28 +00:00
|
|
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
2021-09-08 18:30:20 +00:00
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
|
|
|
import com.afollestad.materialdialogs.color.colorChooser
|
2021-10-04 05:53:40 +00:00
|
|
|
import com.google.android.material.color.DynamicColors
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Hemanth S (h4h13).
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ThemeSettingsFragment : AbsSettingsFragment() {
|
|
|
|
override fun invalidateSettings() {
|
2020-09-24 20:21:32 +00:00
|
|
|
val generalTheme: Preference? = findPreference(GENERAL_THEME)
|
2019-07-08 14:32:23 +00:00
|
|
|
generalTheme?.let {
|
|
|
|
setSummary(it)
|
|
|
|
it.setOnPreferenceChangeListener { _, newValue ->
|
|
|
|
val theme = newValue as String
|
2019-09-26 21:02:49 +00:00
|
|
|
setSummary(it, newValue)
|
2019-09-03 17:54:14 +00:00
|
|
|
ThemeStore.markChanged(requireContext())
|
|
|
|
|
2019-07-08 14:32:23 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
2020-06-06 18:57:28 +00:00
|
|
|
requireActivity().setTheme(PreferenceUtil.themeResFromPrefValue(theme))
|
2019-08-01 14:13:00 +00:00
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
2019-07-08 14:32:23 +00:00
|
|
|
}
|
2021-09-22 12:00:02 +00:00
|
|
|
restartActivity()
|
2019-07-08 14:32:23 +00:00
|
|
|
true
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 20:21:32 +00:00
|
|
|
val accentColorPref: ATEColorPreference? = findPreference(ACCENT_COLOR)
|
2019-08-01 14:13:00 +00:00
|
|
|
val accentColor = ThemeStore.accentColor(requireContext())
|
2020-09-24 20:21:32 +00:00
|
|
|
accentColorPref?.setColor(accentColor, ColorUtil.darkenColor(accentColor))
|
|
|
|
accentColorPref?.setOnPreferenceClickListener {
|
2021-09-08 18:30:20 +00:00
|
|
|
MaterialDialog(requireContext()).show {
|
|
|
|
colorChooser(
|
|
|
|
initialSelection = accentColor,
|
|
|
|
showAlphaSelector = false,
|
|
|
|
colors = ACCENT_COLORS,
|
|
|
|
subColors = ACCENT_COLORS_SUB, allowCustomArgb = true
|
|
|
|
) { _, color ->
|
|
|
|
ThemeStore.editTheme(requireContext()).accentColor(color).commit()
|
|
|
|
if (VersionUtils.hasNougatMR())
|
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
2021-09-22 12:00:02 +00:00
|
|
|
restartActivity()
|
2021-09-08 18:30:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-19 10:38:51 +00:00
|
|
|
return@setOnPreferenceClickListener true
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
2020-09-24 20:21:32 +00:00
|
|
|
val blackTheme: ATESwitchPreference? = findPreference(BLACK_THEME)
|
2019-09-28 17:52:49 +00:00
|
|
|
blackTheme?.setOnPreferenceChangeListener { _, _ ->
|
2019-12-26 15:09:28 +00:00
|
|
|
if (!App.isProVersion()) {
|
|
|
|
showProToastAndNavigate("Just Black theme")
|
|
|
|
return@setOnPreferenceChangeListener false
|
|
|
|
}
|
2019-09-28 17:52:49 +00:00
|
|
|
ThemeStore.markChanged(requireContext())
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
2020-06-06 18:57:28 +00:00
|
|
|
requireActivity().setTheme(PreferenceUtil.themeResFromPrefValue("black"))
|
2019-09-28 17:52:49 +00:00
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
|
|
|
}
|
2021-09-22 12:00:02 +00:00
|
|
|
restartActivity()
|
2019-09-28 17:52:49 +00:00
|
|
|
true
|
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2020-05-23 09:27:55 +00:00
|
|
|
val desaturatedColor: ATESwitchPreference? = findPreference(DESATURATED_COLOR)
|
2019-10-12 06:41:48 +00:00
|
|
|
desaturatedColor?.setOnPreferenceChangeListener { _, value ->
|
|
|
|
val desaturated = value as Boolean
|
2020-04-26 17:14:18 +00:00
|
|
|
ThemeStore.prefs(requireContext())
|
|
|
|
.edit()
|
|
|
|
.putBoolean("desaturated_color", desaturated)
|
2020-02-26 16:49:24 +00:00
|
|
|
.apply()
|
2020-06-06 18:57:28 +00:00
|
|
|
PreferenceUtil.isDesaturatedColor = desaturated
|
2021-09-22 12:00:02 +00:00
|
|
|
restartActivity()
|
2019-10-12 06:41:48 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2020-09-24 20:21:32 +00:00
|
|
|
val colorAppShortcuts: TwoStatePreference? = findPreference(SHOULD_COLOR_APP_SHORTCUTS)
|
2018-12-06 08:52:57 +00:00
|
|
|
if (!VersionUtils.hasNougatMR()) {
|
2020-09-24 20:21:32 +00:00
|
|
|
colorAppShortcuts?.isVisible = false
|
2018-12-06 08:52:57 +00:00
|
|
|
} else {
|
2020-09-24 20:21:32 +00:00
|
|
|
colorAppShortcuts?.isChecked = PreferenceUtil.isColoredAppShortcuts
|
|
|
|
colorAppShortcuts?.setOnPreferenceChangeListener { _, newValue ->
|
2020-06-06 18:57:28 +00:00
|
|
|
PreferenceUtil.isColoredAppShortcuts = newValue as Boolean
|
2019-08-01 14:13:00 +00:00
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
2018-12-06 08:52:57 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
2021-09-26 10:29:32 +00:00
|
|
|
|
|
|
|
val materialYou: ATESwitchPreference? = findPreference(MATERIAL_YOU)
|
2021-10-04 11:25:01 +00:00
|
|
|
materialYou?.setOnPreferenceChangeListener { _, newValue ->
|
|
|
|
if (newValue as Boolean) {
|
|
|
|
DynamicColors.applyToActivitiesIfAvailable(App.getContext())
|
|
|
|
}
|
2021-09-26 10:29:32 +00:00
|
|
|
restartActivity()
|
|
|
|
true
|
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 10:23:03 +00:00
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
2019-02-19 17:40:16 +00:00
|
|
|
addPreferencesFromResource(R.xml.pref_general)
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
}
|