Search in sources :

Example 1 with HorizontalAlbumView

use of com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView in project Shuttle by timusus.

the class DetailFragment method refreshAdapterItems.

void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            boolean albumsAscending = getAlbumsAscending();
            boolean songsAscending = getSongsAscending();
            @SortManager.SongSort int songSort = getSongsSortOrder();
            @SortManager.AlbumSort int albumSort = getAlbumsSortOrder();
            Observable<List<Song>> observable = null;
            if (albumArtist != null) {
                observable = DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(song -> Stream.of(albumArtist.albums).anyMatch(album1 -> album1.id == song.albumId)).collect(Collectors.toList()));
            } else if (album != null) {
                observable = DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(song -> song.albumId == album.id).collect(Collectors.toList()));
            } else if (genre != null) {
                observable = genre.getSongsObservable(getContext());
            } else if (playlist != null) {
                observable = playlist.getSongsObservable(getContext());
            }
            subscriptions.add(observable.map(songs -> {
                songs = Stream.of(songs).filter(song -> {
                    if (albumArtist != null) {
                        return Stream.of(albumArtist.albums).anyMatch(album -> album.id == song.albumId);
                    } else if (album != null) {
                        return song.albumId == album.id;
                    }
                    return true;
                }).collect(Collectors.toList());
                List<Album> albums = Stream.of(Operators.songsToAlbums(songs)).collect(Collectors.toList());
                if (playlist != null && albumSort == SortManager.AlbumSort.DEFAULT) {
                    switch(playlist.type) {
                        case Playlist.Type.MOST_PLAYED:
                            Collections.sort(albums, (a, b) -> ComparisonUtils.compareInt(b.songPlayCount, a.songPlayCount));
                            break;
                        case Playlist.Type.RECENTLY_PLAYED:
                            Collections.sort(albums, (a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed));
                            break;
                        case Playlist.Type.RECENTLY_ADDED:
                            Collections.sort(albums, (a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded));
                            break;
                        case Playlist.Type.USER_CREATED:
                        case Playlist.Type.FAVORITES:
                        case Playlist.Type.PODCAST:
                            Collections.sort(albums, (a, b) -> ComparisonUtils.compare(a.name, b.name));
                            break;
                    }
                } else {
                    SortManager.getInstance().sortAlbums(albums, albumSort);
                    if (!albumsAscending) {
                        Collections.reverse(albums);
                    }
                }
                if (playlist == null || songSort != SortManager.SongSort.DETAIL_DEFAULT) {
                    SortManager.getInstance().sortSongs(songs, songSort);
                    if (!songsAscending) {
                        Collections.reverse(songs);
                    }
                }
                if (album == null) {
                    List<AdaptableItem> items = Stream.of(albums).map(album -> new HorizontalAlbumView(album, requestManager)).collect(Collectors.toList());
                    horizontalRecyclerView.setItems(items);
                }
                List<AdaptableItem> songViews = Stream.of(songs).map(song -> {
                    SongView songView = new SongView(song, multiSelector, requestManager);
                    songView.setShowAlbumArt(false);
                    songView.setEditable(canEdit());
                    songView.setShowTrackNumber(album != null && (songSort == SortManager.SongSort.DETAIL_DEFAULT || songSort == SortManager.SongSort.TRACK_NUMBER));
                    return songView;
                }).collect(Collectors.toList());
                if (album != null && album.numDiscs > 1 && (songSort == SortManager.SongSort.DETAIL_DEFAULT || songSort == SortManager.SongSort.TRACK_NUMBER)) {
                    int discNumber = 0;
                    int length = songViews.size();
                    for (int i = 0; i < length; i++) {
                        SongView songView = (SongView) songViews.get(i);
                        if (discNumber != songView.song.discNumber) {
                            discNumber = songView.song.discNumber;
                            songViews.add(i, new DiscNumberView(discNumber));
                        }
                    }
                }
                List<AdaptableItem> adaptableItems = new ArrayList<>();
                adaptableItems.add(headerItem);
                if (album == null) {
                    adaptableItems.add(horizontalRecyclerView);
                }
                adaptableItems.addAll(songViews);
                return adaptableItems;
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                if (adaptableItems.isEmpty()) {
                    adapter.setEmpty(new EmptyView(R.string.empty_songlist));
                } else {
                    if (sortChanged) {
                        adapter.items.clear();
                        adapter.items = adaptableItems;
                        adapter.notifyDataSetChanged();
                        recyclerView.smoothScrollToPosition(0);
                        sortChanged = false;
                    } else {
                        adapter.setItems(adaptableItems);
                    }
                }
                int numSongs = (int) Stream.of(adaptableItems).filter(value -> value instanceof SongView).count();
                int numAlbums = horizontalRecyclerView.getCount();
                if (lineTwo != null) {
                    if (albumArtist != null) {
                        lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, albumArtist.getNumSongs()));
                    } else if (album != null) {
                        lineTwo.setText(String.format("%s%s", album.getAlbumArtist().name, numSongs > 0 ? " | " + album.getNumSongsLabel() : ""));
                    } else if (genre != null) {
                        lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, numSongs));
                    } else if (playlist != null) {
                        lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, numSongs));
                    }
                }
                List<Album> albums = Stream.of(adaptableItems).filter(adaptableItem -> adaptableItem instanceof SongView).map(songView -> (Song) songView.getItem()).map(Song::getAlbum).distinct().collect(Collectors.toList());
                if (playlist != null || genre != null && !albums.isEmpty()) {
                    if (slideShowObservable != null && !slideShowObservable.isUnsubscribed()) {
                        slideShowObservable.unsubscribe();
                    }
                    slideShowObservable = Observable.interval(8, TimeUnit.SECONDS).onBackpressureDrop().startWith(0L).map(aLong -> {
                        if (albums.isEmpty() || aLong == 0L && currentSlideShowAlbum != null) {
                            return null;
                        }
                        return albums.get(new Random().nextInt(albums.size()));
                    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(nextSlideShowAlbum -> {
                        if (nextSlideShowAlbum != null && nextSlideShowAlbum != currentSlideShowAlbum) {
                            requestManager.load(nextSlideShowAlbum).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).error(GlideUtils.getPlaceHolderDrawable(nextSlideShowAlbum.name, true)).centerCrop().thumbnail(Glide.with(this).load(currentSlideShowAlbum).centerCrop()).animate(new AlwaysCrossFade(false)).into(headerImageView);
                            currentSlideShowAlbum = nextSlideShowAlbum;
                        }
                    });
                    subscriptions.add(slideShowObservable);
                }
            }));
        }
    });
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Random(java.util.Random) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) ColorStateList(android.content.res.ColorStateList) Song(com.simplecity.amp_library.model.Song) Priority(com.bumptech.glide.Priority) RequestManager(com.bumptech.glide.RequestManager) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) MediaStore(android.provider.MediaStore) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) DetailAdapter(com.simplecity.amp_library.ui.adapters.DetailAdapter) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) FloatingActionButton(android.support.design.widget.FloatingActionButton) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ObjectAnimator(android.animation.ObjectAnimator) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseAdaptableItem(com.simplecity.amp_library.ui.modelviews.BaseAdaptableItem) NonScrollImageButton(com.simplecity.amp_library.ui.views.NonScrollImageButton) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) TextView(android.widget.TextView) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) GlideUtils(com.simplecity.amp_library.glide.utils.GlideUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Intent(android.content.Intent) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Menu(android.view.Menu) AnimatorSet(android.animation.AnimatorSet) WeakReference(java.lang.ref.WeakReference) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) SharedElementCallback(android.support.v4.app.SharedElementCallback) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) OvershootInterpolator(android.view.animation.OvershootInterpolator) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) ViewTreeObserver(android.view.ViewTreeObserver) 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) ContentUris(android.content.ContentUris) SongView(com.simplecity.amp_library.ui.modelviews.SongView) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) Random(java.util.Random) ColorStateList(android.content.res.ColorStateList) List(java.util.List) ArrayList(java.util.ArrayList) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 2 with HorizontalAlbumView

