feat: added sorting by newest album added

This commit is contained in:
CappielloAntonio 2024-03-16 16:28:33 +01:00
parent 302458e76b
commit 2712b73dac
7 changed files with 47 additions and 0 deletions

View file

@ -161,6 +161,10 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
case Constants.ALBUM_ORDER_BY_RANDOM:
Collections.shuffle(albums);
break;
case Constants.ALBUM_ORDER_BY_RECENTLY_ADDED:
albums.sort(Comparator.comparing(AlbumID3::getCreated));
Collections.reverse(albums);
break;
}
notifyDataSetChanged();

View file

@ -67,6 +67,7 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
initAppBar();
initAlbumCatalogueView();
initProgressLoader();
return view;
}
@ -124,6 +125,18 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
bind.albumListSortImageView.setOnClickListener(view -> showPopupMenu(view, R.menu.sort_album_popup_menu));
}
private void initProgressLoader() {
albumCatalogueViewModel.getLoadingStatus().observe(getViewLifecycleOwner(), isLoading -> {
if (isLoading) {
bind.albumListSortImageView.setEnabled(false);
bind.albumListProgressLoader.setVisibility(View.VISIBLE);
} else {
bind.albumListSortImageView.setEnabled(true);
bind.albumListProgressLoader.setVisibility(View.GONE);
}
});
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.toolbar_menu, menu);
@ -171,6 +184,9 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
} else if (menuItem.getItemId() == R.id.menu_album_sort_random) {
albumAdapter.sort(Constants.ALBUM_ORDER_BY_RANDOM);
return true;
} else if (menuItem.getItemId() == R.id.menu_album_sort_recently_added) {
albumAdapter.sort(Constants.ALBUM_ORDER_BY_RECENTLY_ADDED);
return true;
}
return false;