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.graphics.Color
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.core.content.ContextCompat
|
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
|
|
|
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
|
|
|
import code.name.monkey.appthemehelper.util.VersionUtils
|
|
|
|
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-09-17 19:36:13 +00:00
|
|
|
import com.afollestad.materialdialogs.LayoutMode
|
2019-02-19 10:38:51 +00:00
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
2019-05-11 13:53:20 +00:00
|
|
|
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
2019-02-19 10:38:51 +00:00
|
|
|
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
|
|
|
|
setSummary(generalTheme, newValue)
|
2019-09-03 17:54:14 +00:00
|
|
|
val color = when (theme) {
|
|
|
|
"light" -> Color.WHITE
|
|
|
|
"black" -> Color.BLACK
|
|
|
|
"dark" -> ContextCompat.getColor(requireContext(), R.color.md_grey_900)
|
|
|
|
else -> Color.WHITE
|
2019-05-17 04:05:13 +00:00
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2019-08-01 14:13:00 +00:00
|
|
|
ThemeStore.editTheme(requireContext())
|
2019-07-08 14:32:23 +00:00
|
|
|
.activityTheme(PreferenceUtil.getThemeResFromPrefValue(theme))
|
2019-09-03 17:54:14 +00:00
|
|
|
.primaryColor(color)
|
2019-07-08 14:32:23 +00:00
|
|
|
.commit()
|
2018-12-06 08:52:57 +00:00
|
|
|
|
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
|
|
|
}
|
2019-08-05 16:13:44 +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 {
|
2019-09-17 19:36:13 +00:00
|
|
|
MaterialDialog(requireActivity(), BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
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)
|
2019-02-19 17:40:16 +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()
|
2019-08-01 14:13:00 +00:00
|
|
|
requireActivity().recreate()
|
2019-02-19 10:38:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return@setOnPreferenceClickListener true
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2019-09-09 13:04:53 +00:00
|
|
|
colorAppShortcuts.isChecked = PreferenceUtil.getInstance(requireContext()).coloredAppShortcuts()
|
2018-12-06 08:52:57 +00:00
|
|
|
colorAppShortcuts.setOnPreferenceChangeListener { _, newValue ->
|
|
|
|
// Save preference
|
2019-09-09 13:04:53 +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
|
|
|
}
|
|
|
|
}
|