[Android] Discriminate the playlist list/grid setting between audio and video and migrate it
Nicolas Pomepuy
git at videolan.org
Fri Nov 18 12:29:46 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Nov 17 09:05:25 2022 +0100| [e1c0315b42f0a8adf0e197f5623d4b9def096966] | committer: Nicolas Pomepuy
Discriminate the playlist list/grid setting between audio and video and migrate it
> https://code.videolan.org/videolan/vlc-android/commit/e1c0315b42f0a8adf0e197f5623d4b9def096966
---
.../providers/medialibrary/PlaylistsProvider.kt | 3 ---
.../src/org/videolan/vlc/util/VersionMigration.kt | 28 +++++++++++++++++++++-
.../vlc/viewmodels/mobile/AudioBrowserViewModel.kt | 2 +-
.../vlc/viewmodels/mobile/PlaylistsViewModel.kt | 2 +-
4 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt
index 2ddf2bd0c2..a07675c7c2 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt
@@ -29,9 +29,6 @@ import org.videolan.vlc.viewmodels.SortableModel
class PlaylistsProvider(context: Context, model: SortableModel, val type: Playlist.Type) : MedialibraryProvider<Playlist>(context, model) {
- override val sortKey: String
- get() = super.sortKey+"_"+type
-
override fun getAll() : Array<Playlist> = medialibrary.getPlaylists(type, sort, desc, Settings.includeMissing)
override fun getPage(loadSize: Int, startposition: Int) : Array<Playlist> {
diff --git a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
index 451f796b82..b8a9385fbe 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
@@ -33,6 +33,7 @@ import androidx.core.content.edit
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.videolan.medialibrary.interfaces.Medialibrary
+import org.videolan.medialibrary.interfaces.media.Playlist
import org.videolan.resources.AndroidDevices
import org.videolan.resources.util.getFromMl
import org.videolan.tools.*
@@ -41,7 +42,7 @@ import org.videolan.vlc.isVLC4
import java.io.File
import java.io.IOException
-private const val CURRENT_VERSION = 10
+private const val CURRENT_VERSION = 11
object VersionMigration {
@@ -84,6 +85,10 @@ object VersionMigration {
migrateToVersion10(settings)
}
+ if (lastVersion < 11) {
+ migrateToVersion11(settings)
+ }
+
//Major version upgrade
if (lastMajorVersion == 3 && currentMajorVersion == 4) {
migrateToVlc4(settings)
@@ -251,6 +256,27 @@ object VersionMigration {
}
}
+ /**
+ * Migrate the playlists' display in grid setting
+ */
+ private fun migrateToVersion11(settings: SharedPreferences) {
+ Log.i(this::class.java.simpleName, "Migration to Version 11: Migrate the playlists' display in grid setting")
+ if (settings.contains("display_mode_playlists"))
+ settings.edit(true) {
+ settings.getBoolean("display_mode_playlists", true).let {oldSetting ->
+ try {
+ val oldColor = oldSetting.toInt()
+ val newColor = Color.argb(255, Color.red(oldColor), Color.green(oldColor), Color.blue(oldColor))
+ putInt("subtitles_color", newColor)
+ } catch (e: Exception) {
+ }
+ putBoolean("display_mode_playlists_${Playlist.Type.AudioOnly}", oldSetting)
+ putBoolean("display_mode_playlists_${Playlist.Type.VideoOnly}", oldSetting)
+ remove("display_mode_playlists")
+ }
+ }
+ }
+
/**
* Migration to vlc 4
* ⚠️⚠️⚠️ This should not be destructive! Any first install will run this.
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
index 3b3e4df9d4..42d6cafa02 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
@@ -46,7 +46,7 @@ class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context) {
val providersInCard = arrayOf(true, true, false, false, true)
var showResumeCard = settings.getBoolean("audio_resume_card", true)
- val displayModeKeys = arrayOf("display_mode_audio_browser_artists", "display_mode_audio_browser_albums", "display_mode_audio_browser_track", "display_mode_audio_browser_genres", "display_mode_playlists")
+ val displayModeKeys = arrayOf("display_mode_audio_browser_artists", "display_mode_audio_browser_albums", "display_mode_audio_browser_track", "display_mode_audio_browser_genres", "display_mode_playlists_AudioOnly")
init {
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
index cb84aa3472..c8361d0d46 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
@@ -31,7 +31,7 @@ import org.videolan.vlc.providers.medialibrary.PlaylistsProvider
import org.videolan.vlc.viewmodels.MedialibraryViewModel
class PlaylistsViewModel(context: Context, type: Playlist.Type) : MedialibraryViewModel(context) {
- val displayModeKey: String = "display_mode_playlists"
+ val displayModeKey: String = "display_mode_playlists_$type"
val provider = PlaylistsProvider(context, this, type)
var providerInCard = true
override val providers : Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
More information about the Android
mailing list