[Android] AudioAlbumsSongsFragment: update correctly the lists after a media deletion

Adrien Maglo git at videolan.org
Fri Feb 21 16:52:11 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Fri Feb 21 16:47:58 2014 +0100| [ee2535deca0b7dee7f24ef80aa89f86ec457579d] | committer: Adrien Maglo

AudioAlbumsSongsFragment: update correctly the lists after a media deletion

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ee2535deca0b7dee7f24ef80aa89f86ec457579d
---

 .../vlc/gui/audio/AudioAlbumsSongsFragment.java    |    6 +++--
 .../vlc/gui/audio/AudioBrowserListAdapter.java     |   23 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 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 05e4afa..0c5b86e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -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();
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 06c48ca..b6af497 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -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();



More information about the Android mailing list