[Android] Use interface for Audio click handler

Geoffrey Métais git at videolan.org
Mon Sep 7 14:29:23 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep  3 17:36:19 2015 +0200| [e00cfe057ff78f0664e2e4e6418ea16c00f5e945] | committer: Geoffrey Métais

Use interface for Audio click handler

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

 vlc-android/res/layout/audio_browser_item.xml      |    4 +--
 .../vlc/gui/audio/AudioBrowserListAdapter.java     |   15 +++++-----
 .../vlc/interfaces/IAudioClickHandler.java         |   30 ++++++++++++++++++++
 3 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/vlc-android/res/layout/audio_browser_item.xml b/vlc-android/res/layout/audio_browser_item.xml
index 0608924..79d3f65 100644
--- a/vlc-android/res/layout/audio_browser_item.xml
+++ b/vlc-android/res/layout/audio_browser_item.xml
@@ -13,7 +13,7 @@
             type="boolean"/>
         <variable
             name="handler"
-            type="org.videolan.vlc.gui.audio.AudioBrowserListAdapter.ClickHandler"/>
+            type="org.videolan.vlc.interfaces.IAudioClickHandler"/>
         <variable
             name="clickable"
             type="boolean"/>
@@ -81,7 +81,7 @@
                 android:background="@drawable/ic_more"
                 android:contentDescription="@string/more_actions"
                 android:visibility="@{clickable ? View.VISIBLE : View.GONE}"
-                android:onClick="@{handler.onClick}"
+                android:onClick="@{handler.onMoreClick}"
                 android:clickable="@{clickable}" />
         </RelativeLayout>
 
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 17f6216..878b703 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -42,6 +42,7 @@ import android.widget.TextView;
 import org.videolan.vlc.BR;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
+import org.videolan.vlc.interfaces.IAudioClickHandler;
 import org.videolan.vlc.util.BitmapCache;
 import org.videolan.vlc.util.Util;
 
@@ -53,7 +54,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
-public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndexer {
+public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndexer, IAudioClickHandler {
     public final static String TAG = "VLC/AudioBrowserListAdapter";
 
     public final static int TYPE_ARTISTS = 0;
@@ -347,7 +348,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
 
         holder.binding.setVariable(BR.footer, !isMediaItemAboveASeparator(position));
         holder.binding.setVariable(BR.clickable, mContextPopupMenuListener != null);
-        holder.binding.setVariable(BR.handler, mClickHandler);
+        holder.binding.setVariable(BR.handler, this);
         holder.binding.executePendingBindings();
 
         return v;
@@ -561,11 +562,9 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
         }
     };
 
-    public ClickHandler mClickHandler = new ClickHandler();
-    public class ClickHandler {
-        public void onClick(View v){
-            if (mContextPopupMenuListener != null)
-                mContextPopupMenuListener.onPopupMenu(v, ((ViewHolder) ((LinearLayout)v.getParent().getParent()).getTag()).position);
-        }
+    @Override
+    public void onMoreClick(View v) {
+        if (mContextPopupMenuListener != null)
+            mContextPopupMenuListener.onPopupMenu(v, ((ViewHolder) ((LinearLayout)v.getParent().getParent()).getTag()).position);
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IAudioClickHandler.java b/vlc-android/src/org/videolan/vlc/interfaces/IAudioClickHandler.java
new file mode 100644
index 0000000..742ece1
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IAudioClickHandler.java
@@ -0,0 +1,30 @@
+/*
+ * *************************************************************************
+ *  IAudioClickHandler.java
+ * **************************************************************************
+ *  Copyright © 2015 VLC authors and VideoLAN
+ *  Author: Geoffrey Métais
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *  ***************************************************************************
+ */
+
+package org.videolan.vlc.interfaces;
+
+import android.view.View;
+
+public interface IAudioClickHandler {
+    void onMoreClick(View v);
+}



More information about the Android mailing list