Commit 8f25dcfb authored by Geoffrey Métais's avatar Geoffrey Métais

Asynchronously compute lists headers

Allows to load lists faster, but UI has to be ready to load headers
later
parent 4b6d909d
Pipeline #17202 passed with stage
in 3 minutes and 14 seconds
......@@ -21,7 +21,9 @@
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.Album
import org.videolan.medialibrary.interfaces.media.Artist
......@@ -59,7 +61,8 @@ class AlbumsProvider(val parent : MediaLibraryItem?, context: Context, model: So
is Genre -> parent.searchAlbums(model.filterQuery, sort, desc, loadSize, startposition)
else -> medialibrary.searchAlbum(model.filterQuery, sort, desc, loadSize, startposition)
}
return list.also { completeHeaders(it, startposition) }
model.viewModelScope.launch { completeHeaders(list, startposition) }
return list
}
override fun getTotalCount() = if (model.filterQuery == null) when(parent) {
......
......@@ -21,7 +21,9 @@
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.media.Artist
import org.videolan.vlc.viewmodels.SortableModel
......@@ -34,7 +36,8 @@ class ArtistsProvider(context: Context, model: SortableModel, var showAll: Boole
override fun getPage(loadSize: Int, startposition: Int): Array<Artist> {
val list = if (model.filterQuery == null) medialibrary.getPagedArtists(showAll, sort, desc, loadSize, startposition)
else medialibrary.searchArtist(model.filterQuery, sort, desc, loadSize, startposition)
return list.also { completeHeaders(it, startposition) }
model.viewModelScope.launch { completeHeaders(list, startposition) }
return list
}
override fun getTotalCount() = if (model.filterQuery == null) medialibrary.getArtistsCount(showAll)
......
......@@ -21,8 +21,11 @@
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.media.Folder
import org.videolan.tools.Settings
import org.videolan.vlc.viewmodels.SortableModel
......@@ -36,6 +39,5 @@ class FoldersProvider(context: Context, model: SortableModel, val type: Int) : M
medialibrary.getFolders(type, sort, desc, loadSize, startposition).also { completeHeaders(it, startposition) }
} else {
medialibrary.searchFolders(model.filterQuery, sort, desc, loadSize, startposition)
}
}.also { if (Settings.showTvUi) completeHeaders(it, startposition) }
}
\ No newline at end of file
......@@ -21,7 +21,9 @@
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.media.Genre
import org.videolan.vlc.viewmodels.SortableModel
......@@ -34,7 +36,8 @@ class GenresProvider(context: Context, model: SortableModel) : MedialibraryProvi
override fun getPage(loadSize: Int, startposition: Int) : Array<Genre> {
val list = if (model.filterQuery == null) medialibrary.getPagedGenres(sort, desc, loadSize, startposition)
else medialibrary.searchGenre(model.filterQuery, sort, desc, loadSize, startposition)
return list.also { completeHeaders(it, startposition) }
model.viewModelScope.launch { completeHeaders(list, startposition) }
return list
}
override fun getTotalCount() = if (model.filterQuery == null) medialibrary.genresCount else medialibrary.getGenresCount(model.filterQuery)
......
......@@ -21,7 +21,9 @@
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.media.Playlist
import org.videolan.vlc.viewmodels.SortableModel
......@@ -34,7 +36,8 @@ class PlaylistsProvider(context: Context, model: SortableModel) : MedialibraryPr
override fun getPage(loadSize: Int, startposition: Int) : Array<Playlist> {
val list = if (model.filterQuery == null) medialibrary.getPagedPlaylists(sort, desc, loadSize, startposition)
else medialibrary.searchPlaylist(model.filterQuery, sort, desc, loadSize, startposition)
return list.also { completeHeaders(it, startposition) }
model.viewModelScope.launch { completeHeaders(list, startposition) }
return list
}
override fun getTotalCount() = if (model.filterQuery == null) medialibrary.playlistsCount else medialibrary.getPlaylistsCount(model.filterQuery)
......
......@@ -21,7 +21,9 @@
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.*
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -67,7 +69,8 @@ class TracksProvider(val parent : MediaLibraryItem?, context: Context, model: So
is Playlist -> parent.searchTracks(model.filterQuery, sort, desc, loadSize, startposition)
else -> medialibrary.searchAudio(model.filterQuery, sort, desc, loadSize, startposition)
}
return list.also { completeHeaders(it, startposition) }
model.viewModelScope.launch { completeHeaders(list, startposition) }
return list
}
override fun getTotalCount() = if (model.filterQuery == null) when (parent) {
......
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.VideoGroup
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -22,7 +24,7 @@ class VideoGroupsProvider(context: Context, model: SortableModel) : Medialibrary
medialibrary.getVideoGroups(sort, desc, loadSize, startposition)
} else {
medialibrary.searchVideoGroups(model.filterQuery, sort, desc, loadSize, startposition)
}.extractSingles().also { if (Settings.showTvUi)completeHeaders(it, startposition) }
}.extractSingles().also { if (Settings.showTvUi) completeHeaders(it, startposition) }
}
private fun Array<VideoGroup>.extractSingles() = map {
......
......@@ -21,7 +21,9 @@
package org.videolan.vlc.providers.medialibrary
import android.content.Context
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.media.Folder
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.interfaces.media.VideoGroup
......@@ -56,7 +58,8 @@ class VideosProvider(val folder : Folder?, val group: VideoGroup?, context: Cont
group !== null -> group.searchTracks(model.filterQuery, sort, desc, loadSize, startposition)
else -> medialibrary.searchVideo(model.filterQuery, sort, desc, loadSize, startposition)
}
return list.also { completeHeaders(it, startposition) }
model.viewModelScope.launch { completeHeaders(list, startposition) }
return list
}
override fun getAll(): Array<MediaWrapper> = when {
......
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