Search in sources :

Example 16 with AlbumArtist

use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.

the class AlbumArtistFragment method refreshAdapterItems.

void refreshAdapterItems(boolean force) {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            int artistDisplayType = SettingsManager.getInstance().getArtistDisplayType();
            boolean ascending = SortManager.getInstance().getArtistsAscending();
            disposable = DataManager.getInstance().getAlbumArtistsRelay().skipWhile(albumArtists -> !force && adapter.items.size() == albumArtists.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(albumArtists -> {
                // Sort
                SortManager.getInstance().sortAlbumArtists(albumArtists);
                // Reverse if required
                if (!ascending) {
                    Collections.reverse(albumArtists);
                }
                return Observable.fromIterable(albumArtists).map(albumArtist -> {
                    // Look for an existing AlbumArtistView wrapping the song, we'll reuse it if it exists.
                    AlbumArtistView albumArtistView = (AlbumArtistView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumArtistView && (((AlbumArtistView) viewModel).albumArtist.equals(albumArtist))).findFirst().orElse(null);
                    if (albumArtistView == null) {
                        albumArtistView = new AlbumArtistView(albumArtist, artistDisplayType, requestManager);
                        albumArtistView.setClickListener(this);
                    }
                    return (ViewModel) albumArtistView;
                }).toList();
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
                if (items.isEmpty()) {
                    adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_artists)));
                } else {
                    adapter.setItems(items);
                }
                // Move the RV back to the top if we've had a sort order change.
                if (sortOrderChanged) {
                    recyclerView.scrollToPosition(0);
                }
                sortOrderChanged = false;
            });
        }
    });
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) ViewType(com.simplecity.amp_library.ui.adapters.ViewType) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) RequestManager(com.bumptech.glide.RequestManager) MenuInflater(android.view.MenuInflater) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Menu(android.view.Menu) View(android.view.View) Observable(io.reactivex.Observable) SectionedAdapter(com.simplecity.amp_library.ui.adapters.SectionedAdapter) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) SortManager(com.simplecity.amp_library.utils.SortManager) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) Disposable(io.reactivex.disposables.Disposable) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Nullable(android.support.annotation.Nullable) SpanSizeLookup(com.simplecityapps.recycler_adapter.recyclerview.SpanSizeLookup) Collections(java.util.Collections) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 17 with AlbumArtist

use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.

the class PlayerFragment method goToArtist.

@SuppressLint("CheckResult")
private void goToArtist() {
    AlbumArtist currentAlbumArtist = MusicUtils.getAlbumArtist();
    // MusicUtils.getAlbumArtist() is only populate with the album the current Song belongs to.
    // Let's find the matching AlbumArtist in the DataManager.albumArtistRelay
    DataManager.getInstance().getAlbumArtistsRelay().first(Collections.emptyList()).flatMapObservable(Observable::fromIterable).filter(albumArtist -> currentAlbumArtist != null && albumArtist.name.equals(currentAlbumArtist.name) && albumArtist.albums.containsAll(currentAlbumArtist.albums)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(albumArtist -> navigationEventRelay.sendEvent(new NavigationEventRelay.NavigationEvent(NavigationEventRelay.NavigationEvent.Type.GO_TO_ARTIST, albumArtist, true)));
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) ImageView(android.widget.ImageView) SeekBarStopChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStopChangeEvent) FavoriteActionBarView(com.simplecity.amp_library.ui.views.FavoriteActionBarView) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) PaletteBitmapTranscoder(com.simplecity.amp_library.glide.palette.PaletteBitmapTranscoder) RepeatingImageButton(com.simplecity.amp_library.ui.views.RepeatingImageButton) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Schedulers(io.reactivex.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) ShuffleButton(com.simplecity.amp_library.ui.views.ShuffleButton) Unbinder(butterknife.Unbinder) Log(android.util.Log) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) LogUtils(com.simplecity.amp_library.utils.LogUtils) PlayPauseView(com.simplecity.amp_library.ui.views.PlayPauseView) SeekBarProgressChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarProgressChangeEvent) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) SnowfallView(com.simplecity.amp_library.ui.views.SnowfallView) SeekBarStartChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStartChangeEvent) Util(com.afollestad.aesthetic.Util) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BlurTransformation(com.jp.wasabeef.glide.transformations.BlurTransformation) Palette(android.support.v7.graphics.Palette) ButterKnife(butterknife.ButterKnife) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SuppressLint(android.annotation.SuppressLint) SeekBarChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarChangeEvent) Flowable(io.reactivex.Flowable) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Observable(io.reactivex.Observable) UnsafeConsumer(com.simplecity.amp_library.rx.UnsafeConsumer) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) BackpressureStrategy(io.reactivex.BackpressureStrategy) LayoutInflater(android.view.LayoutInflater) Target(com.bumptech.glide.request.target.Target) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) TextUtils(android.text.TextUtils) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) PlayerView(com.simplecity.amp_library.ui.views.PlayerView) PaletteBitmap(com.simplecity.amp_library.glide.palette.PaletteBitmap) Glide(com.bumptech.glide.Glide) MultiSheetSlideEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetSlideEventRelay) Toolbar(android.support.v7.widget.Toolbar) MusicService(com.simplecity.amp_library.playback.MusicService) PlayerPresenter(com.simplecity.amp_library.ui.presenters.PlayerPresenter) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) RepeatButton(com.simplecity.amp_library.ui.views.RepeatButton) Collections(java.util.Collections) RxSeekBar(com.jakewharton.rxbinding2.widget.RxSeekBar) ValueAnimator(android.animation.ValueAnimator) RxSharedPreferences(com.f2prateek.rx.preferences2.RxSharedPreferences) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Observable(io.reactivex.Observable) SuppressLint(android.annotation.SuppressLint)

Aggregations

AlbumArtist (com.simplecity.amp_library.model.AlbumArtist)17 Album (com.simplecity.amp_library.model.Album)13 Song (com.simplecity.amp_library.model.Song)10 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)10 Bundle (android.os.Bundle)9 PopupMenu (android.support.v7.widget.PopupMenu)9 View (android.view.View)9 R (com.simplecity.amp_library.R)9 DataManager (com.simplecity.amp_library.utils.DataManager)9 Collections (java.util.Collections)9 Stream (com.annimon.stream.Stream)8 Context (android.content.Context)7 LayoutInflater (android.view.LayoutInflater)7 MenuItem (android.view.MenuItem)7 SubMenu (android.view.SubMenu)7 ViewGroup (android.view.ViewGroup)7 Toast (android.widget.Toast)7 RequestManager (com.bumptech.glide.RequestManager)7 Playlist (com.simplecity.amp_library.model.Playlist)7 Menu (android.view.Menu)6