mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-29 07:01:33 +03:00
Avoid unnecessary reloads when navigating back,
this preserves the scroll position.
This commit is contained in:
parent
36dccc845b
commit
bc16b64be4
@ -49,8 +49,9 @@ class AlbumListFragment : GenericListFragment<MusicDirectory.Entry, AlbumRowAdap
|
||||
if (args == null) throw IllegalArgumentException("Required arguments are missing")
|
||||
|
||||
val refresh = args.getBoolean(Constants.INTENT_EXTRA_NAME_REFRESH)
|
||||
val append = args.getBoolean(Constants.INTENT_EXTRA_NAME_APPEND)
|
||||
|
||||
return listModel.getAlbumList(refresh, refreshListView!!, args)
|
||||
return listModel.getAlbumList(refresh or append, refreshListView!!, args)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,8 @@ import org.moire.ultrasonic.util.Util
|
||||
|
||||
class AlbumListModel(application: Application) : GenericListModel(application) {
|
||||
|
||||
val albumList: MutableLiveData<List<MusicDirectory.Entry>> = MutableLiveData()
|
||||
val albumList: MutableLiveData<List<MusicDirectory.Entry>> = MutableLiveData(listOf())
|
||||
var lastType: String? = null
|
||||
private var loadedUntil: Int = 0
|
||||
|
||||
fun getAlbumList(
|
||||
@ -21,8 +22,14 @@ class AlbumListModel(application: Application) : GenericListModel(application) {
|
||||
swipe: SwipeRefreshLayout,
|
||||
args: Bundle
|
||||
): LiveData<List<MusicDirectory.Entry>> {
|
||||
// Don't reload the data if navigating back to the view that was active before.
|
||||
// This way, we keep the scroll position
|
||||
val albumListType = args.getString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE)!!
|
||||
|
||||
backgroundLoadFromServer(refresh, swipe, args)
|
||||
if (refresh || albumList.value!!.isEmpty() || albumListType != lastType) {
|
||||
lastType = albumListType
|
||||
backgroundLoadFromServer(refresh, swipe, args)
|
||||
}
|
||||
return albumList
|
||||
}
|
||||
|
||||
|
@ -30,13 +30,17 @@ import org.moire.ultrasonic.service.MusicService
|
||||
* Provides ViewModel which contains the list of available Artists
|
||||
*/
|
||||
class ArtistListModel(application: Application) : GenericListModel(application) {
|
||||
private val artists: MutableLiveData<List<Artist>> = MutableLiveData()
|
||||
private val artists: MutableLiveData<List<Artist>> = MutableLiveData(listOf())
|
||||
|
||||
/**
|
||||
* Retrieves all available Artists in a LiveData
|
||||
*/
|
||||
fun getItems(refresh: Boolean, swipe: SwipeRefreshLayout): LiveData<List<Artist>> {
|
||||
backgroundLoadFromServer(refresh, swipe)
|
||||
// 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) {
|
||||
backgroundLoadFromServer(refresh, swipe)
|
||||
}
|
||||
return artists
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user