Commit c19920e1 authored by Geoffrey Métais's avatar Geoffrey Métais

ViewModels: refresh after values initialization

Fix #732
parent ed8b937a
...@@ -31,6 +31,10 @@ class HistoryModel(context: Context) : MedialibraryModel<MediaWrapper>(context) ...@@ -31,6 +31,10 @@ class HistoryModel(context: Context) : MedialibraryModel<MediaWrapper>(context)
override fun canSortByName() = false override fun canSortByName() = false
init {
if (medialibrary.isStarted) refresh()
}
override suspend fun updateList() { override suspend fun updateList() {
dataset.value = withContext(Dispatchers.Default) { medialibrary.lastMediaPlayed().toMutableList() } dataset.value = withContext(Dispatchers.Default) { medialibrary.lastMediaPlayed().toMutableList() }
} }
......
...@@ -25,7 +25,6 @@ import kotlinx.coroutines.launch ...@@ -25,7 +25,6 @@ import kotlinx.coroutines.launch
import org.videolan.medialibrary.Medialibrary import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.media.MediaLibraryItem import org.videolan.medialibrary.media.MediaLibraryItem
abstract class MedialibraryModel<T : MediaLibraryItem>(context: Context) : BaseModel<T>(context), Medialibrary.OnMedialibraryReadyListener, Medialibrary.OnDeviceChangeListener { abstract class MedialibraryModel<T : MediaLibraryItem>(context: Context) : BaseModel<T>(context), Medialibrary.OnMedialibraryReadyListener, Medialibrary.OnDeviceChangeListener {
val medialibrary = Medialibrary.getInstance() val medialibrary = Medialibrary.getInstance()
...@@ -34,7 +33,6 @@ abstract class MedialibraryModel<T : MediaLibraryItem>(context: Context) : BaseM ...@@ -34,7 +33,6 @@ abstract class MedialibraryModel<T : MediaLibraryItem>(context: Context) : BaseM
medialibrary.apply { medialibrary.apply {
addOnMedialibraryReadyListener(this@MedialibraryModel) addOnMedialibraryReadyListener(this@MedialibraryModel)
medialibrary.addOnDeviceChangeListener(this@MedialibraryModel) medialibrary.addOnDeviceChangeListener(this@MedialibraryModel)
if (isStarted) refresh()
} }
} }
......
...@@ -53,7 +53,10 @@ open class VideosModel(context: Context, private val group: String?, val folder ...@@ -53,7 +53,10 @@ open class VideosModel(context: Context, private val group: String?, val folder
else Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA) else Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = customDesc ?: Settings.getInstance(context).getBoolean(sortKey+"_desc", false) desc = customDesc ?: Settings.getInstance(context).getBoolean(sortKey+"_desc", false)
Medialibrary.lastThumb.observeForever(thumbObs) Medialibrary.lastThumb.observeForever(thumbObs)
if (medialibrary.isStarted) medialibrary.addMediaCb(this) if (medialibrary.isStarted) {
medialibrary.addMediaCb(this)
refresh()
}
} }
override fun onMediaAdded() { override fun onMediaAdded() {
......
...@@ -43,6 +43,7 @@ class AlbumModel(context: Context, val parent: MediaLibraryItem? = null): AudioM ...@@ -43,6 +43,7 @@ class AlbumModel(context: Context, val parent: MediaLibraryItem? = null): AudioM
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA) sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false) desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (sort == Medialibrary.SORT_ALPHA && parent is Artist) sort = Medialibrary.SORT_RELEASEDATE if (sort == Medialibrary.SORT_ALPHA && parent is Artist) sort = Medialibrary.SORT_RELEASEDATE
if (medialibrary.isStarted) refresh()
} }
override fun onAlbumsAdded() { override fun onAlbumsAdded() {
......
...@@ -35,6 +35,7 @@ class ArtistModel(context: Context, private var showAll: Boolean = false): Audio ...@@ -35,6 +35,7 @@ class ArtistModel(context: Context, private var showAll: Boolean = false): Audio
init { init {
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA) sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false) desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (medialibrary.isStarted) refresh()
} }
fun showAll(show: Boolean) { fun showAll(show: Boolean) {
......
...@@ -36,6 +36,7 @@ class GenresModel(context: Context): AudioModel(context), Medialibrary.GenresCb ...@@ -36,6 +36,7 @@ class GenresModel(context: Context): AudioModel(context), Medialibrary.GenresCb
init { init {
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA) sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false) desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (medialibrary.isStarted) refresh()
} }
override fun onMedialibraryReady() { override fun onMedialibraryReady() {
......
...@@ -32,6 +32,10 @@ import org.videolan.vlc.util.EmptyMLCallbacks ...@@ -32,6 +32,10 @@ import org.videolan.vlc.util.EmptyMLCallbacks
class PlaylistsModel(context: Context): AudioModel(context), Medialibrary.PlaylistsCb by EmptyMLCallbacks { class PlaylistsModel(context: Context): AudioModel(context), Medialibrary.PlaylistsCb by EmptyMLCallbacks {
init {
if (medialibrary.isStarted) refresh()
}
override fun onMedialibraryReady() { override fun onMedialibraryReady() {
super.onMedialibraryReady() super.onMedialibraryReady()
medialibrary.addPlaylistCb(this) medialibrary.addPlaylistCb(this)
......
...@@ -43,6 +43,7 @@ class TracksModel(context: Context, val parent: MediaLibraryItem? = null): Audio ...@@ -43,6 +43,7 @@ class TracksModel(context: Context, val parent: MediaLibraryItem? = null): Audio
is Album -> Medialibrary.SORT_DEFAULT is Album -> Medialibrary.SORT_DEFAULT
else -> Medialibrary.SORT_ALPHA else -> Medialibrary.SORT_ALPHA
} }
if (medialibrary.isStarted) refresh()
} }
override fun onMedialibraryReady() { override fun onMedialibraryReady() {
......
...@@ -31,7 +31,6 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo ...@@ -31,7 +31,6 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
medialibrary.apply { medialibrary.apply {
medialibrary.addOnMedialibraryReadyListener(this@MLPagedModel) medialibrary.addOnMedialibraryReadyListener(this@MLPagedModel)
medialibrary.addOnDeviceChangeListener(this@MLPagedModel) medialibrary.addOnDeviceChangeListener(this@MLPagedModel)
if (isStarted) refresh()
} }
} }
......
...@@ -22,6 +22,7 @@ class PagedAlbumsModel(context: Context, val parent: MediaLibraryItem? = null) : ...@@ -22,6 +22,7 @@ class PagedAlbumsModel(context: Context, val parent: MediaLibraryItem? = null) :
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA) sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false) desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (sort == Medialibrary.SORT_ALPHA && parent is Artist) sort = Medialibrary.SORT_RELEASEDATE if (sort == Medialibrary.SORT_ALPHA && parent is Artist) sort = Medialibrary.SORT_RELEASEDATE
if (medialibrary.isStarted) refresh()
} }
override fun onAlbumsAdded() { override fun onAlbumsAdded() {
......
...@@ -11,6 +11,9 @@ import org.videolan.vlc.util.Settings ...@@ -11,6 +11,9 @@ import org.videolan.vlc.util.Settings
class PagedArtistsModel(context: Context, private var showAll: Boolean = false): MLPagedModel<Artist>(context), Medialibrary.ArtistsCb by EmptyMLCallbacks { class PagedArtistsModel(context: Context, private var showAll: Boolean = false): MLPagedModel<Artist>(context), Medialibrary.ArtistsCb by EmptyMLCallbacks {
init {
if (medialibrary.isStarted) refresh()
}
override fun onArtistsAdded() { override fun onArtistsAdded() {
refresh() refresh()
} }
......
...@@ -11,6 +11,11 @@ import org.videolan.vlc.media.MediaUtils ...@@ -11,6 +11,11 @@ import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.media.getAll import org.videolan.vlc.media.getAll
class PagedFoldersModel(context: Context, val type: Int) : MLPagedModel<Folder>(context) { class PagedFoldersModel(context: Context, val type: Int) : MLPagedModel<Folder>(context) {
init {
if (medialibrary.isStarted) refresh()
}
override fun getAll() = emptyArray<Folder>() override fun getAll() = emptyArray<Folder>()
override fun getTotalCount() = medialibrary.getFoldersCount(type) override fun getTotalCount() = medialibrary.getFoldersCount(type)
......
...@@ -13,6 +13,7 @@ class PagedGenresModel(context: Context): MLPagedModel<Genre>(context), Medialib ...@@ -13,6 +13,7 @@ class PagedGenresModel(context: Context): MLPagedModel<Genre>(context), Medialib
init { init {
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA) sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false) desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (medialibrary.isStarted) refresh()
} }
override fun onMedialibraryReady() { override fun onMedialibraryReady() {
......
...@@ -8,6 +8,10 @@ import org.videolan.medialibrary.media.Playlist ...@@ -8,6 +8,10 @@ import org.videolan.medialibrary.media.Playlist
class PagedPlaylistsModel(context: Context): MLPagedModel<Playlist>(context), Medialibrary.PlaylistsCb { class PagedPlaylistsModel(context: Context): MLPagedModel<Playlist>(context), Medialibrary.PlaylistsCb {
init {
if (medialibrary.isStarted) refresh()
}
override fun onMedialibraryReady() { override fun onMedialibraryReady() {
super.onMedialibraryReady() super.onMedialibraryReady()
medialibrary.addPlaylistCb(this) medialibrary.addPlaylistCb(this)
......
...@@ -30,6 +30,7 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null): ...@@ -30,6 +30,7 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
is Album -> Medialibrary.SORT_DEFAULT is Album -> Medialibrary.SORT_DEFAULT
else -> Medialibrary.SORT_ALPHA else -> Medialibrary.SORT_ALPHA
} }
if (medialibrary.isStarted) refresh()
} }
override fun onMedialibraryReady() { override fun onMedialibraryReady() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment