[Android] Fix Storages comparison

Geoffrey Métais git at videolan.org
Tue Feb 6 11:37:57 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb  6 10:31:13 2018 +0100| [8191209bc7e1640f479ff43ab94ae9aaa862fc93] | committer: Geoffrey Métais

Fix Storages comparison

> https://code.videolan.org/videolan/vlc-android/commit/8191209bc7e1640f479ff43ab94ae9aaa862fc93
---

 .../videolan/medialibrary/media/MediaLibraryItem.java | 19 +++++++------------
 .../src/org/videolan/medialibrary/media/Storage.java  |  6 ++++++
 .../videolan/vlc/gui/browser/BaseBrowserAdapter.java  |  3 +--
 .../videolan/vlc/gui/browser/BaseBrowserFragment.java |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
index 4bbe7764a..c92090ad4 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
@@ -4,8 +4,6 @@ import android.os.Parcel;
 import android.os.Parcelable;
 import android.text.TextUtils;
 
-import org.videolan.medialibrary.Medialibrary;
-
 public abstract class MediaLibraryItem implements Parcelable {
 
     public static final int TYPE_ALBUM    = 1 << 1;
@@ -106,18 +104,15 @@ public abstract class MediaLibraryItem implements Parcelable {
     }
 
     public boolean equals(MediaLibraryItem other) {
-        if (this == other)
-            return true;
-        if (other == null)
-            return false;
-        if (getItemType() != other.getItemType())
-            return false;
-        if (mId != 0)
-            return mId == other.getId();
-        if (getItemType() == TYPE_DUMMY)
-            return TextUtils.equals(getTitle(), other.getTitle());
+        if (this == other) return true;
+        if (other == null) return false;
+        if (getItemType() != other.getItemType()) return false;
+        if (mId != 0) return mId == other.getId();
+        if (getItemType() == TYPE_DUMMY) return TextUtils.equals(getTitle(), other.getTitle());
         if (getItemType() == TYPE_MEDIA)
             return TextUtils.equals(((MediaWrapper)this).getLocation(), ((MediaWrapper)other).getLocation());
+        if (getItemType() == TYPE_STORAGE)
+            return TextUtils.equals(((Storage)this).getName(), ((Storage)other).getName());
         return false;
     }
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Storage.java b/medialibrary/src/org/videolan/medialibrary/media/Storage.java
index 876c671c2..a5b2fccae 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Storage.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Storage.java
@@ -4,6 +4,7 @@ package org.videolan.medialibrary.media;
 import android.net.Uri;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.text.TextUtils;
 
 public class Storage extends MediaLibraryItem {
 
@@ -68,4 +69,9 @@ public class Storage extends MediaLibraryItem {
         this.uri = in.readParcelable(Uri.class.getClassLoader());
         this.description = in.readString();
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return obj instanceof Storage && TextUtils.equals(mTitle, ((Storage)obj).getTitle());
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index 302c7a8f3..39a2b97cf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -237,8 +237,7 @@ public class BaseBrowserAdapter extends SortableAdapter<MediaLibraryItem, BaseBr
     }
 
     public void clear() {
-        if (!isEmpty())
-            update(new ArrayList<MediaLibraryItem>(0));
+        if (!isEmpty()) update(new ArrayList<MediaLibraryItem>(0));
     }
 
     public boolean isEmpty() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 6636a97ed..8fde04d3b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -390,7 +390,7 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
         if (isSortEnabled()) {
             refreshList = new ArrayList<>();
             refreshing = true;
-        }
+        } else mAdapter.clear();
         mBrowserHandler.removeCallbacksAndMessages(null);
         mHandler.sendEmptyMessageDelayed(BrowserFragmentHandler.MSG_SHOW_LOADING, 300);
 



More information about the Android mailing list