[Android] Playlist : Fix delete crash
Alexandre Perraud
git at videolan.org
Mon Aug 8 14:05:04 CEST 2016
vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Fri Aug 5 17:53:40 2016 +0200| [ab55759ecc8cb7cc1ab719536e7e29148aefe2d2] | committer: Alexandre Perraud
Playlist : Fix delete crash
> https://code.videolan.org/videolan/vlc-android/commit/ab55759ecc8cb7cc1ab719536e7e29148aefe2d2
---
.../vlc/gui/audio/AudioAlbumsSongsFragment.java | 7 ++++---
.../videolan/vlc/gui/audio/AudioBrowserFragment.java | 5 ++---
.../vlc/gui/audio/AudioBrowserListAdapter.java | 20 +++++++++++---------
.../src/org/videolan/vlc/media/MediaLibrary.java | 2 +-
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index f540652..81b8199 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -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;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 80ee356..1c7b6e2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -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;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index d850420..a60e80e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -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);
}
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java
index 1f97a0f..67b3aa5 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java
@@ -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)));
}
More information about the Android
mailing list