use of com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView in project Shuttle by timusus.

the class BaseDetailFragment method getAlbumViewModels.

@NonNull
@Override
public List<ViewModel> getAlbumViewModels(List<Album> albums) {
    if (albums.isEmpty()) {
        return Collections.emptyList();
    }
    List<ViewModel> items = new ArrayList<>();
    if (setHorizontalItemsDisposable != null) {
        setHorizontalItemsDisposable.dispose();
    }
    setHorizontalItemsDisposable = horizontalRecyclerView.setItems(Stream.of(albums).map(album -> {
        HorizontalAlbumView horizontalAlbumView = new HorizontalAlbumView(album, requestManager);
        horizontalAlbumView.setClickListener(BaseDetailFragment.this);
        horizontalAlbumView.showYear(true);
        return horizontalAlbumView;
    }).collect(Collectors.toList()));
    items.add(new SubheaderView(StringUtils.makeAlbumsLabel(getContext(), albums.size())));
    items.add(horizontalRecyclerView);
    return items;
}
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) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) 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)

Aggregations

AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 ColorStateList (android.content.res.ColorStateList)2 Bundle (android.os.Bundle)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 SharedElementCallback (android.support.v4.app.SharedElementCallback)2 ViewCompat (android.support.v4.view.ViewCompat)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 PopupMenu (android.support.v7.widget.PopupMenu)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Transition (android.transition.Transition)2 LayoutInflater (android.view.LayoutInflater)2 MenuItem (android.view.MenuItem)2 SubMenu (android.view.SubMenu)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 Toast (android.widget.Toast)2 Collectors (com.annimon.stream.Collectors)2 Stream (com.annimon.stream.Stream)2