Search in sources :

Example 11 with Song

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

the class DetailFragment method onActionItemClicked.

boolean onActionItemClicked(MenuItem item) {
    final ArrayList<Song> checkedSongs = getCheckedSongs();
    if (checkedSongs == null || checkedSongs.isEmpty()) {
        return true;
    }
    switch(item.getItemId()) {
        case NEW_PLAYLIST:
            PlaylistUtils.createPlaylistDialog(getActivity(), checkedSongs);
            return true;
        case PLAYLIST_SELECTED:
            Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
            PlaylistUtils.addToPlaylist(getContext(), playlist, checkedSongs);
            return true;
        case R.id.delete:
            new DialogUtils.DeleteDialogBuilder().context(getContext()).singleMessageId(R.string.delete_song_desc).multipleMessage(R.string.delete_song_desc_multiple).itemNames(Stream.of(checkedSongs).map(song -> song.name).collect(Collectors.toList())).songsToDelete(Observable.just(checkedSongs)).build().show();
            return true;
        case R.id.menu_add_to_queue:
            MusicUtils.addToQueue(getActivity(), checkedSongs);
            return true;
    }
    return false;
}
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) Song(com.simplecity.amp_library.model.Song) Playlist(com.simplecity.amp_library.model.Playlist) DialogUtils(com.simplecity.amp_library.utils.DialogUtils)

Example 12 with Song

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

the class SearchActivity method onOverflowClick.

@Override
public void onOverflowClick(View v, int position, Object object) {
    PopupMenu menu = new PopupMenu(this, v);
    if (object instanceof AlbumArtist) {
        menu.getMenu().add(0, PLAY_SELECTION, 0, R.string.play_selection);
    } else if (object instanceof Album) {
        menu.getMenu().add(0, PLAY_SELECTION, 0, R.string.play_selection);
    } else if (object instanceof Song) {
        menu.getMenu().add(0, PLAY_NEXT, 0, R.string.play_next);
        menu.getMenu().add(0, USE_AS_RINGTONE, 4, R.string.ringtone_menu);
    }
    SubMenu sub = menu.getMenu().addSubMenu(0, ADD_TO_PLAYLIST, 1, R.string.add_to_playlist);
    PlaylistUtils.makePlaylistMenu(this, sub, 0);
    menu.getMenu().add(0, QUEUE, 2, R.string.add_to_queue);
    if (ShuttleUtils.isUpgraded()) {
        menu.getMenu().add(0, TAGGER, 3, R.string.edit_tags);
    }
    menu.getMenu().add(0, DELETE_ITEM, 6, R.string.delete_item);
    menu.setOnMenuItemClickListener(item -> {
        Observable<List<Song>> songsObservable = null;
        if (object instanceof Song) {
            songsObservable = Observable.just(Collections.singletonList((Song) object));
        } else if (object instanceof AlbumArtist) {
            songsObservable = ((AlbumArtist) object).getSongsObservable();
        } else if (object instanceof Album) {
            songsObservable = ((Album) object).getSongsObservable();
        }
        switch(item.getItemId()) {
            case PLAY_SELECTION:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playAll(songs, () -> {
                    final String message = getString(R.string.emptyplaylist);
                    Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
                }));
                return true;
            case PLAY_NEXT:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playNext(SearchActivity.this, songs));
                return true;
            case NEW_PLAYLIST:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> PlaylistUtils.createPlaylistDialog(SearchActivity.this, songs));
                return true;
            case PLAYLIST_SELECTED:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
                    Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
                    PlaylistUtils.addToPlaylist(this, playlist, songs);
                });
                return true;
            case USE_AS_RINGTONE:
                ShuttleUtils.setRingtone(SearchActivity.this, ((Song) object));
                return true;
            case QUEUE:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.addToQueue(SearchActivity.this, songs));
                return true;
            case TAGGER:
                TaggerDialog.newInstance((Serializable) object).show(getSupportFragmentManager());
                return true;
            case DELETE_ITEM:
                DialogUtils.DeleteDialogBuilder builder = new DialogUtils.DeleteDialogBuilder().context(this).songsToDelete(songsObservable);
                if (object instanceof Song) {
                    builder.singleMessageId(R.string.delete_song_desc).multipleMessage(R.string.delete_song_desc_multiple).itemNames(Collections.singletonList(((Song) object).name));
                } else if (object instanceof AlbumArtist) {
                    builder.singleMessageId(R.string.delete_album_artist_desc).multipleMessage(R.string.delete_album_artist_desc_multiple).itemNames(Collections.singletonList(((AlbumArtist) object).name));
                } else if (object instanceof Album) {
                    builder.singleMessageId(R.string.delete_album_desc).multipleMessage(R.string.delete_album_desc_multiple).itemNames(Collections.singletonList(((Album) object).name));
                }
                builder.build().show();
                return true;
        }
        return false;
    });
    menu.show();
}
Also used : Serializable(java.io.Serializable) Album(com.simplecity.amp_library.model.Album) SubMenu(android.view.SubMenu) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) Song(com.simplecity.amp_library.model.Song) Playlist(com.simplecity.amp_library.model.Playlist) List(java.util.List) ArrayList(java.util.ArrayList) PopupMenu(android.support.v7.widget.PopupMenu)

