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)
override fun canSortByName() = false
init {
if (medialibrary.isStarted) refresh()
}
override suspend fun updateList() {
dataset.value = withContext(Dispatchers.Default) { medialibrary.lastMediaPlayed().toMutableList() }
}
......
......@@ -25,7 +25,6 @@ import kotlinx.coroutines.launch
import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.media.MediaLibraryItem
abstract class MedialibraryModel<T : MediaLibraryItem>(context: Context) : BaseModel<T>(context), Medialibrary.OnMedialibraryReadyListener, Medialibrary.OnDeviceChangeListener {
val medialibrary = Medialibrary.getInstance()
......@@ -34,7 +33,6 @@ abstract class MedialibraryModel<T : MediaLibraryItem>(context: Context) : BaseM
medialibrary.apply {
addOnMedialibraryReadyListener(this@MedialibraryModel)
medialibrary.addOnDeviceChangeListener(this@MedialibraryModel)
if (isStarted) refresh()
}
}
......
......@@ -53,7 +53,10 @@ open class VideosModel(context: Context, private val group: String?, val folder
else Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = customDesc ?: Settings.getInstance(context).getBoolean(sortKey+"_desc", false)
Medialibrary.lastThumb.observeForever(thumbObs)
if (medialibrary.isStarted) medialibrary.addMediaCb(this)
if (medialibrary.isStarted) {
medialibrary.addMediaCb(this)
refresh()
}
}
override fun onMediaAdded() {
......
......@@ -43,6 +43,7 @@ class AlbumModel(context: Context, val parent: MediaLibraryItem? = null): AudioM
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (sort == Medialibrary.SORT_ALPHA && parent is Artist) sort = Medialibrary.SORT_RELEASEDATE
if (medialibrary.isStarted) refresh()
}
override fun onAlbumsAdded() {
......
......@@ -35,6 +35,7 @@ class ArtistModel(context: Context, private var showAll: Boolean = false): Audio
init {
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (medialibrary.isStarted) refresh()
}
fun showAll(show: Boolean) {
......
......@@ -36,6 +36,7 @@ class GenresModel(context: Context): AudioModel(context), Medialibrary.GenresCb
init {
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (medialibrary.isStarted) refresh()
}
override fun onMedialibraryReady() {
......
......@@ -32,6 +32,10 @@ import org.videolan.vlc.util.EmptyMLCallbacks
class PlaylistsModel(context: Context): AudioModel(context), Medialibrary.PlaylistsCb by EmptyMLCallbacks {
init {
if (medialibrary.isStarted) refresh()
}
override fun onMedialibraryReady() {
super.onMedialibraryReady()
medialibrary.addPlaylistCb(this)
......
......@@ -43,6 +43,7 @@ class TracksModel(context: Context, val parent: MediaLibraryItem? = null): Audio
is Album -> Medialibrary.SORT_DEFAULT
else -> Medialibrary.SORT_ALPHA
}
if (medialibrary.isStarted) refresh()
}
override fun onMedialibraryReady() {
......
......@@ -31,7 +31,6 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
medialibrary.apply {
medialibrary.addOnMedialibraryReadyListener(this@MLPagedModel)
medialibrary.addOnDeviceChangeListener(this@MLPagedModel)
if (isStarted) refresh()
}
}
......
......@@ -22,6 +22,7 @@ class PagedAlbumsModel(context: Context, val parent: MediaLibraryItem? = null) :
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (sort == Medialibrary.SORT_ALPHA && parent is Artist) sort = Medialibrary.SORT_RELEASEDATE
if (medialibrary.isStarted) refresh()
}
override fun onAlbumsAdded() {
......
......@@ -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 {
init {
if (medialibrary.isStarted) refresh()
}
override fun onArtistsAdded() {
refresh()
}
......
......@@ -11,6 +11,11 @@ import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.media.getAll
class PagedFoldersModel(context: Context, val type: Int) : MLPagedModel<Folder>(context) {
init {
if (medialibrary.isStarted) refresh()
}
override fun getAll() = emptyArray<Folder>()
override fun getTotalCount() = medialibrary.getFoldersCount(type)
......
......@@ -13,6 +13,7 @@ class PagedGenresModel(context: Context): MLPagedModel<Genre>(context), Medialib
init {
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_ALPHA)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", false)
if (medialibrary.isStarted) refresh()
}
override fun onMedialibraryReady() {
......
......@@ -8,6 +8,10 @@ import org.videolan.medialibrary.media.Playlist
class PagedPlaylistsModel(context: Context): MLPagedModel<Playlist>(context), Medialibrary.PlaylistsCb {
init {
if (medialibrary.isStarted) refresh()
}
override fun onMedialibraryReady() {
super.onMedialibraryReady()
medialibrary.addPlaylistCb(this)
......
......@@ -30,6 +30,7 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
is Album -> Medialibrary.SORT_DEFAULT
else -> Medialibrary.SORT_ALPHA
}
if (medialibrary.isStarted) refresh()
}
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