diff --git a/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt b/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt index e988c937c..b25c240a5 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/SettingsCompat.kt @@ -31,58 +31,7 @@ import org.oxycblt.auxio.playback.state.PlaybackMode // TODO: Slate these for removal eventually. There probably isn't that many left who have the // old values but 2.0.0 will probably convince most of those to update too. -fun handleThemeCompat(prefs: SharedPreferences): Int { - if (prefs.contains(OldKeys.KEY_THEME)) { - // Before the creation of IntListPreference, I used strings to represent the themes. - // I no longer need to do this. - val newValue = when (prefs.getStringOrNull(OldKeys.KEY_THEME)) { - EntryValues.THEME_AUTO -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM - EntryValues.THEME_LIGHT -> AppCompatDelegate.MODE_NIGHT_NO - EntryValues.THEME_DARK -> AppCompatDelegate.MODE_NIGHT_YES - - else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM - } - - prefs.edit { - putInt(SettingsManager.KEY_THEME, newValue) - remove(OldKeys.KEY_THEME) - apply() - } - - return newValue - } - - return prefs.getInt(SettingsManager.KEY_THEME, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) -} - fun handleAccentCompat(prefs: SharedPreferences): Accent { - if (prefs.contains(OldKeys.KEY_ACCENT1)) { - var accent = prefs.getInt(OldKeys.KEY_ACCENT1, 5) - - // Correct any accents over yellow to their correct positions - if (accent > 12) { - accent-- - } - - // Correct neutral accents to the closest accent [Grey] - if (accent == 18) { - accent = 16 - } - - // If there are still any issues with indices, just correct them so a crash doesn't occur. - if (accent >= ACCENT_COUNT) { - accent = ACCENT_COUNT - 1 - } - - // Move this to the [also legacy] ACCENT2 field. This makes it easier to convert in the - // next step. - prefs.edit { - putInt(OldKeys.KEY_ACCENT2, accent) - remove(OldKeys.KEY_ACCENT1) - apply() - } - } - if (prefs.contains(OldKeys.KEY_ACCENT2)) { var accent = prefs.getInt(OldKeys.KEY_ACCENT2, 5) @@ -111,55 +60,9 @@ fun handleAccentCompat(prefs: SharedPreferences): Accent { return Accent(prefs.getInt(SettingsManager.KEY_ACCENT, 5)) } -fun handleSongPlayModeCompat(prefs: SharedPreferences): PlaybackMode { - if (prefs.contains(OldKeys.KEY_SONG_PLAYBACK_MODE)) { - val mode = when (prefs.getStringOrNull(OldKeys.KEY_SONG_PLAYBACK_MODE)) { - EntryValues.IN_GENRE -> PlaybackMode.IN_GENRE - EntryValues.IN_ARTIST -> PlaybackMode.IN_ARTIST - EntryValues.IN_ALBUM -> PlaybackMode.IN_ALBUM - EntryValues.ALL_SONGS -> PlaybackMode.ALL_SONGS - - else -> PlaybackMode.ALL_SONGS - } - - prefs.edit { - putInt(SettingsManager.KEY_SONG_PLAYBACK_MODE, mode.toInt()) - remove(OldKeys.KEY_SONG_PLAYBACK_MODE) - apply() - } - - return mode - } - - return PlaybackMode.fromInt(prefs.getInt(SettingsManager.KEY_SONG_PLAYBACK_MODE, Int.MIN_VALUE)) - ?: PlaybackMode.ALL_SONGS -} - -/** - * A verbose shortcut for getString(key, null). Used during string pref migrations - */ -private fun SharedPreferences.getStringOrNull(key: String): String? = getString(key, null) - /** * Cache of the old keys used in Auxio. */ private object OldKeys { - const val KEY_ACCENT1 = "KEY_ACCENT" const val KEY_ACCENT2 = "KEY_ACCENT2" - const val KEY_THEME = "KEY_THEME" - const val KEY_SONG_PLAYBACK_MODE = "KEY_SONG_PLAY_MODE" -} - -/** - * Static cache of old string values used in Auxio - */ -private object EntryValues { - const val THEME_AUTO = "AUTO" - const val THEME_LIGHT = "LIGHT" - const val THEME_DARK = "DARK" - - const val IN_GENRE = "IN_GENRE" - const val IN_ARTIST = "IN_ARTIST" - const val IN_ALBUM = "IN_ALBUM" - const val ALL_SONGS = "ALL_SONGS" } diff --git a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt index 4072d7612..4e8477d39 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt @@ -20,6 +20,7 @@ package org.oxycblt.auxio.settings import android.content.Context import android.content.SharedPreferences +import androidx.appcompat.app.AppCompatDelegate import androidx.core.content.edit import androidx.preference.PreferenceManager import org.oxycblt.auxio.accent.Accent @@ -39,9 +40,6 @@ class SettingsManager private constructor(context: Context) : private val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context) init { - // Poke the song playback mode pref so that it migrates [if it hasn't already] - handleSongPlayModeCompat(sharedPrefs) - sharedPrefs.registerOnSharedPreferenceChangeListener(this) } @@ -49,7 +47,7 @@ class SettingsManager private constructor(context: Context) : /** The current theme */ val theme: Int - get() = handleThemeCompat(sharedPrefs) + get() = sharedPrefs.getInt(KEY_THEME, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) /** Whether the dark theme should be black or not */ val useBlackTheme: Boolean @@ -110,7 +108,8 @@ class SettingsManager private constructor(context: Context) : /** What queue to create when a song is selected (ex. From All Songs or Search) */ val songPlaybackMode: PlaybackMode - get() = handleSongPlayModeCompat(sharedPrefs) + get() = PlaybackMode.fromInt(sharedPrefs.getInt(KEY_SONG_PLAYBACK_MODE, Int.MIN_VALUE)) + ?: PlaybackMode.ALL_SONGS /** Whether shuffle should stay on when a new song is selected. */ val keepShuffle: Boolean diff --git a/info/ARCHITECTURE.md b/info/ARCHITECTURE.md index c38364d23..a7329803a 100644 --- a/info/ARCHITECTURE.md +++ b/info/ARCHITECTURE.md @@ -110,7 +110,7 @@ Other data types represent a specific UI configuration or state: Things to keep in mind while working with music data: - `id` is not derived from the `MediaStore` ID of the music data. It is actually a hash of the unique fields of the music data. Attempting to use it as a `MediaStore` ID will result in errors. -- Any field beginning with `_mediaStore` is off-limits. These fields are meant for use within MusicLoader and generally provide +- Any field beginning with `_mediaStore` is off-limits. These fields are meant for use within `MusicLoader` and generally provide poor UX to the user. - Generally, `name` is used when saving music data to storage, while `resolvedName` is used when displaying music data to the user. - For `Song` instances in particular, prefer `resolvedAlbumName` and `resolvedArtistName` over `album.resolvedName` and `album.artist.resolvedName` diff --git a/info/FAQ.md b/info/FAQ.md index cfd397e99..1085ec962 100644 --- a/info/FAQ.md +++ b/info/FAQ.md @@ -33,7 +33,7 @@ This is expected since reading from the audio database takes awhile, especially #### Auxio does not detect new music! This is a current limitation with the music loader. To remedy this, go to Settings -> Reload music whenever new songs are added. -I hope to make the loader do this automatically eventually. +I hope to make the app rescan music on the fly eventually. #### ReplayGain isn't working on my music!