[Android] Improve settings sharing between the view models

Nicolas Pomepuy git at videolan.org
Fri Jun 17 13:30:06 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun 14 09:11:38 2022 +0200| [d0f4eb545774c3cf954a3d0f453ac734b262143f] | committer: Duncan McNamara

Improve settings sharing between the view models

> https://code.videolan.org/videolan/vlc-android/commit/d0f4eb545774c3cf954a3d0f453ac734b262143f
---

 .../vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt   | 2 +-
 .../src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt  | 2 --
 .../org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt    | 7 +++----
 .../src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt   | 2 --
 4 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
index 725d50105..50fd5239e 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/SortableModel.kt
@@ -11,7 +11,7 @@ import org.videolan.vlc.util.SortModule
 abstract class SortableModel(protected val context: Context): ViewModel(), RefreshModel,
     SortModule
 {
-    private val settings = Settings.getInstance(context)
+    open val settings = Settings.getInstance(context)
     protected open val sortKey : String = this.javaClass.simpleName
     var sort = settings.getInt(sortKey, Medialibrary.SORT_DEFAULT)
     var desc = settings.getBoolean("${sortKey}_desc", false)
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt
index e42478bad..f4be35493 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AlbumSongsViewModel.kt
@@ -26,7 +26,6 @@ import androidx.lifecycle.ViewModelProvider
 import org.videolan.medialibrary.interfaces.media.Album
 import org.videolan.medialibrary.interfaces.media.Artist
 import org.videolan.medialibrary.media.MediaLibraryItem
-import org.videolan.tools.Settings
 import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment
 import org.videolan.vlc.providers.medialibrary.AlbumsProvider
 import org.videolan.vlc.providers.medialibrary.TracksProvider
@@ -39,7 +38,6 @@ class AlbumSongsViewModel(context: Context, val parent: MediaLibraryItem) : Medi
     override val providers = arrayOf(albumsProvider, tracksProvider)
     val providersInCard = arrayOf(true, false)
     val displayModeKeys = arrayOf("display_mode_albums_song_albums", "display_mode_albums_song_tracks")
-    private val settings = Settings.getInstance(context)
 
     init {
         when (parent) {
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 24c861367..a5abd6ff6 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
@@ -25,14 +25,14 @@ import androidx.lifecycle.ViewModel
 import androidx.lifecycle.ViewModelProvider
 import androidx.lifecycle.viewModelScope
 import kotlinx.coroutines.launch
+import org.videolan.resources.KEY_AUDIO_CURRENT_TAB
+import org.videolan.tools.KEY_ARTISTS_SHOW_ALL
+import org.videolan.tools.Settings
 import org.videolan.vlc.gui.audio.AudioBrowserFragment
 import org.videolan.vlc.providers.medialibrary.AlbumsProvider
 import org.videolan.vlc.providers.medialibrary.ArtistsProvider
 import org.videolan.vlc.providers.medialibrary.GenresProvider
 import org.videolan.vlc.providers.medialibrary.TracksProvider
-import org.videolan.resources.KEY_AUDIO_CURRENT_TAB
-import org.videolan.tools.KEY_ARTISTS_SHOW_ALL
-import org.videolan.tools.Settings
 import org.videolan.vlc.viewmodels.MedialibraryViewModel
 
 class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context) {
@@ -44,7 +44,6 @@ class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context) {
     val tracksProvider = TracksProvider(null, context, this)
     val genresProvider = GenresProvider(context, this)
     override val providers = arrayOf(artistsProvider, albumsProvider, tracksProvider, genresProvider)
-    private val settings = Settings.getInstance(context)
     val providersInCard = arrayOf(true, true, false, false)
 
     var showResumeCard = settings.getBoolean("audio_resume_card", true)
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 0c50d7f6a..b33cd57fc 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
@@ -24,7 +24,6 @@ import android.content.Context
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.ViewModelProvider
 import org.videolan.medialibrary.media.MediaLibraryItem
-import org.videolan.tools.Settings
 import org.videolan.vlc.gui.PlaylistFragment
 import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
 import org.videolan.vlc.providers.medialibrary.PlaylistsProvider
@@ -35,7 +34,6 @@ class PlaylistsViewModel(context: Context) : MedialibraryViewModel(context) {
     val provider = PlaylistsProvider(context, this)
     var providerInCard = true
     override val providers : Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
-    private val settings = Settings.getInstance(context)
 
     init {
         watchPlaylists()



More information about the Android mailing list