Example 13 with Song

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

the class SuggestedFragment method refreshAdapterItems.

void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            subscription = new CompositeSubscription();
            Observable<Playlist> mostPlayedPlaylistObservable = Observable.fromCallable(Playlist::mostPlayedPlaylist).subscribeOn(Schedulers.io()).cache();
            Observable<List<Song>> mostPlayedSongsObservable = mostPlayedPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
            Observable<List<AdaptableItem>> mostPlayedItemsObservable = mostPlayedPlaylistObservable.flatMap(playlist -> {
                SuggestedHeader mostPlayedHeader = new SuggestedHeader(getString(R.string.mostplayed), getString(R.string.suggested_most_played_songs_subtitle), playlist);
                SuggestedHeaderView mostPlayedHeaderView = new SuggestedHeaderView(mostPlayedHeader);
                return mostPlayedSongsObservable.map(songs -> {
                    List<AdaptableItem> items = new ArrayList<>();
                    if (!songs.isEmpty()) {
                        items.add(mostPlayedHeaderView);
                        items.add(mostPlayedRecyclerView);
                    }
                    return items;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<List<AdaptableItem>> recentlyPlayedAlbums = Observable.fromCallable(Playlist::recentlyPlayedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
                SuggestedHeader recentlyPlayedHeader = new SuggestedHeader(getString(R.string.suggested_recent_title), getString(R.string.suggested_recent_subtitle), playlist);
                SuggestedHeaderView recentlyPlayedHeaderView = new SuggestedHeaderView(recentlyPlayedHeader);
                return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).limit(6).flatMap(album -> album.getSongsObservable().map(songs -> {
                    album.numSongs = songs.size();
                    return album;
                })).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
                    if (!adaptableItems.isEmpty()) {
                        adaptableItems.add(0, recentlyPlayedHeaderView);
                    }
                    return adaptableItems;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<Playlist> favouritesPlaylistObservable = Observable.fromCallable(Playlist::favoritesPlaylist).subscribeOn(Schedulers.io()).cache();
            Observable<List<Song>> favouritesSongsObservable = favouritesPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
            Observable<List<AdaptableItem>> favoriteSongsItemsObservable = favouritesPlaylistObservable.flatMap(playlist -> {
                SuggestedHeader favoriteHeader = new SuggestedHeader(getString(R.string.fav_title), getString(R.string.suggested_favorite_subtitle), playlist);
                SuggestedHeaderView favoriteHeaderView = new SuggestedHeaderView(favoriteHeader);
                return favouritesSongsObservable.map(songs -> {
                    List<AdaptableItem> items = new ArrayList<>();
                    if (!songs.isEmpty()) {
                        items.add(favoriteHeaderView);
                        items.add(favoriteRecyclerView);
                    }
                    return items;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<List<AdaptableItem>> recentlyAddedAlbums = Observable.fromCallable(Playlist::recentlyAddedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
                SuggestedHeader recentlyAddedHeader = new SuggestedHeader(getString(R.string.recentlyadded), getString(R.string.suggested_recently_added_subtitle), playlist);
                SuggestedHeaderView recentlyAddedHeaderView = new SuggestedHeaderView(recentlyAddedHeader);
                return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).limit(4).flatMap(album -> album.getSongsObservable().map(songs -> {
                    album.numSongs = songs.size();
                    return album;
                })).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
                    if (!adaptableItems.isEmpty()) {
                        adaptableItems.add(0, recentlyAddedHeaderView);
                    }
                    return adaptableItems;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable.merge(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums);
            subscription.add(Observable.combineLatest(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums, (mostPlayedSongs1, recentlyPlayedAlbums1, favoriteSongs1, recentlyAddedAlbums1) -> {
                List<AdaptableItem> items = new ArrayList<>();
                items.addAll(mostPlayedSongs1);
                items.addAll(recentlyPlayedAlbums1);
                items.addAll(favoriteSongs1);
                items.addAll(recentlyAddedAlbums1);
                return items;
            }).debounce(250, TimeUnit.MILLISECONDS).switchIfEmpty(Observable.just(new ArrayList<>())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                if (adaptableItems.isEmpty()) {
                    suggestedAdapter.setEmpty(new EmptyView(R.string.empty_suggested));
                } else {
                    suggestedAdapter.setItems(adaptableItems);
                }
            }));
            subscription.add(mostPlayedSongsObservable.map(songs -> {
                Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(b.playCount, a.playCount));
                return Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList());
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                mostPlayedRecyclerView.itemAdapter.setItems(adaptableItems);
            }));
            subscription.add(favouritesSongsObservable.map(songs -> Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                favoriteRecyclerView.itemAdapter.setItems(adaptableItems);
            }));
        }
    });
}
Also used : R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) SuggestedDividerDecoration(com.simplecity.amp_library.ui.views.SuggestedDividerDecoration) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) Serializable(java.io.Serializable) 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) Context(android.content.Context) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) Intent(android.content.Intent) ArrayList(java.util.ArrayList) Observable(rx.Observable) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) SuggestedAdapter(com.simplecity.amp_library.ui.adapters.SuggestedAdapter) Toast(android.widget.Toast) 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) 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) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) Playlist(com.simplecity.amp_library.model.Playlist) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) CompositeSubscription(rx.subscriptions.CompositeSubscription) List(java.util.List) ArrayList(java.util.ArrayList) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 14 with Song

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

