From 53eb77e8b3515a8ffa11e25b62d376ca40da675c Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Tue, 22 Nov 2016 10:40:29 +0100 Subject: [PATCH] re-add playlist renaming --- .../android/medialibrary/MediaLibrary.java | 22 ++++++++++++++++++- .../android/vanilla/PlaybackActivity.java | 2 +- .../android/vanilla/Playlist.java | 14 +++--------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/ch/blinkenlights/android/medialibrary/MediaLibrary.java b/src/ch/blinkenlights/android/medialibrary/MediaLibrary.java index 32a03d08..c1857720 100644 --- a/src/ch/blinkenlights/android/medialibrary/MediaLibrary.java +++ b/src/ch/blinkenlights/android/medialibrary/MediaLibrary.java @@ -123,7 +123,7 @@ public class MediaLibrary { */ public static boolean removePlaylist(Context context, long id) { // first, wipe all songs - getBackend(context).delete(MediaLibrary.TABLE_PLAYLISTS_SONGS, MediaLibrary.PlaylistSongColumns.PLAYLIST_ID+"="+id, null); + removeFromPlaylist(context, MediaLibrary.PlaylistSongColumns.PLAYLIST_ID+"="+id, null); int rows = getBackend(context).delete(MediaLibrary.TABLE_PLAYLISTS, MediaLibrary.PlaylistColumns._ID+"="+id, null); return (rows > 0); } @@ -174,6 +174,26 @@ public class MediaLibrary { return getBackend(context).delete(MediaLibrary.TABLE_PLAYLISTS_SONGS, selection, selectionArgs); } + /** + * Renames an existing playlist + * + * @param context the context to use + * @param playlistId the id of the playlist to rename + * @param newName the new name of the playlist + * @return the id of the new playlist, -1 on error + */ + public static long renamePlaylist(Context context, long playlistId, String newName) { + long newId = createPlaylist(context, newName); + if (newId >= 0) { + String selection = MediaLibrary.PlaylistSongColumns.PLAYLIST_ID+"="+playlistId; + ContentValues v = new ContentValues(); + v.put(MediaLibrary.PlaylistSongColumns.PLAYLIST_ID, newId); + getBackend(context).update(MediaLibrary.TABLE_PLAYLISTS_SONGS, v, selection, null, true); + removePlaylist(context, playlistId); + } + return newId; + } + /** * Registers a new content observer for the media library * diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java index 7b08c8fe..b6bfff65 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java @@ -471,7 +471,7 @@ public abstract class PlaybackActivity extends Activity } case MSG_RENAME_PLAYLIST: { PlaylistTask playlistTask = (PlaylistTask)message.obj; - Playlist.renamePlaylist(getContentResolver(), playlistTask.playlistId, playlistTask.name); + Playlist.renamePlaylist(getApplicationContext(), playlistTask.playlistId, playlistTask.name); break; } case MSG_DELETE: { diff --git a/src/ch/blinkenlights/android/vanilla/Playlist.java b/src/ch/blinkenlights/android/vanilla/Playlist.java index eb02b11e..d4b7ba0d 100644 --- a/src/ch/blinkenlights/android/vanilla/Playlist.java +++ b/src/ch/blinkenlights/android/vanilla/Playlist.java @@ -164,20 +164,12 @@ public class Playlist { /** * Rename the playlist with the given id. * - * @param resolver A ContentResolver to use. + * @param context the context to use * @param id The Media.Audio.Playlists id of the playlist. * @param newName The new name for the playlist. */ - public static void renamePlaylist(ContentResolver resolver, long id, String newName) - { - /* - * FIXME: OBSOLETED CODE - long newId = createPlaylist(resolver, newName); - if (newId != -1) { // new playlist created -> move stuff over - _copyToPlaylist(resolver, id, newId); - deletePlaylist(resolver, id); - } - */ + public static void renamePlaylist(Context context, long id, String newName) { + MediaLibrary.renamePlaylist(context, id, newName); } /**