use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.
the class SuggestedFragment method getMostPlayedViewModels.
Observable<List<ViewModel>> getMostPlayedViewModels() {
return Playlist.mostPlayedPlaylist.getSongsObservable().map(songs -> {
if (!songs.isEmpty()) {
List<ViewModel> viewModels = new ArrayList<>();
SuggestedHeader mostPlayedHeader = new SuggestedHeader(getString(R.string.mostplayed), getString(R.string.suggested_most_played_songs_subtitle), Playlist.mostPlayedPlaylist);
SuggestedHeaderView mostPlayedHeaderView = new SuggestedHeaderView(mostPlayedHeader);
mostPlayedHeaderView.setClickListener(this);
viewModels.add(mostPlayedHeaderView);
viewModels.add(mostPlayedRecyclerView);
Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(b.playCount, a.playCount));
SongClickListener songClickListener = new SongClickListener(songs);
mostPlayedRecyclerView.viewModelAdapter.setItems(Stream.of(songs).map(song -> {
SuggestedSongView suggestedSongView = new SuggestedSongView(song, requestManager);
suggestedSongView.setClickListener(songClickListener);
return (ViewModel) suggestedSongView;
}).limit(20).toList());
return viewModels;
} else {
return Collections.emptyList();
}
});
}
use of com.simplecityapps.recycler_adapter.model.ViewModel 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();
}
});
}
use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.
the class AlbumDetailFragment method getSongViewModels.
@NonNull
@Override
public List<ViewModel> getSongViewModels(List<Song> songs) {
int songSortOrder = getSongSortOrder();
List<ViewModel> songViewModels = super.getSongViewModels(songs);
Stream.of(songViewModels).filter(viewModel -> viewModel instanceof SongView).forEach(viewModel -> {
((SongView) viewModel).showArtistName(false);
((SongView) viewModel).showAlbumName(false);
((SongView) viewModel).setShowTrackNumber(songSortOrder == SortManager.SongSort.TRACK_NUMBER || songSortOrder == SortManager.SongSort.DETAIL_DEFAULT);
});
if (album.numDiscs > 1 && (songSortOrder == SortManager.SongSort.DETAIL_DEFAULT || songSortOrder == SortManager.SongSort.TRACK_NUMBER)) {
int discNumber = 0;
int length = songViewModels.size();
for (int i = 0; i < length; i++) {
ViewModel viewModel = songViewModels.get(i);
if (viewModel instanceof SongView) {
if (discNumber != ((SongView) viewModel).song.discNumber) {
discNumber = ((SongView) viewModel).song.discNumber;
songViewModels.add(i, new DiscNumberView(discNumber));
}
}
}
}
return songViewModels;
}
use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.
the class BaseDetailFragment method getSongViewModels.
@NonNull
@Override
public List<ViewModel> getSongViewModels(List<Song> songs) {
List<ViewModel> items = new ArrayList<>();
items.add(new SubheaderView(StringUtils.makeSongsLabel(getContext(), songs.size())));
items.addAll(Stream.of(songs).map(song -> {
SongView songView = new SongView(song, requestManager);
songView.setClickListener(BaseDetailFragment.this);
return songView;
}).toList());
return items;
}
use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.
the class BaseDetailFragment method setupContextualToolbar.
private void setupContextualToolbar() {
ContextualToolbar contextualToolbar = ContextualToolbar.findContextualToolbar(this);
if (contextualToolbar != null) {
contextualToolbar.setTransparentBackground(true);
contextualToolbar.getMenu().clear();
contextualToolbar.inflateMenu(R.menu.context_menu_general);
SubMenu sub = contextualToolbar.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
disposables.add(PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe());
contextualToolbar.setOnMenuItemClickListener(MenuUtils.getSongMenuClickListener(getContext(), Single.defer(() -> Operators.reduceSongSingles(contextualToolbarHelper.getItems())), deleteDialog -> deleteDialog.show(getChildFragmentManager()), () -> contextualToolbarHelper.finish()));
contextualToolbarHelper = new ContextualToolbarHelper<Single<List<Song>>>(contextualToolbar, new ContextualToolbarHelper.Callback() {
@Override
public void notifyItemChanged(int position, SelectableViewModel viewModel) {
if (adapter.items.contains(viewModel)) {
adapter.notifyItemChanged(position, 0);
} else if (horizontalRecyclerView.viewModelAdapter.items.contains(viewModel)) {
horizontalRecyclerView.viewModelAdapter.notifyItemChanged(position);
}
}
@Override
public void notifyDatasetChanged() {
adapter.notifyItemRangeChanged(0, adapter.items.size(), 0);
horizontalRecyclerView.viewModelAdapter.notifyItemRangeChanged(0, horizontalRecyclerView.viewModelAdapter.items.size(), 0);
}
}) {
@Override
public void start() {
super.start();
// Need to hide the collapsed text, as it overlaps the contextual toolbar
collapsingToolbarTextColor = toolbarLayout.getCollapsedTitleTextColor();
collapsingToolbarSubTextColor = toolbarLayout.getCollapsedSubTextColor();
toolbarLayout.setCollapsedTitleTextColor(0x01FFFFFF);
toolbarLayout.setCollapsedSubTextColor(0x01FFFFFF);
toolbar.setVisibility(View.GONE);
}
@Override
public void finish() {
if (toolbarLayout != null) {
toolbarLayout.setCollapsedTitleTextColor(collapsingToolbarTextColor);
toolbarLayout.setCollapsedSubTextColor(collapsingToolbarSubTextColor);
}
if (toolbar != null) {
toolbar.setVisibility(View.VISIBLE);
}
super.finish();
}
};
}
}
Aggregations