Search in sources :

Example 1 with ShuffleView

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

the class AlbumFragment method onCreateView.

@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (recyclerView == null) {
        int spanCount = SettingsManager.getInstance().getAlbumColumnCount(getResources());
        layoutManager = new GridLayoutManager(getContext(), spanCount);
        spanSizeLookup = new SpanSizeLookup(adapter, spanCount);
        spanSizeLookup.setSpanIndexCacheEnabled(true);
        layoutManager.setSpanSizeLookup(spanSizeLookup);
        recyclerView = (FastScrollRecyclerView) inflater.inflate(R.layout.fragment_recycler, container, false);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new GridDividerDecoration(getResources(), 4, true));
        recyclerView.setRecyclerListener(new RecyclerListener());
    }
    if (recyclerView.getAdapter() != adapter) {
        recyclerView.setAdapter(adapter);
    }
    shuffleView = new ShuffleView();
    shuffleView.setTitleResId(R.string.shuffle_albums);
    shuffleView.setClickListener(this);
    return recyclerView;
}
Also used : SpanSizeLookup(com.simplecityapps.recycler_adapter.recyclerview.SpanSizeLookup) GridLayoutManager(android.support.v7.widget.GridLayoutManager) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ShuffleView(com.simplecity.amp_library.ui.modelviews.ShuffleView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 2 with ShuffleView

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

the class AlbumFragment method refreshAdapterItems.

void refreshAdapterItems(boolean force) {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
            boolean ascending = SortManager.getInstance().getAlbumsAscending();
            subscription = DataManager.getInstance().getAlbumsRelay().skipWhile(albums -> !force && Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumView).count() == albums.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(albums -> {
                // Sort
                SortManager.getInstance().sortAlbums(albums);
                // Reverse if required
                if (!ascending) {
                    Collections.reverse(albums);
                }
                return Observable.fromIterable(albums).map(album -> {
                    // Look for an existing AlbumView wrapping the album, we'll reuse it if it exists.
                    AlbumView albumView = (AlbumView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumView && (((AlbumView) viewModel).album.equals(album))).findFirst().orElse(null);
                    if (albumView == null) {
                        albumView = new AlbumView(album, albumDisplayType, requestManager);
                        albumView.setClickListener(this);
                    }
                    return (ViewModel) albumView;
                }).toList();
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
                if (items.isEmpty()) {
                    adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_albums)));
                } else {
                    items.add(0, shuffleView);
                    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;
            }, error -> LogUtils.logException(TAG, "Error refreshing adapter items", error));
        }
    });
}
Also used : R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) SectionedAdapter(com.simplecity.amp_library.ui.adapters.SectionedAdapter) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) SortManager(com.simplecity.amp_library.utils.SortManager) 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) 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) SpanSizeLookup(com.simplecityapps.recycler_adapter.recyclerview.SpanSizeLookup) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ShuffleView(com.simplecity.amp_library.ui.modelviews.ShuffleView) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewType(com.simplecity.amp_library.ui.adapters.ViewType) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) Observable(io.reactivex.Observable) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) DataManager(com.simplecity.amp_library.utils.DataManager) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) SuppressLint(android.annotation.SuppressLint)

Example 3 with ShuffleView

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

the class SongFragment method onCreate.

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setHasOptionsMenu(true);
    adapter = new SectionedAdapter();
    shuffleView = new ShuffleView();
    shuffleView.setClickListener(this);
}
Also used : SectionedAdapter(com.simplecity.amp_library.ui.adapters.SectionedAdapter) ShuffleView(com.simplecity.amp_library.ui.modelviews.ShuffleView)

Example 4 with ShuffleView

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

the class SongFragment method refreshAdapterItems.

void refreshAdapterItems(boolean force) {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            boolean ascending = SortManager.getInstance().getSongsAscending();
            disposable = DataManager.getInstance().getSongsRelay().skipWhile(songs -> !force && Stream.of(adapter.items).filter(viewModel -> viewModel instanceof SongView).count() == songs.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(songs -> {
                // Sort
                SortManager.getInstance().sortSongs(songs);
                // Reverse if required
                if (!ascending) {
                    Collections.reverse(songs);
                }
                return Observable.fromIterable(songs).map(song -> {
                    // Look for an existing SongView wrapping the song, we'll reuse it if it exists.
                    SongView songView = (SongView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof SongView && (((SongView) viewModel).song.equals(song))).findFirst().orElse(null);
                    if (songView == null) {
                        songView = new SongView(song, null);
                        songView.setClickListener(this);
                    }
                    return (ViewModel) songView;
                }).toList();
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
                if (items.isEmpty()) {
                    adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_songlist)));
                } else {
                    items.add(0, shuffleView);
                    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;
            }, error -> LogUtils.logException(TAG, "Error refreshing adapter items", error));
        }
    });
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) ShuffleView(com.simplecity.amp_library.ui.modelviews.ShuffleView) SongView(com.simplecity.amp_library.ui.modelviews.SongView) 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) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) Song(com.simplecity.amp_library.model.Song) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) 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) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) SortManager(com.simplecity.amp_library.utils.SortManager) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) DataManager(com.simplecity.amp_library.utils.DataManager) Nullable(android.support.annotation.Nullable) Collections(java.util.Collections) SongView(com.simplecity.amp_library.ui.modelviews.SongView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Aggregations

ShuffleView (com.simplecity.amp_library.ui.modelviews.ShuffleView)4 SectionedAdapter (com.simplecity.amp_library.ui.adapters.SectionedAdapter)3 RecyclerListener (com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener)3 SuppressLint (android.annotation.SuppressLint)2 Bundle (android.os.Bundle)2 Nullable (android.support.annotation.Nullable)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 PopupMenu (android.support.v7.widget.PopupMenu)2 LayoutInflater (android.view.LayoutInflater)2 Menu (android.view.Menu)2 MenuInflater (android.view.MenuInflater)2 MenuItem (android.view.MenuItem)2 SubMenu (android.view.SubMenu)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Toast (android.widget.Toast)2 Stream (com.annimon.stream.Stream)2 R (com.simplecity.amp_library.R)2 UpgradeDialog (com.simplecity.amp_library.ui.dialog.UpgradeDialog)2 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)2