re-add playlist renaming

This commit is contained in:
Adrian Ulrich committed 2016-11-22 10:40:29 +01:00
1 parent c631d17b52
commit 53eb77e8b3
3 files changed
+25 -13

No files matched your search

@@ -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
*
@@ -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: {
@@ -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);
}
/**