use of com.simplecity.amp_library.ui.modelviews.AlbumView in project Shuttle by timusus.
the class AlbumFragment method refreshAdapterItems.
void refreshAdapterItems() {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
boolean ascending = SortManager.getInstance().getAlbumsAscending();
subscription = DataManager.getInstance().getAlbumsRelay().flatMap(albums -> {
SortManager.getInstance().sortAlbums(albums);
if (!ascending) {
Collections.reverse(albums);
}
return Observable.from(albums).map(album -> (AdaptableItem) new AlbumView(album, albumDisplayType, requestManager, multiSelector)).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
albumAdapter.setEmpty(new EmptyView(R.string.empty_albums));
} else {
albumAdapter.setItems(items);
}
if (sortOrderChanged) {
recyclerView.scrollToPosition(0);
}
sortOrderChanged = false;
});
}
});
}
use of com.simplecity.amp_library.ui.modelviews.AlbumView in project Shuttle by timusus.
the class AlbumAdapter method getSectionName.
@NonNull
@Override
public String getSectionName(int position) {
if (!(items.get(position) instanceof AlbumView)) {
return "";
}
int sortOrder = SortManager.getInstance().getAlbumsSortOrder();
Album album = ((AlbumView) items.get(position)).album;
String string = null;
boolean requiresSubstring = true;
switch(sortOrder) {
case SortManager.AlbumSort.DEFAULT:
string = StringUtils.keyFor(album.name);
break;
case SortManager.AlbumSort.NAME:
string = album.name;
break;
case SortManager.AlbumSort.ARTIST_NAME:
string = album.albumArtistName;
break;
case SortManager.AlbumSort.YEAR:
string = String.valueOf(album.year);
if (string.length() != 4) {
string = "-";
} else {
string = string.substring(2, 4);
}
requiresSubstring = false;
break;
}
if (requiresSubstring) {
if (!TextUtils.isEmpty(string)) {
string = string.substring(0, 1).toUpperCase();
} else {
string = " ";
}
}
return string;
}
use of com.simplecity.amp_library.ui.modelviews.AlbumView in project Shuttle by timusus.
the class SuggestedFragment method getRecentlyPlayedViewModels.
Observable<List<ViewModel>> getRecentlyPlayedViewModels() {
return Playlist.recentlyPlayedPlaylist.getSongsObservable().flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMapSingle(albums -> Observable.fromIterable(albums).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).flatMapSingle(album -> album.getSongsSingle().map(songs -> {
album.numSongs = songs.size();
return album;
}).filter(a -> a.numSongs > 0).toSingle()).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).take(6).toList()).map(albums -> {
if (!albums.isEmpty()) {
List<ViewModel> viewModels = new ArrayList<>();
SuggestedHeader recentlyPlayedHeader = new SuggestedHeader(getString(R.string.suggested_recent_title), getString(R.string.suggested_recent_subtitle), Playlist.recentlyPlayedPlaylist);
SuggestedHeaderView recentlyPlayedHeaderView = new SuggestedHeaderView(recentlyPlayedHeader);
recentlyPlayedHeaderView.setClickListener(this);
viewModels.add(recentlyPlayedHeaderView);
viewModels.addAll(Stream.of(albums).map(album -> {
AlbumView albumView = new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager);
albumView.setClickListener(this);
return albumView;
}).toList());
return viewModels;
} else {
return Collections.emptyList();
}
});
}
Aggregations