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;
}
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();
}
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);
}));
}
});
}
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();
}
}
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 "";
}
Aggregations