Search in sources :

Example 6 with SuggestedHeaderView

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();
        }
    });
}
Also used : R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SuggestedDividerDecoration(com.simplecity.amp_library.ui.views.SuggestedDividerDecoration) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Song(com.simplecity.amp_library.model.Song) Optional(com.annimon.stream.Optional) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) LogUtils(com.simplecity.amp_library.utils.LogUtils) Playlist(com.simplecity.amp_library.model.Playlist) PopupMenu(android.support.v7.widget.PopupMenu) ViewGroup(android.view.ViewGroup) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) Nullable(android.support.annotation.Nullable) Context(android.content.Context) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) ViewType(com.simplecity.amp_library.ui.adapters.ViewType) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader) Toast(android.widget.Toast) Observable(io.reactivex.Observable) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) PlaylistDetailFragment(com.simplecity.amp_library.ui.detail.PlaylistDetailFragment) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) ArrayList(java.util.ArrayList) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader)

Aggregations

SuggestedHeaderView (com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView)6 SuppressLint (android.annotation.SuppressLint)5 GridLayoutManager (android.support.v7.widget.GridLayoutManager)5 SuggestedHeader (com.simplecity.amp_library.model.SuggestedHeader)5 AlbumView (com.simplecity.amp_library.ui.modelviews.AlbumView)5 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)5 HorizontalRecyclerView (com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView)5 SuggestedSongView (com.simplecity.amp_library.ui.modelviews.SuggestedSongView)5 SuggestedDividerDecoration (com.simplecity.amp_library.ui.views.SuggestedDividerDecoration)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Context (android.content.Context)4 Bundle (android.os.Bundle)4 PopupMenu (android.support.v7.widget.PopupMenu)4 RecyclerView (android.support.v7.widget.RecyclerView)4 LayoutInflater (android.view.LayoutInflater)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 Toast (android.widget.Toast)4 Optional (com.annimon.stream.Optional)4