the class SuggestedFragment method onOverflowClick.

@Override
public void onOverflowClick(View v, int position, Object item) {
    if (item instanceof AlbumArtist) {
        PopupMenu menu = new PopupMenu(SuggestedFragment.this.getActivity(), v);
        MenuUtils.addAlbumArtistMenuOptions(getActivity(), menu);
        MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, (AlbumArtist) item);
        menu.show();
    } else if (item instanceof Album) {
        PopupMenu menu = new PopupMenu(SuggestedFragment.this.getActivity(), v);
        MenuUtils.addAlbumMenuOptions(getActivity(), menu);
        MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, (Album) item);
        menu.show();
    } else if (item instanceof Song) {
        PopupMenu menu = new PopupMenu(SuggestedFragment.this.getActivity(), v);
        MenuUtils.addSongMenuOptions(getActivity(), menu);
        MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, (Song) item, menuItem -> {
            switch(menuItem.getItemId()) {
                case BLACKLIST:
                    {
                        BlacklistHelper.addToBlacklist(((Song) item));
                        suggestedAdapter.removeItem(position);
                        return true;
                    }
            }
            return false;
        });
        menu.show();
    }
}
Also used : Song(com.simplecity.amp_library.model.Song) AppCompatActivity(android.support.v7.app.AppCompatActivity) Album(com.simplecity.amp_library.model.Album) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) PopupMenu(android.support.v7.widget.PopupMenu)

Example 15 with Song

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

the class SongAdapter method getSectionName.

@NonNull
@Override
public String getSectionName(int position) {
    if (!(items.get(position) instanceof SongView)) {
        return "";
    }
    int sortOrder = SortManager.getInstance().getSongsSortOrder();
    if (sortOrder != SortManager.SongSort.DATE && sortOrder != SortManager.SongSort.DURATION && sortOrder != SortManager.SongSort.TRACK_NUMBER) {
        Song song = ((SongView) items.get(position)).song;
        String string = null;
        boolean requiresSubstring = true;
        switch(sortOrder) {
            case SortManager.SongSort.DEFAULT:
                string = StringUtils.keyFor(song.name);
                break;
            case SortManager.SongSort.NAME:
                string = song.name;
                break;
            case SortManager.SongSort.YEAR:
                string = String.valueOf(song.year);
                if (string.length() != 4) {
                    string = "-";
                } else {
                    string = string.substring(2, 4);
                }
                requiresSubstring = false;
                break;
            case SortManager.SongSort.ALBUM_NAME:
                string = StringUtils.keyFor(song.albumName);
                break;
            case SortManager.SongSort.ARTIST_NAME:
                string = StringUtils.keyFor(song.artistName);
                break;
        }
        if (requiresSubstring) {
            if (!TextUtils.isEmpty(string)) {
                string = string.substring(0, 1).toUpperCase();
            } else {
                string = " ";
            }
        }
        return string;
    }
    return "";
}
Also used : Song(com.simplecity.amp_library.model.Song) SongView(com.simplecity.amp_library.ui.modelviews.SongView) NonNull(android.support.annotation.NonNull)

Aggregations

Song (com.simplecity.amp_library.model.Song)26 List (java.util.List)14 Intent (android.content.Intent)13 Stream (com.annimon.stream.Stream)12 Album (com.simplecity.amp_library.model.Album)12 Context (android.content.Context)11 ArrayList (java.util.ArrayList)11 Observable (rx.Observable)11 Toast (android.widget.Toast)10 Collectors (com.annimon.stream.Collectors)10 R (com.simplecity.amp_library.R)10 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)10 Schedulers (rx.schedulers.Schedulers)10 Uri (android.net.Uri)9 AlbumArtist (com.simplecity.amp_library.model.AlbumArtist)9 Playlist (com.simplecity.amp_library.model.Playlist)9 ContentUris (android.content.ContentUris)7 MediaStore (android.provider.MediaStore)7 View (android.view.View)7 Glide (com.bumptech.glide.Glide)7