[Android] Use observable string to refresh browsers items
Geoffrey Métais
git at videolan.org
Tue Nov 29 18:50:48 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Nov 29 18:49:34 2016 +0100| [a98f2d82cef8a015ad8b3025256654762537fd2e] | committer: Geoffrey Métais
Use observable string to refresh browsers items
> https://code.videolan.org/videolan/vlc-android/commit/a98f2d82cef8a015ad8b3025256654762537fd2e
---
vlc-android/res/layout/directory_view_item.xml | 4 ++--
.../vlc/gui/browser/BaseBrowserAdapter.java | 27 ++++------------------
.../vlc/gui/browser/BaseBrowserFragment.java | 2 +-
3 files changed, 7 insertions(+), 26 deletions(-)
diff --git a/vlc-android/res/layout/directory_view_item.xml b/vlc-android/res/layout/directory_view_item.xml
index df973ca..67d7de7 100644
--- a/vlc-android/res/layout/directory_view_item.xml
+++ b/vlc-android/res/layout/directory_view_item.xml
@@ -94,9 +94,9 @@
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:maxLines="1"
- android:text="@{item.description}"
+ android:text="@{item.observableDescription}"
android:fontFamily="sans-serif-light"
- android:visibility="@{item.description != null ? View.VISIBLE : View.GONE}"
+ android:visibility="@{item.observableDescription != null ? View.VISIBLE : View.GONE}"
android:textColor="?attr/list_subtitle"/>
</LinearLayout>
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 08458cd..3de9380 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -23,10 +23,10 @@
package org.videolan.vlc.gui.browser;
import android.databinding.DataBindingUtil;
+import android.databinding.ObservableField;
import android.databinding.ViewDataBinding;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
-import android.support.v4.util.SparseArrayCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
@@ -48,7 +48,6 @@ import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.MediaItemFilter;
-import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
@@ -70,7 +69,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
ArrayList<MediaLibraryItem> mMediaList = new ArrayList<>();
ArrayList<MediaLibraryItem> mOriginalData = null;
BaseBrowserFragment fragment;
- SparseArrayCompat<WeakReference<MediaViewHolder>> mHolders = new SparseArrayCompat<>();
private int mTop = 0;
private int mMediaCount = 0;
private ItemFilter mFilter = new ItemFilter();
@@ -109,8 +107,9 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
}
private void onBindMediaViewHolder(final MediaViewHolder vh, int position) {
- mHolders.put(position, new WeakReference<>(vh));
final MediaWrapper media = (MediaWrapper) getItem(position);
+ if (media.observableDescription == null)
+ media.observableDescription = new ObservableField<>(media.getDescription());
vh.binding.setItem(media);
vh.binding.setHasContextMenu(true);
if (fragment instanceof NetworkBrowserFragment && fragment.isRootDirectory())
@@ -120,12 +119,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
vh.setViewBackground(vh.itemView.hasFocus(), mSelectedItems.contains(position));
}
-
- @Override
- public void onViewRecycled(ViewHolder holder) {
- mHolders.remove(holder.getAdapterPosition());
- }
-
@Override
public int getItemCount() {
return mMediaList.size();
@@ -145,6 +138,7 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
public void onMoreClick(View v){}
public abstract int getType();
+
}
class MediaViewHolder extends ViewHolder<DirectoryViewItemBinding> implements View.OnLongClickListener {
@@ -286,19 +280,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
mTop = top;
}
- void setDescription(int position, String description){
- Object item = getItem(position);
- if (item instanceof MediaWrapper)
- ((MediaWrapper) item).setDescription(description);
- else if (item instanceof Storage)
- ((Storage) item).setDescription(description);
- else
- return;
- WeakReference<MediaViewHolder> wr = mHolders.get(position);
- if (wr != null && wr.get() != null)
- wr.get().binding.setItem((MediaLibraryItem) item);
- }
-
public void addAll(ArrayList<MediaWrapper> mediaList){
mMediaList.clear();
boolean isHoneyComb = AndroidUtil.isHoneycombOrLater();
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 8cc87a0..64a0285 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -612,7 +612,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
MediaWrapper mw = null;
if (!TextUtils.equals(holderText, "")) {
- mAdapter.setDescription(mCurrentParsedPosition, holderText);
+ mAdapter.getItem(mCurrentParsedPosition).observableDescription.set(holderText);
directories.addAll(files);
mFoldersContentLists.put(mCurrentParsedPosition, new ArrayList<>(directories));
}
More information about the Android
mailing list