[Android] Use Databinding utils to inflate browsers views
Geoffrey Métais
git at videolan.org
Wed Feb 1 13:59:16 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 1 09:59:58 2017 +0100| [1a8534abaf28cc6114ef709e041c443f2476f238] | committer: Geoffrey Métais
Use Databinding utils to inflate browsers views
> https://code.videolan.org/videolan/vlc-android/commit/1a8534abaf28cc6114ef709e041c443f2476f238
---
.../vlc/gui/browser/BaseBrowserAdapter.java | 35 ++++++++--------------
.../vlc/gui/browser/StorageBrowserAdapter.java | 17 ++---------
2 files changed, 14 insertions(+), 38 deletions(-)
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 1d7e40a..fe6e46a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -22,12 +22,9 @@
*/
package org.videolan.vlc.gui.browser;
-import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
-import android.os.Handler;
-import android.os.Looper;
import android.support.annotation.MainThread;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
@@ -73,7 +70,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
protected final BaseBrowserFragment fragment;
private int mTop = 0, mMediaCount = 0, mSelectionCount = 0;
private ItemFilter mFilter = new ItemFilter();
- private Handler mHandler = new Handler(Looper.getMainLooper());
BaseBrowserAdapter(BaseBrowserFragment fragment){
this.fragment = fragment;
@@ -81,18 +77,11 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- ViewHolder vh;
- View v;
- if (viewType == MediaLibraryItem.TYPE_MEDIA) {
- v = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.browser_item, parent, false);
- vh = new MediaViewHolder(v);
- } else {
- v = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.browser_item_separator, parent, false);
- vh = new SeparatorViewHolder(v);
- }
- return vh;
+ LayoutInflater inflater = LayoutInflater.from(parent.getContext());
+ if (viewType == MediaLibraryItem.TYPE_MEDIA || viewType == MediaLibraryItem.TYPE_STORAGE)
+ return new MediaViewHolder(BrowserItemBinding.inflate(inflater, parent, false));
+ else
+ return new SeparatorViewHolder(BrowserItemSeparatorBinding.inflate(inflater, parent, false));
}
@Override
@@ -152,11 +141,11 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
class MediaViewHolder extends ViewHolder<BrowserItemBinding> implements View.OnLongClickListener {
- MediaViewHolder(View v) {
- super(v);
- binding = DataBindingUtil.bind(v);
+ MediaViewHolder(final BrowserItemBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
binding.setHolder(this);
- v.setOnLongClickListener(new View.OnLongClickListener() {
+ itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
binding.browserCheckbox.toggle();
@@ -212,9 +201,9 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
private class SeparatorViewHolder extends ViewHolder<BrowserItemSeparatorBinding> {
- SeparatorViewHolder(View v) {
- super(v);
- binding = DataBindingUtil.bind(v);
+ SeparatorViewHolder(BrowserItemSeparatorBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
}
@Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
index 8a40c1b..9b7279a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
@@ -24,25 +24,22 @@
package org.videolan.vlc.gui.browser;
import android.content.Intent;
-import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.CheckBox;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.medialibrary.media.Storage;
import org.videolan.vlc.MediaParsingService;
-import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.util.CustomDirectories;
import java.util.ArrayList;
import java.util.Arrays;
-public class StorageBrowserAdapter extends BaseBrowserAdapter {
+class StorageBrowserAdapter extends BaseBrowserAdapter {
- boolean isRoot;
+ private boolean isRoot;
private static ArrayList<String> mMediaDirsLocation;
private static ArrayList<String> mCustomDirsLocation;
@@ -54,16 +51,6 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
}
@Override
- public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- ViewHolder vh;
- View v;
- v = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.browser_item, parent, false);
- vh = new MediaViewHolder(v);
- return vh;
- }
-
- @Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final MediaViewHolder vh = (MediaViewHolder) holder;
final MediaLibraryItem storage = getItem(position);
More information about the Android
mailing list