home: cleanup code

Clean up some bugs and old code from the tab customization
addition.
This commit is contained in:
OxygenCobalt 2021-10-17 20:53:00 -06:00
parent 23d1be8ebc
commit 0537681a86
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 20 additions and 11 deletions

View file

@ -39,6 +39,10 @@ class HomeViewModel : ViewModel(), SettingsManager.Callback {
private val musicStore = MusicStore.getInstance() private val musicStore = MusicStore.getInstance()
private val settingsManager = SettingsManager.getInstance() private val settingsManager = SettingsManager.getInstance()
/** Internal getter for getting the visible library tabs */
private val visibleTabs: List<DisplayMode> get() = settingsManager.libTabs
.filterIsInstance<Tab.Visible>().map { it.mode }
private val mSongs = MutableLiveData(listOf<Song>()) private val mSongs = MutableLiveData(listOf<Song>())
val songs: LiveData<List<Song>> get() = mSongs val songs: LiveData<List<Song>> get() = mSongs
@ -51,7 +55,7 @@ class HomeViewModel : ViewModel(), SettingsManager.Callback {
private val mGenres = MutableLiveData(listOf<Genre>()) private val mGenres = MutableLiveData(listOf<Genre>())
val genres: LiveData<List<Genre>> get() = mGenres val genres: LiveData<List<Genre>> get() = mGenres
var tabs: List<DisplayMode> = settingsManager.visibleTabs var tabs: List<DisplayMode> = visibleTabs
private set private set
private val mCurTab = MutableLiveData(tabs[0]) private val mCurTab = MutableLiveData(tabs[0])
@ -122,7 +126,7 @@ class HomeViewModel : ViewModel(), SettingsManager.Callback {
// --- OVERRIDES --- // --- OVERRIDES ---
override fun onLibTabsUpdate(libTabs: Array<Tab>) { override fun onLibTabsUpdate(libTabs: Array<Tab>) {
tabs = settingsManager.visibleTabs tabs = visibleTabs
mRecreateTabs.value = true mRecreateTabs.value = true
} }

View file

@ -18,6 +18,7 @@
package org.oxycblt.auxio.settings package org.oxycblt.auxio.settings
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
@ -105,6 +106,8 @@ class SettingsListFragment : PreferenceFragmentCompat() {
pref.apply { pref.apply {
when (key) { when (key) {
SettingsManager.KEY_THEME -> { SettingsManager.KEY_THEME -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) return
setIcon(AppCompatDelegate.getDefaultNightMode().toThemeIcon()) setIcon(AppCompatDelegate.getDefaultNightMode().toThemeIcon())
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value -> onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
@ -115,6 +118,8 @@ class SettingsListFragment : PreferenceFragmentCompat() {
} }
SettingsManager.KEY_BLACK_THEME -> { SettingsManager.KEY_BLACK_THEME -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) return
onPreferenceClickListener = Preference.OnPreferenceClickListener { onPreferenceClickListener = Preference.OnPreferenceClickListener {
if (requireContext().isNight) { if (requireContext().isNight) {
requireActivity().recreate() requireActivity().recreate()
@ -125,6 +130,8 @@ class SettingsListFragment : PreferenceFragmentCompat() {
} }
SettingsManager.KEY_ACCENT -> { SettingsManager.KEY_ACCENT -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) return
onPreferenceClickListener = Preference.OnPreferenceClickListener { onPreferenceClickListener = Preference.OnPreferenceClickListener {
AccentDialog().show(childFragmentManager, AccentDialog.TAG) AccentDialog().show(childFragmentManager, AccentDialog.TAG)
true true

View file

@ -31,6 +31,8 @@ import org.oxycblt.auxio.ui.SortMode
/** /**
* Wrapper around the [SharedPreferences] class that writes & reads values without a context. * Wrapper around the [SharedPreferences] class that writes & reads values without a context.
* @author OxygenCobalt * @author OxygenCobalt
* TODO: Consider re-adding the colorize notif setting but only on <Android 10 since it really
* doesn't work on Android 11+
*/ */
class SettingsManager private constructor(context: Context) : class SettingsManager private constructor(context: Context) :
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
@ -82,9 +84,6 @@ class SettingsManager private constructor(context: Context) :
} }
} }
/** The currently visible library tabs */
val visibleTabs: List<DisplayMode> get() = libTabs.filterIsInstance<Tab.Visible>().map { it.mode }
/** Whether to load embedded covers */ /** Whether to load embedded covers */
val showCovers: Boolean val showCovers: Boolean
get() = sharedPrefs.getBoolean(KEY_SHOW_COVERS, true) get() = sharedPrefs.getBoolean(KEY_SHOW_COVERS, true)

View file

@ -19,6 +19,7 @@
package org.oxycblt.auxio.settings.tabs package org.oxycblt.auxio.settings.tabs
import org.oxycblt.auxio.ui.DisplayMode import org.oxycblt.auxio.ui.DisplayMode
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.logE import org.oxycblt.auxio.util.logE
/** /**
@ -54,10 +55,6 @@ sealed class Tab(open val mode: DisplayMode) {
/** The default tab sequence, represented in integer form **/ /** The default tab sequence, represented in integer form **/
const val SEQUENCE_DEFAULT = 0b1000_1001_1010_1011_0100 const val SEQUENCE_DEFAULT = 0b1000_1001_1010_1011_0100
// Temporary value to make sure we create a 5-tab sequence even though playlists
// aren't implemented yet.
private const val TEMP_BIT_CAP = 20
/** /**
* Convert an array [tabs] into a sequence of tabs. * Convert an array [tabs] into a sequence of tabs.
*/ */
@ -66,7 +63,7 @@ sealed class Tab(open val mode: DisplayMode) {
val distinct = tabs.distinctBy { it.mode } val distinct = tabs.distinctBy { it.mode }
var sequence = 0b0100 var sequence = 0b0100
var shift = TEMP_BIT_CAP var shift = SEQUENCE_LEN * 4
distinct.forEach { tab -> distinct.forEach { tab ->
val bin = when (tab) { val bin = when (tab) {
@ -89,9 +86,11 @@ sealed class Tab(open val mode: DisplayMode) {
// Try to parse a mode for each chunk in the sequence. // Try to parse a mode for each chunk in the sequence.
// If we can't parse one, just skip it. // If we can't parse one, just skip it.
for (shift in (0..TEMP_BIT_CAP).reversed() step 4) { for (shift in (0..4 * SEQUENCE_LEN).reversed() step 4) {
val chunk = sequence.shr(shift) and 0b1111 val chunk = sequence.shr(shift) and 0b1111
logD(sequence.shr(shift).toString(2))
val mode = when (chunk and 7) { val mode = when (chunk and 7) {
0 -> DisplayMode.SHOW_SONGS 0 -> DisplayMode.SHOW_SONGS
1 -> DisplayMode.SHOW_ALBUMS 1 -> DisplayMode.SHOW_ALBUMS