use of com.simplecity.amp_library.ui.modelviews.EmptyView in project Shuttle by timusus.
the class AlbumArtistFragment method refreshAdapterItems.
void refreshAdapterItems(boolean force) {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
int artistDisplayType = SettingsManager.getInstance().getArtistDisplayType();
boolean ascending = SortManager.getInstance().getArtistsAscending();
disposable = DataManager.getInstance().getAlbumArtistsRelay().skipWhile(albumArtists -> !force && adapter.items.size() == albumArtists.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(albumArtists -> {
// Sort
SortManager.getInstance().sortAlbumArtists(albumArtists);
// Reverse if required
if (!ascending) {
Collections.reverse(albumArtists);
}
return Observable.fromIterable(albumArtists).map(albumArtist -> {
// Look for an existing AlbumArtistView wrapping the song, we'll reuse it if it exists.
AlbumArtistView albumArtistView = (AlbumArtistView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumArtistView && (((AlbumArtistView) viewModel).albumArtist.equals(albumArtist))).findFirst().orElse(null);
if (albumArtistView == null) {
albumArtistView = new AlbumArtistView(albumArtist, artistDisplayType, requestManager);
albumArtistView.setClickListener(this);
}
return (ViewModel) albumArtistView;
}).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_artists)));
} else {
adapter.setItems(items);
}
// Move the RV back to the top if we've had a sort order change.
if (sortOrderChanged) {
recyclerView.scrollToPosition(0);
}
sortOrderChanged = false;
});
}
});
}
use of com.simplecity.amp_library.ui.modelviews.EmptyView in project Shuttle by timusus.
the class SongFragment method refreshAdapterItems.
void refreshAdapterItems(boolean force) {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
boolean ascending = SortManager.getInstance().getSongsAscending();
disposable = DataManager.getInstance().getSongsRelay().skipWhile(songs -> !force && Stream.of(adapter.items).filter(viewModel -> viewModel instanceof SongView).count() == songs.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(songs -> {
// Sort
SortManager.getInstance().sortSongs(songs);
// Reverse if required
if (!ascending) {
Collections.reverse(songs);
}
return Observable.fromIterable(songs).map(song -> {
// Look for an existing SongView wrapping the song, we'll reuse it if it exists.
SongView songView = (SongView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof SongView && (((SongView) viewModel).song.equals(song))).findFirst().orElse(null);
if (songView == null) {
songView = new SongView(song, null);
songView.setClickListener(this);
}
return (ViewModel) songView;
}).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_songlist)));
} else {
items.add(0, shuffleView);
adapter.setItems(items);
}
// Move the RV back to the top if we've had a sort order change.
if (sortOrderChanged) {
recyclerView.scrollToPosition(0);
}
sortOrderChanged = false;
}, error -> LogUtils.logException(TAG, "Error refreshing adapter items", error));
}
});
}
Aggregations