restore previous code
This commit is contained in:
parent
c9f2050c46
commit
961c726da8
|
@ -19,7 +19,7 @@ class AlbumListModel(application: Application) : GenericListModel(application) {
|
|||
|
||||
fun getAlbumList(
|
||||
refresh: Boolean,
|
||||
swipe: SwipeRefreshLayout?,
|
||||
swipe: SwipeRefreshLayout,
|
||||
args: Bundle
|
||||
): LiveData<List<MusicDirectory.Entry>> {
|
||||
// Don't reload the data if navigating back to the view that was active before.
|
||||
|
|
|
@ -30,12 +30,12 @@ import org.moire.ultrasonic.service.MusicService
|
|||
* Provides ViewModel which contains the list of available Artists
|
||||
*/
|
||||
class ArtistListModel(application: Application) : GenericListModel(application) {
|
||||
val artists: MutableLiveData<List<ArtistOrIndex>> = MutableLiveData(listOf())
|
||||
private val artists: MutableLiveData<List<ArtistOrIndex>> = MutableLiveData(listOf())
|
||||
|
||||
/**
|
||||
* Retrieves all available Artists in a LiveData
|
||||
*/
|
||||
fun getItems(refresh: Boolean, swipe: SwipeRefreshLayout?): LiveData<List<ArtistOrIndex>> {
|
||||
fun getItems(refresh: Boolean, swipe: SwipeRefreshLayout): LiveData<List<ArtistOrIndex>> {
|
||||
// Don't reload the data if navigating back to the view that was active before.
|
||||
// This way, we keep the scroll position
|
||||
if (artists.value!!.isEmpty() || refresh) {
|
||||
|
|
|
@ -66,24 +66,20 @@ open class GenericListModel(application: Application) :
|
|||
*/
|
||||
fun backgroundLoadFromServer(
|
||||
refresh: Boolean,
|
||||
swipe: SwipeRefreshLayout?,
|
||||
swipe: SwipeRefreshLayout,
|
||||
bundle: Bundle = Bundle()
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
if (swipe != null) {
|
||||
swipe.isRefreshing = true
|
||||
}
|
||||
swipe.isRefreshing = true
|
||||
loadFromServer(refresh, swipe, bundle)
|
||||
if (swipe != null) {
|
||||
swipe.isRefreshing = false
|
||||
}
|
||||
swipe.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the load() function with error handling
|
||||
*/
|
||||
suspend fun loadFromServer(refresh: Boolean, swipe: SwipeRefreshLayout?, bundle: Bundle) =
|
||||
suspend fun loadFromServer(refresh: Boolean, swipe: SwipeRefreshLayout, bundle: Bundle) =
|
||||
withContext(Dispatchers.IO) {
|
||||
val musicService = MusicServiceFactory.getMusicService()
|
||||
val isOffline = ActiveServerProvider.isOffline()
|
||||
|
@ -92,9 +88,7 @@ open class GenericListModel(application: Application) :
|
|||
try {
|
||||
load(isOffline, useId3Tags, musicService, refresh, bundle)
|
||||
} catch (all: Exception) {
|
||||
if (swipe != null) {
|
||||
handleException(all, swipe.context)
|
||||
}
|
||||
handleException(all, swipe.context)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue