copy playlist contents during rename
Android 4.4 has a silly bug (? feature ?) where renaming a playlist will make it impossible to re-create a new playlist with the old name until the renamed playlist has been deleted. This patch changes vanillas rename code to actually copy the full playlist and delete the old version.
This commit is contained in:
parent
f230b14eda
commit
0530495bc1
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
|
||||
* Copyright (C) 2014 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -180,6 +181,18 @@ public class Playlist {
|
||||
resolver.delete(uri, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy content from one playlist to another
|
||||
*
|
||||
* @param resolver A ContentResolver to use.
|
||||
* @param sourceid The Media.Audio.Playlists id of the source playlist
|
||||
* @param destinationId The Media.Audio.Playlists id of the destination playlist
|
||||
*/
|
||||
private static void _copyToPlaylist(ContentResolver resolver, long sourceId, long destinationId) {
|
||||
QueryTask query = MediaUtils.buildPlaylistQuery(sourceId, Song.FILLED_PLAYLIST_PROJECTION, null);
|
||||
addToPlaylist(resolver, destinationId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename the playlist with the given id.
|
||||
*
|
||||
@ -189,16 +202,10 @@ public class Playlist {
|
||||
*/
|
||||
public static void renamePlaylist(ContentResolver resolver, long id, String newName)
|
||||
{
|
||||
long existingId = getPlaylist(resolver, newName);
|
||||
// We are already called the requested name; nothing to do.
|
||||
if (existingId == id)
|
||||
return;
|
||||
// There is already a playlist with this name. Kill it.
|
||||
if (existingId != -1)
|
||||
deletePlaylist(resolver, existingId);
|
||||
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(MediaStore.Audio.Playlists.NAME, newName);
|
||||
resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values, "_id=" + id, null);
|
||||
long newId = createPlaylist(resolver, newName);
|
||||
if (newId != -1) { // new playlist created -> move stuff over
|
||||
_copyToPlaylist(resolver, id, newId);
|
||||
deletePlaylist(resolver, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user