use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class DetailPresenter method playlistSelected.
void playlistSelected(Context context, MenuItem item, Runnable insertCallback) {
songsProvider.getSongs().observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(PlaylistUtils.ARG_PLAYLIST);
PlaylistUtils.addToPlaylist(context, playlist, songs, insertCallback);
});
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method createPlaylist.
@Nullable
public static Playlist createPlaylist(Context context, String name) {
Playlist playlist = null;
long id = -1;
if (!TextUtils.isEmpty(name)) {
Query query = new Query.Builder().uri(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI).projection(new String[] { MediaStore.Audio.PlaylistsColumns.NAME }).selection(MediaStore.Audio.PlaylistsColumns.NAME + " = '" + name + "'").build();
final Cursor cursor = SqlUtils.createQuery(context, query);
if (cursor != null) {
try {
int count = cursor.getCount();
if (count <= 0) {
final ContentValues values = new ContentValues(1);
values.put(MediaStore.Audio.PlaylistsColumns.NAME, name);
// Catch NPE occurring on Amazon devices.
try {
final Uri uri = context.getContentResolver().insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values);
if (uri != null) {
id = Long.parseLong(uri.getLastPathSegment());
}
} catch (NullPointerException e) {
Crashlytics.log("Failed to create playlist: " + e.getMessage());
}
}
} finally {
cursor.close();
}
}
}
if (id != -1) {
playlist = new Playlist(Playlist.Type.USER_CREATED, id, name, true, false, true, true, true);
} else {
Crashlytics.log(String.format("Failed to create playlist. Name: %s, id: %d", name, id));
DataManager.getInstance().getPlaylistsRelay().first(Collections.emptyList()).subscribe(playlists -> Crashlytics.log("Existing playlists: " + playlists), throwable -> {
});
}
return playlist;
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method addFileObjectsToPlaylist.
@SuppressLint("CheckResult")
public static void addFileObjectsToPlaylist(Context context, Playlist playlist, List<BaseFileObject> fileObjects, Runnable insertCallback) {
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, insertCallback);
}, error -> LogUtils.logException(TAG, "Error getting songs for file object", error));
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method createFavoritePlaylist.
@Nullable
public static Optional<Playlist> createFavoritePlaylist() {
Playlist playlist = PlaylistUtils.createPlaylist(ShuttleApplication.getInstance(), ShuttleApplication.getInstance().getString(R.string.fav_title));
if (playlist != null) {
playlist.canDelete = false;
playlist.canRename = false;
playlist.type = Playlist.Type.FAVORITES;
}
return Optional.ofNullable(playlist);
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method renamePlaylistDialog.
public static void renamePlaylistDialog(final Context context, final Playlist playlist) {
@SuppressLint("InflateParams") View customView = LayoutInflater.from(context).inflate(R.layout.dialog_playlist, null);
final EditText editText = customView.findViewById(R.id.editText);
editText.setText(playlist.name);
MaterialDialog.Builder builder = DialogUtils.getBuilder(context).title(R.string.create_playlist_create_text_prompt).customView(customView, false).positiveText(R.string.save).onPositive((materialDialog, dialogAction) -> {
String name = editText.getText().toString();
if (name.length() > 0) {
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues(1);
values.put(MediaStore.Audio.Playlists.NAME, name);
resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values, MediaStore.Audio.Playlists._ID + "=?", new String[] { Long.valueOf(playlist.id).toString() });
playlist.name = name;
Toast.makeText(context, R.string.playlist_renamed_message, Toast.LENGTH_SHORT).show();
}
}).negativeText(R.string.cancel);
final MaterialDialog dialog = builder.build();
TextWatcher textWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// check if playlist with current name exists already, and warn the user if so.
setSaveButton(dialog, playlist, editText.getText().toString());
}
public void afterTextChanged(Editable s) {
}
};
editText.addTextChangedListener(textWatcher);
dialog.show();
}
Aggregations