Skip to content

Commit

Permalink
only refresh the data if really needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ramack committed Oct 17, 2019
1 parent 1112f23 commit 548ae98
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/src/main/java/org/piwigo/ui/main/AlbumsViewModel.java
Expand Up @@ -84,9 +84,7 @@ public Integer getCategory() {
return category;
}

void loadAlbums(Integer categoryId) {
category = categoryId;

private void forcedLoadAlbums(){
Account account = userManager.getActiveAccount().getValue();
if (albumsSubscription != null) {
// cleanup, just in case
Expand All @@ -99,16 +97,23 @@ void loadAlbums(Integer categoryId) {
photosSubscription = null;
}
if (account != null) {
albumsSubscription = categoriesRepository.getCategories(account, categoryId)
albumsSubscription = categoriesRepository.getCategories(account, category)
.subscribe(new CategoriesSubscriber());
photosSubscription = imageRepository.getImages(account, categoryId)
photosSubscription = imageRepository.getImages(account, category)
.subscribe(new ImagesSubscriber());
}
}

void loadAlbums(Integer categoryId) {
if(category == null || category != category) {
category = categoryId;
forcedLoadAlbums();
}
}

public void onRefresh() {
isLoading.set(true);
loadAlbums(getCategory());
forcedLoadAlbums();
}

private class CategoriesSubscriber extends Subscriber<List<Category>> {
Expand Down

0 comments on commit 548ae98

Please sign in to comment.