use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class QueuePresenter method saveQueue.
public void saveQueue(Context context, MenuItem item) {
Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(PlaylistUtils.ARG_PLAYLIST);
PlaylistUtils.addToPlaylist(context, playlist, MusicUtils.getQueue(), null);
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method addToFavorites.
/**
* Add a song to the favourites playlist
*/
public static void addToFavorites(final Context context) {
Song song = MusicUtils.getSong();
if (song == null) {
return;
}
Observable.fromCallable(Playlist::favoritesPlaylist).flatMap(playlist -> playlist.getSongsObservable(context).flatMap(new Func1<List<Song>, Observable<Playlist>>() {
@Override
public Observable<Playlist> call(List<Song> songs) {
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlist.id);
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, song.id);
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, songs.size() + 1);
context.getContentResolver().insert(uri, values);
return Observable.just(playlist);
}
})).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(playlist -> {
Toast.makeText(context, context.getResources().getString(R.string.song_to_favourites, song.name), Toast.LENGTH_SHORT).show();
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(MusicService.InternalIntents.FAVORITE_CHANGED));
});
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method makePlaylistMenu.
public static void makePlaylistMenu(Context context, SubMenu sub, int fragmentGroupId) {
Query query = new Query.Builder().uri(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI).projection(new String[] { BaseColumns._ID, MediaStore.Audio.PlaylistsColumns.NAME }).build();
SqlBriteUtils.createQuery(context, Playlist::new, query).observeOn(AndroidSchedulers.mainThread()).subscribe(playlists -> {
sub.clear();
sub.add(fragmentGroupId, MusicUtils.Defs.NEW_PLAYLIST, 0, R.string.new_playlist);
for (Playlist playlist : playlists) {
final Intent intent = new Intent();
intent.putExtra(ShuttleUtils.ARG_PLAYLIST, playlist);
sub.add(fragmentGroupId, MusicUtils.Defs.PLAYLIST_SELECTED, 0, playlist.name).setIntent(intent);
}
});
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method addToPlaylist.
/**
* Method addToPlaylist.
*
* @param playlist Playlist
* @param songs List<Song>
* @return boolean true if the playlist addition was successful
*/
public static void addToPlaylist(Context context, Playlist playlist, List<Song> songs) {
if (playlist == null || songs == null || songs.isEmpty()) {
return;
}
playlist.getSongsObservable(context).observeOn(AndroidSchedulers.mainThread()).subscribe(existingSongs -> {
if (!SettingsManager.getInstance().ignoreDuplicates()) {
List<Song> duplicates = Stream.of(existingSongs).filter(songs::contains).distinct().collect(Collectors.toList());
if (!duplicates.isEmpty()) {
View customView = LayoutInflater.from(context).inflate(R.layout.dialog_playlist_duplicates, null);
TextView messageText = (TextView) customView.findViewById(R.id.textView);
CheckBox applyToAll = (CheckBox) customView.findViewById(R.id.applyToAll);
CheckBox alwaysAdd = (CheckBox) customView.findViewById(R.id.alwaysAdd);
if (duplicates.size() <= 1) {
applyToAll.setVisibility(View.GONE);
applyToAll.setChecked(false);
}
messageText.setText(getPlaylistRemoveString(context, duplicates.get(0)));
applyToAll.setText(getApplyCheckboxString(context, duplicates.size()));
DialogUtils.getBuilder(context).title(R.string.dialog_title_playlist_duplicates).customView(customView, false).positiveText(R.string.dialog_button_playlist_duplicate_add).autoDismiss(false).onPositive((dialog, which) -> {
if (duplicates.size() != 1 && !applyToAll.isChecked()) {
duplicates.remove(0);
messageText.setText(getPlaylistRemoveString(context, duplicates.get(0)));
applyToAll.setText(getApplyCheckboxString(context, duplicates.size()));
} else {
insertPlaylistItems(context, playlist, songs, existingSongs.size());
SettingsManager.getInstance().setIgnoreDuplicates(alwaysAdd.isChecked());
dialog.dismiss();
}
}).negativeText(R.string.dialog_button_playlist_duplicate_skip).onNegative((dialog, which) -> {
if (duplicates.size() != 1 && !applyToAll.isChecked()) {
songs.remove(duplicates.remove(0));
messageText.setText(getPlaylistRemoveString(context, duplicates.get(0)));
applyToAll.setText(getApplyCheckboxString(context, duplicates.size()));
} else {
Stream.of(duplicates).filter(songs::contains).forEach(songs::remove);
insertPlaylistItems(context, playlist, songs, existingSongs.size());
SettingsManager.getInstance().setIgnoreDuplicates(alwaysAdd.isChecked());
dialog.dismiss();
}
}).show();
} else {
insertPlaylistItems(context, playlist, songs, existingSongs.size());
}
} else {
insertPlaylistItems(context, playlist, songs, existingSongs.size());
}
});
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method addFileObjectsToPlaylist.
public static void addFileObjectsToPlaylist(Context context, Playlist playlist, List<BaseFileObject> fileObjects) {
ProgressDialog progressDialog = ProgressDialog.show(context, "", context.getString(R.string.gathering_songs), false);
long folderCount = Stream.of(fileObjects).filter(value -> value.fileType == FileType.FOLDER).count();
if (folderCount > 0) {
progressDialog.show();
}
ShuttleUtils.getSongsForFileObjects(fileObjects).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
addToPlaylist(context, playlist, songs);
});
}
Aggregations