home: fix tab setting migration

Fix a few issues with the tab migration:
1. It wasn't even being ran
2. It incorrectly updated the tabs by adding a playlist tab when it was
actually already present.
This commit is contained in:
Alexander Capehart 2023-05-21 11:45:00 -06:00
parent 8953f12a1e
commit fb892453bd
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 9 additions and 5 deletions

View file

@ -25,6 +25,7 @@ import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import org.oxycblt.auxio.home.HomeSettings
import org.oxycblt.auxio.image.ImageSettings
import org.oxycblt.auxio.playback.PlaybackSettings
import org.oxycblt.auxio.ui.UISettings
@ -39,6 +40,7 @@ class Auxio : Application() {
@Inject lateinit var imageSettings: ImageSettings
@Inject lateinit var playbackSettings: PlaybackSettings
@Inject lateinit var uiSettings: UISettings
@Inject lateinit var homeSettings: HomeSettings
override fun onCreate() {
super.onCreate()
@ -46,6 +48,7 @@ class Auxio : Application() {
imageSettings.migrate()
playbackSettings.migrate()
uiSettings.migrate()
homeSettings.migrate()
// Adding static shortcuts in a dynamic manner is better than declaring them
// manually, as it will properly handle the difference between debug and release
// Auxio instances.

View file

@ -71,10 +71,13 @@ class HomeSettingsImpl @Inject constructor(@ApplicationContext context: Context)
Tab.fromIntCode(sharedPreferences.getInt(OLD_KEY_LIB_TABS, Tab.SEQUENCE_DEFAULT))
?: unlikelyToBeNull(Tab.fromIntCode(Tab.SEQUENCE_DEFAULT))
// Add the new playlist tab to old tab configurations
val correctedTabs = oldTabs + Tab.Visible(MusicMode.PLAYLISTS)
// The playlist tab is now parsed, but it needs to be made visible.
val playlistIndex = oldTabs.indexOfFirst { it.mode == MusicMode.PLAYLISTS }
if (playlistIndex > -1) { // Sanity check
oldTabs[playlistIndex] = Tab.Visible(MusicMode.PLAYLISTS)
}
sharedPreferences.edit {
putInt(getString(R.string.set_key_home_tabs), Tab.toIntCode(correctedTabs))
putInt(getString(R.string.set_key_home_tabs), Tab.toIntCode(oldTabs))
remove(OLD_KEY_LIB_TABS)
}
}

View file

@ -26,8 +26,6 @@ import org.oxycblt.auxio.util.logE
*
* @param mode The type of list in the home view this instance corresponds to.
* @author Alexander Capehart (OxygenCobalt)
*
* TODO: Tab migration to playlists is busted and resets the config entirely. Need to fix.
*/
sealed class Tab(open val mode: MusicMode) {
/**