Commit ab55759e authored by Alexandre Perraud's avatar Alexandre Perraud

Playlist : Fix delete crash

parent 81d21b3f
......@@ -231,8 +231,9 @@ public class AudioAlbumsSongsFragment extends PlaybackServiceFragment implements
if (id == R.id.audio_list_browser_delete) {
final AudioBrowserListAdapter.ListItem listItem = adapter.getItem(position);
final String key = adapter.getKey(position);
adapter.remove(position, key);
adapter.remove(position);
UiTools.snackerWithCancel(getView(), getString(R.string.file_deleted), new Runnable() {
@Override
public void run() {
......@@ -241,7 +242,7 @@ public class AudioAlbumsSongsFragment extends PlaybackServiceFragment implements
}, new Runnable() {
@Override
public void run() {
adapter.addItem(position, key, listItem);
adapter.addItem(position, listItem);
}
});
return true;
......
......@@ -466,11 +466,10 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
return false;
final MediaWrapper media = mediaList.get(0);
final AudioBrowserListAdapter.ListItem listItem = adapter.getItem(position);
final String key = adapter.getKey(position);
String message;
Runnable action;
adapter.remove(position, key);
adapter.remove(position);
if (mode == MODE_PLAYLIST) {
message = getString(R.string.playlist_deleted);
......@@ -492,7 +491,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
UiTools.snackerWithCancel(getView(), message, action, new Runnable() {
@Override
public void run() {
adapter.addItem(position, key, listItem);
adapter.addItem(position, listItem);
}
});
return true;
......
......@@ -92,15 +92,17 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
public static class ListItem {
final public String mTitle;
final public String mSubTitle;
final public String mMediaKey;
final public ArrayList<MediaWrapper> mMediaList;
final public boolean mIsSeparator;
public ListItem(String title, String subTitle, MediaWrapper media, boolean isSeparator) {
public ListItem(String title, String subTitle, MediaWrapper media, boolean isSeparator, String mediaKey) {
mMediaList = new ArrayList<>();
if (media != null)
mMediaList.add(media);
mTitle = title;
mSubTitle = subTitle;
mMediaKey = mediaKey;
mIsSeparator = isSeparator;
}
}
......@@ -147,7 +149,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
if (mMediaItemMap.containsKey(mediaKey))
mMediaItemMap.get(mediaKey).mMediaList.add(media);
else {
ListItem item = new ListItem(title, subTitle, media, false);
ListItem item = new ListItem(title, subTitle, media, false, mediaKey);
mMediaItemMap.put(mediaKey, item);
mItems.add(item);
}
......@@ -199,14 +201,14 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
});
}
public void remove(int position, String key) {
public void remove(int position) {
mMediaItemMap.remove(mItems.get(position).mMediaKey);
mItems.remove(position);
mMediaItemMap.remove(key);
notifyDataSetChanged();
}
public void addItem(int position, String key, ListItem item) {
mMediaItemMap.put(key, item);
public void addItem(int position, ListItem item) {
mMediaItemMap.put(item.mMediaKey, item);
mItems.add(position, item);
notifyDataSetChanged();
}
......@@ -250,7 +252,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
if (Character.isLetter(firstChar)) {
String firstCharInString = String.valueOf(firstChar);
if ((firstSeparator || firstChar != prevFirstChar) && !sections.contains(firstCharInString)) {
ListItem item = new ListItem(firstCharInString, null, null, true);
ListItem item = new ListItem(firstCharInString, null, null, true, null);
mItems.add(i, item);
mSections.put(i, String.valueOf(firstChar));
i++;
......@@ -259,7 +261,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
sections.add(firstCharInString);
}
} else if (firstSeparator) {
ListItem item = new ListItem("#", null, null, true);
ListItem item = new ListItem("#", null, null, true, null);
mItems.add(i, item);
mSections.put(i, "#");
i++;
......@@ -276,7 +278,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
if (mSeparatorItemMap.containsKey(titleKey))
mSeparatorItemMap.get(titleKey).mMediaList.add(media);
else {
ListItem item = new ListItem(title, null, media, true);
ListItem item = new ListItem(title, null, media, true, null);
mSeparatorItemMap.put(titleKey, item);
mItems.add(item);
}
......
......@@ -214,7 +214,7 @@ public class MediaLibrary {
items = db.playlistGetItems(playlistName);
if (items == null)
continue;
playList = new AudioBrowserListAdapter.ListItem(playlistName, null, null, false);
playList = new AudioBrowserListAdapter.ListItem(playlistName, null, null, false, null);
for (String track : items){
playList.mMediaList.add(new MediaWrapper(AndroidUtil.LocationToUri(track)));
}
......
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