mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
fix: Fix issues with AlbumCatalogue
This commit is contained in:
parent
ae82bcd7bf
commit
c6d08d6a3f
3 changed files with 38 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.cappielloantonio.tempo.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
|
|
@ -22,6 +23,7 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
|||
private final MutableLiveData<List<AlbumID3>> albumList = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
private int page = 0;
|
||||
private Status status = Status.STOPPED;
|
||||
|
||||
public AlbumCatalogueViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -31,7 +33,19 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
|||
return albumList;
|
||||
}
|
||||
|
||||
public void loadAlbums(int size) {
|
||||
public void loadAlbums() {
|
||||
page = 0;
|
||||
albumList.setValue(new ArrayList<>());
|
||||
albumList.setValue(new ArrayList<>());
|
||||
status = Status.RUNNING;
|
||||
loadAlbums(500);
|
||||
}
|
||||
|
||||
public void stopLoading() {
|
||||
status = Status.STOPPED;
|
||||
}
|
||||
|
||||
private void loadAlbums(int size) {
|
||||
retrieveAlbums(new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
|
|
@ -39,9 +53,11 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
|||
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
List<AlbumID3> liveAlbum = albumList.getValue();
|
||||
if (status == Status.STOPPED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (liveAlbum == null) liveAlbum = new ArrayList<>();
|
||||
List<AlbumID3> liveAlbum = albumList.getValue();
|
||||
|
||||
liveAlbum.addAll((List<AlbumID3>) media);
|
||||
albumList.setValue(liveAlbum);
|
||||
|
|
@ -73,4 +89,9 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private enum Status {
|
||||
RUNNING,
|
||||
STOPPED
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue