Change setting ripple color

Change the ripple on the settings to a generally neutral color instead of the gaudy colorPrimary.
This commit is contained in:
OxygenCobalt
2020-11-29 14:43:37 -07:00
parent e15df4ce73
commit 59036a2747
23 changed files with 169 additions and 77 deletions
@@ -26,8 +26,8 @@ import org.oxycblt.auxio.ui.accent
import org.oxycblt.auxio.ui.toColor
/**
* A source code copy of [com.reddit.indicatorfastscroll.FastScrollerThumbView] that fixes a
* memory leak that occurs from having nested fragments. All credit goes to the authors of
* A semi-copy, semi-custom implementation of [com.reddit.indicatorfastscroll.FastScrollerThumbView]
* that fixes a memory leak that occurs from a bug fix they added. All credit goes to the authors of
* the fast scroll library.
* <a href="https://github.com/reddit/IndicatorFastScroll"> Link to repo </a>
* @author Reddit, OxygenCobalt
@@ -81,7 +81,11 @@ class NoLeakThumbView @JvmOverloads constructor(
fastScrollerView.onTouchEvent(event)
fastScrollerView.performClick()
if (event.actionMasked in intArrayOf(MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL)) {
if (event.actionMasked in intArrayOf(
MotionEvent.ACTION_UP,
MotionEvent.ACTION_CANCEL
)
) {
isActivated = false
return@setOnTouchListener true
}
@@ -104,15 +108,9 @@ class NoLeakThumbView @JvmOverloads constructor(
fastScrollerView.apply {
children.forEach { view ->
if (view.containsY(touchY)) {
when (view) {
is ImageView -> {
consumed = true
}
is TextView -> {
consumed = true
}
}
if (view.containsY(touchY) && (view is ImageView || view is TextView)) {
consumed = true
return@forEach
}
}
}
@@ -1,12 +1,17 @@
package org.oxycblt.auxio.settings
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.activityViewModels
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceGroupAdapter
import androidx.preference.PreferenceScreen
import androidx.preference.PreferenceViewHolder
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.MaterialDialog
@@ -18,12 +23,15 @@ import org.oxycblt.auxio.ui.ACCENTS
import org.oxycblt.auxio.ui.accent
import org.oxycblt.auxio.ui.getDetailedAccentSummary
class SettingListFragment : PreferenceFragmentCompat() {
class SettingsListFragment : PreferenceFragmentCompat() {
private val settingsModel: SettingsViewModel by activityViewModels()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.apply {
}
val themePref = findPreference<Preference>(SettingsManager.Keys.KEY_THEME)?.apply {
setIcon(
when (AppCompatDelegate.getDefaultNightMode()) {
@@ -80,9 +88,33 @@ class SettingListFragment : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.prefs_main, rootKey)
}
// Forcefully override the adapter creation process so I can get rid of the ugly
// colorPrimary ripples.
@SuppressLint("RestrictedApi")
override fun onCreateAdapter(preferenceScreen: PreferenceScreen?): RecyclerView.Adapter<*> {
return object : PreferenceGroupAdapter(preferenceScreen) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): PreferenceViewHolder {
val holder = super.onCreateViewHolder(parent, viewType)
if (holder.itemView.id != android.R.id.title) {
holder.itemView.setBackgroundResource(R.drawable.ui_ripple)
}
return holder
}
}
}
private fun offLoad(something: String) {
Log.d(this::class.simpleName, something)
}
private fun showAccentDialog() {
MaterialDialog(requireActivity()).show {
title(R.string.label_settings_accent)
title(R.string.setting_accent)
// Roll my own RecyclerView since [To no surprise whatsoever] Material Dialogs
// has a bug where ugly dividers will show with the RecyclerView even if you disable them.
@@ -14,7 +14,8 @@ import org.oxycblt.auxio.ui.ACCENTS
* the first time it occurs.
* @author OxygenCobalt
*/
class SettingsManager private constructor(context: Context) : SharedPreferences.OnSharedPreferenceChangeListener {
class SettingsManager private constructor(context: Context) :
SharedPreferences.OnSharedPreferenceChangeListener {
private val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
init {
@@ -79,6 +80,10 @@ class SettingsManager private constructor(context: Context) : SharedPreferences.
) ?: SortMode.ALPHA_DOWN
}
fun getEdgeToEdge(): Boolean {
return sharedPrefs.getBoolean(Keys.KEY_EDGE_TO_EDGE, false)
}
// --- OVERRIDES ---
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
@@ -124,6 +129,7 @@ class SettingsManager private constructor(context: Context) : SharedPreferences.
const val KEY_LIBRARY_SORT_MODE = "KEY_LIBRARY_SORT_MODE"
const val KEY_THEME = "KEY_THEME"
const val KEY_ACCENT = "KEY_ACCENT"
const val KEY_EDGE_TO_EDGE = "KEY_EDGE"
}
private object Theme {
@@ -133,11 +139,12 @@ class SettingsManager private constructor(context: Context) : SharedPreferences.
}
/**
* A safe interface for receiving preference updates, use this instead of
* An interface for receiving some settings updates.
* [SharedPreferences.OnSharedPreferenceChangeListener].
*/
interface Callback {
fun onThemeUpdate(newTheme: Int) {}
fun onAccentUpdate(newAccent: Pair<Int, Int>) {}
fun onEdgeToEdgeUpdate(isEdgeToEdge: Boolean) {}
}
}
@@ -1,7 +1,6 @@
package org.oxycblt.auxio.settings.adapters
import android.content.res.ColorStateList
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
@@ -9,6 +8,7 @@ import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.ItemAccentBinding
import org.oxycblt.auxio.ui.ACCENTS
import org.oxycblt.auxio.ui.accent
import org.oxycblt.auxio.ui.getAccentItemSummary
import org.oxycblt.auxio.ui.toColor
class AccentAdapter(
@@ -29,20 +29,25 @@ class AccentAdapter(
) : RecyclerView.ViewHolder(binding.root) {
fun bind(accentData: Pair<Int, Int>) {
binding.accent.setOnClickListener {
Log.d(this::class.simpleName, accentData.toString())
doOnAccentConfirm(accentData)
}
binding.accent.apply {
imageTintList = if (accentData.first != accent.first) {
ColorStateList.valueOf(
android.R.color.transparent.toColor(context)
)
} else {
contentDescription = getAccentItemSummary(context, accentData)
setOnClickListener {
doOnAccentConfirm(accentData)
}
imageTintList = if (accentData.first == accent.first) {
isEnabled = false
ColorStateList.valueOf(
R.color.background.toColor(context)
)
} else {
isEnabled = true
ColorStateList.valueOf(
android.R.color.transparent.toColor(context)
)
}
backgroundTintList = ColorStateList.valueOf(
@@ -129,18 +129,19 @@ class SongsFragment : Fragment(), SearchView.OnQueryTextListener {
useDefaultScroller = false
itemIndicatorSelectedCallbacks.add(object : FastScrollerView.ItemIndicatorSelectedCallback {
override fun onItemIndicatorSelected(
indicator: FastScrollItemIndicator,
indicatorCenterY: Int,
itemPosition: Int
) {
val layoutManager = binding.songRecycler.layoutManager
as LinearLayoutManager
itemIndicatorSelectedCallbacks.add(object :
FastScrollerView.ItemIndicatorSelectedCallback {
override fun onItemIndicatorSelected(
indicator: FastScrollItemIndicator,
indicatorCenterY: Int,
itemPosition: Int
) {
val layoutManager = binding.songRecycler.layoutManager
as LinearLayoutManager
layoutManager.scrollToPositionWithOffset(itemPosition, 0)
layoutManager.scrollToPositionWithOffset(itemPosition, 0)
}
}
}
)
}
@@ -93,6 +93,7 @@ fun PopupMenu.setupSongActions(song: Song, context: Context, playbackModel: Play
}
inflateAndShow(R.menu.menu_song_actions)
}
/**
* Show actions for a song item, such as the ones found in [org.oxycblt.auxio.songs.SongsFragment]
*/