2019-05-11 13:53:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Hemanth Savarala.
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License v3
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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
|
2019-09-03 17:54:14 +00:00
|
|
|
import code.name.monkey.appthemehelper.ACCENT_COLORS
|
|
|
|
import code.name.monkey.appthemehelper.ACCENT_COLORS_SUB
|
|
|
|
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
|
2019-12-26 15:09:28 +00:00
|
|
|
import code.name.monkey.retromusic.App
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
2018-12-08 03:33:02 +00:00
|
|
|
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
2019-02-19 10:38:51 +00:00
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
|
|
|
import com.afollestad.materialdialogs.color.colorChooser
|
|
|
|
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Hemanth S (h4h13).
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ThemeSettingsFragment : AbsSettingsFragment() {
|
|
|
|
override fun invalidateSettings() {
|
2019-07-08 14:32:23 +00:00
|
|
|
val generalTheme: Preference? = findPreference("general_theme")
|
|
|
|
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) {
|
2019-08-05 16:13:44 +00:00
|
|
|
requireActivity().setTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
2019-08-01 14:13:00 +00:00
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
2019-07-08 14:32:23 +00:00
|
|
|
}
|
2020-04-21 17:58:06 +00:00
|
|
|
requireActivity().recreate()
|
2019-07-08 14:32:23 +00:00
|
|
|
true
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 12:43:43 +00:00
|
|
|
val accentColorPref: ATEColorPreference = findPreference("accent_color")!!
|
2019-08-01 14:13:00 +00:00
|
|
|
val accentColor = ThemeStore.accentColor(requireContext())
|
2018-12-06 08:52:57 +00:00
|
|
|
accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor))
|
|
|
|
|
|
|
|
accentColorPref.setOnPreferenceClickListener {
|
2020-04-26 17:14:18 +00:00
|
|
|
MaterialDialog(requireActivity()).show {
|
2019-11-28 14:16:54 +00:00
|
|
|
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
|
2019-04-09 17:29:48 +00:00
|
|
|
title(R.string.accent_color)
|
2019-02-19 10:38:51 +00:00
|
|
|
positiveButton(R.string.set)
|
2020-02-26 16:49:24 +00:00
|
|
|
colorChooser(
|
|
|
|
colors = ACCENT_COLORS,
|
|
|
|
allowCustomArgb = true,
|
|
|
|
subColors = ACCENT_COLORS_SUB
|
|
|
|
) { _, color ->
|
2019-08-05 16:13:44 +00:00
|
|
|
ThemeStore.editTheme(requireContext()).accentColor(color).commit()
|
2019-02-19 10:38:51 +00:00
|
|
|
if (VersionUtils.hasNougatMR())
|
2019-08-05 16:13:44 +00:00
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
2020-04-26 17:14:18 +00:00
|
|
|
|
|
|
|
requireActivity().recreate()
|
|
|
|
|
2019-02-19 10:38:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return@setOnPreferenceClickListener true
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
2019-09-28 17:52:49 +00:00
|
|
|
val blackTheme: ATESwitchPreference? = findPreference("black_theme")
|
|
|
|
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) {
|
|
|
|
requireActivity().setTheme(PreferenceUtil.getThemeResFromPrefValue("black"))
|
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
|
|
|
}
|
2020-04-21 17:58:06 +00:00
|
|
|
requireActivity().recreate()
|
2019-09-28 17:52:49 +00:00
|
|
|
true
|
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2020-02-26 16:49:24 +00:00
|
|
|
val desaturatedColor: ATESwitchPreference? =
|
|
|
|
findPreference(PreferenceUtil.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()
|
2019-10-12 06:41:48 +00:00
|
|
|
PreferenceUtil.getInstance(requireContext()).setDesaturatedColor(desaturated)
|
2020-04-21 17:58:06 +00:00
|
|
|
requireActivity().recreate()
|
2019-10-12 06:41:48 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 12:43:43 +00:00
|
|
|
val colorAppShortcuts: TwoStatePreference = findPreference("should_color_app_shortcuts")!!
|
2018-12-06 08:52:57 +00:00
|
|
|
if (!VersionUtils.hasNougatMR()) {
|
|
|
|
colorAppShortcuts.isVisible = false
|
|
|
|
} else {
|
2020-02-26 16:49:24 +00:00
|
|
|
colorAppShortcuts.isChecked =
|
|
|
|
PreferenceUtil.getInstance(requireContext()).coloredAppShortcuts()
|
2018-12-06 08:52:57 +00:00
|
|
|
colorAppShortcuts.setOnPreferenceChangeListener { _, newValue ->
|
|
|
|
// Save preference
|
2020-02-26 16:49:24 +00:00
|
|
|
PreferenceUtil.getInstance(requireContext())
|
|
|
|
.setColoredAppShortcuts(newValue as Boolean)
|
2019-08-01 14:13:00 +00:00
|
|
|
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
|
2018-12-06 08:52:57 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|