use of com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView 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