restore previous code

This commit is contained in:
James Wells 2021-07-18 16:14:43 -04:00
parent c9f2050c46
commit 961c726da8
No known key found for this signature in database
GPG Key ID: DB1528F6EED16127
3 changed files with 8 additions and 14 deletions

View File

@ -19,7 +19,7 @@ class AlbumListModel(application: Application) : GenericListModel(application) {
fun getAlbumList( fun getAlbumList(
refresh: Boolean, refresh: Boolean,
swipe: SwipeRefreshLayout?, swipe: SwipeRefreshLayout,
args: Bundle args: Bundle
): LiveData<List<MusicDirectory.Entry>> { ): LiveData<List<MusicDirectory.Entry>> {
// Don't reload the data if navigating back to the view that was active before. // Don't reload the data if navigating back to the view that was active before.

View File

@ -30,12 +30,12 @@ import org.moire.ultrasonic.service.MusicService
* Provides ViewModel which contains the list of available Artists * Provides ViewModel which contains the list of available Artists
*/ */
class ArtistListModel(application: Application) : GenericListModel(application) { 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 * 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. // Don't reload the data if navigating back to the view that was active before.
// This way, we keep the scroll position // This way, we keep the scroll position
if (artists.value!!.isEmpty() || refresh) { if (artists.value!!.isEmpty() || refresh) {

View File

@ -66,24 +66,20 @@ open class GenericListModel(application: Application) :
*/ */
fun backgroundLoadFromServer( fun backgroundLoadFromServer(
refresh: Boolean, refresh: Boolean,
swipe: SwipeRefreshLayout?, swipe: SwipeRefreshLayout,
bundle: Bundle = Bundle() bundle: Bundle = Bundle()
) { ) {
viewModelScope.launch { viewModelScope.launch {
if (swipe != null) { swipe.isRefreshing = true
swipe.isRefreshing = true
}
loadFromServer(refresh, swipe, bundle) loadFromServer(refresh, swipe, bundle)
if (swipe != null) { swipe.isRefreshing = false
swipe.isRefreshing = false
}
} }
} }
/** /**
* Calls the load() function with error handling * 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) { withContext(Dispatchers.IO) {
val musicService = MusicServiceFactory.getMusicService() val musicService = MusicServiceFactory.getMusicService()
val isOffline = ActiveServerProvider.isOffline() val isOffline = ActiveServerProvider.isOffline()
@ -92,9 +88,7 @@ open class GenericListModel(application: Application) :
try { try {
load(isOffline, useId3Tags, musicService, refresh, bundle) load(isOffline, useId3Tags, musicService, refresh, bundle)
} catch (all: Exception) { } catch (all: Exception) {
if (swipe != null) { handleException(all, swipe.context)
handleException(all, swipe.context)
}
} }
} }