Commit ee2535de authored by Adrien Maglo's avatar Adrien Maglo

AudioAlbumsSongsFragment: update correctly the lists after a media deletion

parent 4649b8f7
......@@ -259,8 +259,10 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
@Override
public void run(Object o) {
AudioBrowserListAdapter.ListItem listItem = (AudioBrowserListAdapter.ListItem)o;
mMediaLibrary.getMediaItems().remove(listItem.mMediaList.get(0));
updateList();
Media media = listItem.mMediaList.get(0);
mMediaLibrary.getMediaItems().remove(media);
mSongsAdapter.removeMedia(media);
mAlbumsAdapter.removeMedia(media);
}
});
alertDialog.show();
......
......@@ -130,6 +130,29 @@ public class AudioBrowserListAdapter extends BaseAdapter {
mItems.add(item);
}
/**
* Remove all the reference to a media in the list items.
* Remove also all the list items that contain only this media.
* @param media the media to remove
*/
public void removeMedia(Media media) {
for (int i = 0; i < mItems.size(); ++i) {
ListItem item = mItems.get(i);
if (item.mMediaList == null)
continue;
for (int j = 0; j < item.mMediaList.size(); ++j)
if (item.mMediaList.get(j).getLocation().equals(media.getLocation())) {
item.mMediaList.remove(j);
j--;
}
if (item.mMediaList.isEmpty() && !item.mIsSeparator) {
mItems.remove(i);
i--;
}
}
notifyDataSetChanged();
}
public void clear() {
mMediaItemMap.clear();
mItems.clear();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment