Search in sources :

Example 21 with ViewModel

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();
        }
    });
}
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) ArrayList(java.util.ArrayList) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader)

Example 22 with ViewModel

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();
        }
    });
}
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)

Example 23 with ViewModel

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;
}
Also used : R(com.simplecity.amp_library.R) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) Context(android.content.Context) Bundle(android.os.Bundle) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) SongView(com.simplecity.amp_library.ui.modelviews.SongView) ArtworkDialog(com.simplecity.amp_library.utils.ArtworkDialog) SortManager(com.simplecity.amp_library.utils.SortManager) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) NonNull(android.support.annotation.NonNull) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) Drawable(android.graphics.drawable.Drawable) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) Single(io.reactivex.Single) Song(com.simplecity.amp_library.model.Song) List(java.util.List) Toolbar(android.support.v7.widget.Toolbar) BiographyDialog(com.simplecity.amp_library.ui.dialog.BiographyDialog) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) SongView(com.simplecity.amp_library.ui.modelviews.SongView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) NonNull(android.support.annotation.NonNull)

Example 24 with ViewModel

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;
}
Also used : SongView(com.simplecity.amp_library.ui.modelviews.SongView) SubheaderView(com.simplecity.amp_library.ui.modelviews.SubheaderView) ArrayList(java.util.ArrayList) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) NonNull(android.support.annotation.NonNull)

Example 25 with ViewModel

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();
            }
        };
    }
}
Also used : R(com.simplecity.amp_library.R) CompletionListUpdateCallbackAdapter(com.simplecityapps.recycler_adapter.adapter.CompletionListUpdateCallbackAdapter) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ImageView(android.widget.ImageView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) Random(java.util.Random) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) OnClick(butterknife.OnClick) BindView(butterknife.BindView) ColorStateList(android.content.res.ColorStateList) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) Optional(com.annimon.stream.Optional) Priority(com.bumptech.glide.Priority) RequestManager(com.bumptech.glide.RequestManager) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) Schedulers(io.reactivex.schedulers.Schedulers) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) Unbinder(butterknife.Unbinder) ActionBarUtils(com.simplecity.amp_library.utils.ActionBarUtils) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) FloatingActionButton(android.support.design.widget.FloatingActionButton) SortManager(com.simplecity.amp_library.utils.SortManager) ObjectAnimator(android.animation.ObjectAnimator) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) ViewGroup(android.view.ViewGroup) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ContextualToolbarHost(com.simplecity.amp_library.ui.views.ContextualToolbarHost) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Album(com.simplecity.amp_library.model.Album) TypefaceManager(com.simplecity.amp_library.utils.TypefaceManager) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ButterKnife(butterknife.ButterKnife) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) DrawerLockManager(com.simplecity.amp_library.ui.drawer.DrawerLockManager) TransitionListenerAdapter(com.simplecity.amp_library.ui.fragments.TransitionListenerAdapter) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) NonNull(android.support.annotation.NonNull) StringUtils(com.simplecity.amp_library.utils.StringUtils) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) AnimationUtils(android.view.animation.AnimationUtils) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) AnimatorSet(android.animation.AnimatorSet) Observable(io.reactivex.Observable) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) SharedElementCallback(android.support.v4.app.SharedElementCallback) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) SubheaderView(com.simplecity.amp_library.ui.modelviews.SubheaderView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) CustomCollapsingToolbarLayout(android.support.design.widget.CustomCollapsingToolbarLayout) Glide(com.bumptech.glide.Glide) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TransitionInflater(android.transition.TransitionInflater) BaseFragment(com.simplecity.amp_library.ui.fragments.BaseFragment) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) Song(com.simplecity.amp_library.model.Song) SharedElementCallback(android.support.v4.app.SharedElementCallback) Single(io.reactivex.Single) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) SubMenu(android.view.SubMenu) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar)

Aggregations

ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)28 Stream (com.annimon.stream.Stream)18 R (com.simplecity.amp_library.R)18 List (java.util.List)18 Nullable (android.support.annotation.Nullable)17 View (android.view.View)17 Bundle (android.os.Bundle)16 LayoutInflater (android.view.LayoutInflater)16 MenuUtils (com.simplecity.amp_library.utils.MenuUtils)16 RecyclerListener (com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener)16 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)16 ViewGroup (android.view.ViewGroup)15 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)15 Disposable (io.reactivex.disposables.Disposable)15 PopupMenu (android.support.v7.widget.PopupMenu)14 UpgradeDialog (com.simplecity.amp_library.ui.dialog.UpgradeDialog)14 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)14 Observable (io.reactivex.Observable)14 Collections (java.util.Collections)14 TimeUnit (java.util.concurrent.TimeUnit)14