[Android] Fix click listeners for video grid
Geoffrey Métais
git at videolan.org
Thu Dec 17 16:32:12 CET 2015
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 17 16:31:06 2015 +0100| [1cfa4f25f4b1d9ae6e518d5e4dd3301fcf508c0f] | committer: Geoffrey Métais
Fix click listeners for video grid
> https://code.videolan.org/videolan/vlc-android/commit/1cfa4f25f4b1d9ae6e518d5e4dd3301fcf508c0f
---
vlc-android/res/layout/video_grid_card.xml | 15 +++++----------
vlc-android/res/layout/video_list_card.xml | 15 +++++----------
.../src/org/videolan/vlc/gui/video/VideoListAdapter.java | 14 +++++---------
3 files changed, 15 insertions(+), 29 deletions(-)
diff --git a/vlc-android/res/layout/video_grid_card.xml b/vlc-android/res/layout/video_grid_card.xml
index 8638866..983dff6 100644
--- a/vlc-android/res/layout/video_grid_card.xml
+++ b/vlc-android/res/layout/video_grid_card.xml
@@ -15,10 +15,6 @@
type="String" />
<variable
- name="position"
- type="int" />
-
- <variable
name="max"
type="int" />
@@ -39,8 +35,8 @@
type="android.widget.ImageView.ScaleType" />
<variable
- name="handler"
- type="org.videolan.vlc.gui.video.VideoListAdapter.ClickHandler" />
+ name="holder"
+ type="org.videolan.vlc.gui.video.VideoListAdapter.ViewHolder" />
</data>
<FrameLayout
@@ -49,7 +45,7 @@
android:layout_marginBottom="10dip"
android:longClickable="true"
android:clickable="true"
- android:onClick="@{handler.onClick}">
+ android:onClick="@{holder.onClick}">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="@dimen/grid_card_width"
@@ -111,10 +107,9 @@
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="@string/more_actions"
- android:onClick="@{handler.onMoreClick}"
+ android:onClick="@{holder.onMoreClick}"
android:scaleType="fitCenter"
- android:src="@drawable/ic_more"
- android:tag="@{position}" />
+ android:src="@drawable/ic_more" />
</LinearLayout>
diff --git a/vlc-android/res/layout/video_list_card.xml b/vlc-android/res/layout/video_list_card.xml
index 730d9b2..960880e 100644
--- a/vlc-android/res/layout/video_list_card.xml
+++ b/vlc-android/res/layout/video_list_card.xml
@@ -15,10 +15,6 @@
type="String" />
<variable
- name="position"
- type="int" />
-
- <variable
name="max"
type="int" />
@@ -39,8 +35,8 @@
type="android.widget.ImageView.ScaleType" />
<variable
- name="handler"
- type="org.videolan.vlc.gui.video.VideoListAdapter.ClickHandler" />
+ name="holder"
+ type="org.videolan.vlc.gui.video.VideoListAdapter.ViewHolder" />
</data>
<android.support.v7.widget.CardView
@@ -52,7 +48,7 @@
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
android:clickable="true"
- android:onClick="@{handler.onClick}"
+ android:onClick="@{holder.onClick}"
android:longClickable="true">
<LinearLayout
@@ -98,10 +94,9 @@
android:layout_above="@+id/info_layout"
android:clickable="true"
android:contentDescription="@string/more_actions"
- android:onClick="@{handler.onMoreClick}"
+ android:onClick="@{holder.onMoreClick}"
android:scaleType="fitCenter"
- android:src="@drawable/ic_more"
- android:tag="@{position}" />
+ android:src="@drawable/ic_more" />
<LinearLayout
android:id="@+id/info_layout"
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 99920d6..b304808 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -105,9 +105,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
fillView(holder, media);
- holder.binding.setVariable(BR.position, position);
holder.binding.setVariable(BR.media, media);
- holder.binding.setVariable(BR.handler, mClickHandler);
holder.binding.executePendingBindings();
holder.itemView.setOnLongClickListener(this);
if (asyncLoad)
@@ -336,7 +334,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
return super.getItemViewType(position);
}
- static class ViewHolder extends RecyclerView.ViewHolder {
+ public class ViewHolder extends RecyclerView.ViewHolder {
boolean listmode;
ViewDataBinding binding;
@@ -344,14 +342,11 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
super(itemView);
binding = DataBindingUtil.bind(itemView);
this.listmode = listMode;
+ binding.setVariable(BR.holder, this);
}
- }
- public ClickHandler mClickHandler = new ClickHandler();
- public class ClickHandler {
public void onClick(View v){
- int position = ((Integer) v.findViewById(R.id.item_more).getTag()).intValue();
- MediaWrapper media = mVideos.get(position);
+ MediaWrapper media = mVideos.get(getAdapterPosition());
if (media instanceof MediaGroup) {
MainActivity activity = (MainActivity) mFragment.getActivity();
activity.showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, media.getTitle());
@@ -360,10 +355,11 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
VideoPlayerActivity.start(v.getContext(), media.getUri(), media.getTitle());
}
}
+
public void onMoreClick(View v){
if (mFragment == null)
return;
- mFragment.mGridView.openContextMenu(((Integer) v.getTag()).intValue());
+ mFragment.mGridView.openContextMenu(getAdapterPosition());
}
}
More information about the Android
mailing list