mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-30 15:41: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")
|
if (args == null) throw IllegalArgumentException("Required arguments are missing")
|
||||||
|
|
||||||
val refresh = args.getBoolean(Constants.INTENT_EXTRA_NAME_REFRESH)
|
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) {
|
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
|
private var loadedUntil: Int = 0
|
||||||
|
|
||||||
fun getAlbumList(
|
fun getAlbumList(
|
||||||
@ -21,8 +22,14 @@ class AlbumListModel(application: Application) : GenericListModel(application) {
|
|||||||
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.
|
||||||
|
// This way, we keep the scroll position
|
||||||
|
val albumListType = args.getString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE)!!
|
||||||
|
|
||||||
|
if (refresh || albumList.value!!.isEmpty() || albumListType != lastType) {
|
||||||
|
lastType = albumListType
|
||||||
backgroundLoadFromServer(refresh, swipe, args)
|
backgroundLoadFromServer(refresh, swipe, args)
|
||||||
|
}
|
||||||
return albumList
|
return albumList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,13 +30,17 @@ 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) {
|
||||||
private val artists: MutableLiveData<List<Artist>> = MutableLiveData()
|
private val artists: MutableLiveData<List<Artist>> = MutableLiveData(listOf())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all available Artists in a LiveData
|
* Retrieves all available Artists in a LiveData
|
||||||
*/
|
*/
|
||||||
fun getItems(refresh: Boolean, swipe: SwipeRefreshLayout): LiveData<List<Artist>> {
|
fun getItems(refresh: Boolean, swipe: SwipeRefreshLayout): LiveData<List<Artist>> {
|
||||||
|
// 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)
|
backgroundLoadFromServer(refresh, swipe)
|
||||||
|
}
|
||||||
return artists
|
return artists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user