Search in sources :

Example 6 with AlbumView

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

the class AlbumFragment method refreshAdapterItems.

void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
            boolean ascending = SortManager.getInstance().getAlbumsAscending();
            subscription = DataManager.getInstance().getAlbumsRelay().flatMap(albums -> {
                SortManager.getInstance().sortAlbums(albums);
                if (!ascending) {
                    Collections.reverse(albums);
                }
                return Observable.from(albums).map(album -> (AdaptableItem) new AlbumView(album, albumDisplayType, requestManager, multiSelector)).toList();
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
                if (items.isEmpty()) {
                    albumAdapter.setEmpty(new EmptyView(R.string.empty_albums));
                } else {
                    albumAdapter.setItems(items);
                }
                if (sortOrderChanged) {
                    recyclerView.scrollToPosition(0);
                }
                sortOrderChanged = false;
            });
        }
    });
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) 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) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) 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) Intent(android.content.Intent) MenuItem(android.view.MenuItem) Observable(rx.Observable) SuppressLint(android.annotation.SuppressLint) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) RecyclerView(android.support.v7.widget.RecyclerView) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) DataManager(com.simplecity.amp_library.utils.DataManager) Collections(java.util.Collections) AlbumAdapter(com.simplecity.amp_library.ui.adapters.AlbumAdapter) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) SuppressLint(android.annotation.SuppressLint)

Example 7 with AlbumView

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

the class AlbumAdapter method getSectionName.

@NonNull
@Override
public String getSectionName(int position) {
    if (!(items.get(position) instanceof AlbumView)) {
        return "";
    }
    int sortOrder = SortManager.getInstance().getAlbumsSortOrder();
    Album album = ((AlbumView) items.get(position)).album;
    String string = null;
    boolean requiresSubstring = true;
    switch(sortOrder) {
        case SortManager.AlbumSort.DEFAULT:
            string = StringUtils.keyFor(album.name);
            break;
        case SortManager.AlbumSort.NAME:
            string = album.name;
            break;
        case SortManager.AlbumSort.ARTIST_NAME:
            string = album.albumArtistName;
            break;
        case SortManager.AlbumSort.YEAR:
            string = String.valueOf(album.year);
            if (string.length() != 4) {
                string = "-";
            } else {
                string = string.substring(2, 4);
            }
            requiresSubstring = false;
            break;
    }
    if (requiresSubstring) {
        if (!TextUtils.isEmpty(string)) {
            string = string.substring(0, 1).toUpperCase();
        } else {
            string = " ";
        }
    }
    return string;
}
Also used : AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) Album(com.simplecity.amp_library.model.Album) NonNull(android.support.annotation.NonNull)

Example 8 with AlbumView

use of com.simplecity.amp_library.ui.modelviews.AlbumView 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)

Aggregations

AlbumView (com.simplecity.amp_library.ui.modelviews.AlbumView)8 Album (com.simplecity.amp_library.model.Album)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 Bundle (android.os.Bundle)6 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 PopupMenu (android.support.v7.widget.PopupMenu)6 View (android.view.View)6 Stream (com.annimon.stream.Stream)6 RequestManager (com.bumptech.glide.RequestManager)6 R (com.simplecity.amp_library.R)6 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)6 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)6 Collections (java.util.Collections)6 RecyclerView (android.support.v7.widget.RecyclerView)5 LayoutInflater (android.view.LayoutInflater)5 ViewGroup (android.view.ViewGroup)5 Toast (android.widget.Toast)5 Playlist (com.simplecity.amp_library.model.Playlist)5 Song (com.simplecity.amp_library.model.Song)5