[Android] Set search results focusable with DPAD

Geoffrey Métais git at videolan.org
Thu Nov 2 15:44:15 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov  2 15:42:03 2017 +0100| [0f6e870920c23d4c4c4f908799c6ddf6af32e7f5] | committer: Geoffrey Métais

Set search results focusable with DPAD

> https://code.videolan.org/videolan/vlc-android/commit/0f6e870920c23d4c4c4f908799c6ddf6af32e7f5
---

 vlc-android/res/layout/search_item.xml                 |  6 +++++-
 .../src/org/videolan/vlc/gui/SearchResultAdapter.java  | 18 ++++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/vlc-android/res/layout/search_item.xml b/vlc-android/res/layout/search_item.xml
index dd538a571..dd10dcebc 100644
--- a/vlc-android/res/layout/search_item.xml
+++ b/vlc-android/res/layout/search_item.xml
@@ -15,6 +15,9 @@
         <variable
             name="handler"
             type="org.videolan.vlc.gui.SearchActivity.ClickHandler" />
+        <variable
+            name="bgColor"
+            type="int" />
     </data>
 
     <RelativeLayout
@@ -22,7 +25,8 @@
         android:layout_height="wrap_content"
         android:layout_margin="10dp"
         android:clickable="true"
-        android:background="?attr/background_default"
+        android:focusable="true"
+        android:background="@{bgColor}"
         android:onClick="@{() -> handler.onItemClick(item)}">
 
         <ImageView
diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java
index 5d4b672ba..11da5f46b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java
@@ -1,6 +1,5 @@
 package org.videolan.vlc.gui;
 
-import android.content.Context;
 import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
@@ -8,6 +7,7 @@ import android.view.ViewGroup;
 
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.vlc.databinding.SearchItemBinding;
+import org.videolan.vlc.gui.helpers.SelectorViewHolder;
 import org.videolan.vlc.gui.helpers.UiTools;
 
 
@@ -15,11 +15,16 @@ public class SearchResultAdapter extends RecyclerView.Adapter<SearchResultAdapte
 
     MediaLibraryItem[] mDataList;
     SearchActivity.ClickHandler mClickHandler;
+    private final LayoutInflater mLayoutInflater;
+
+    SearchResultAdapter(LayoutInflater inflater) {
+        super();
+        mLayoutInflater = inflater;
+    }
 
     @Override
     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-        LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-        return new ViewHolder(SearchItemBinding.inflate(inflater, parent, false));
+        return new ViewHolder(SearchItemBinding.inflate(mLayoutInflater, parent, false));
     }
 
     @Override
@@ -43,13 +48,10 @@ public class SearchResultAdapter extends RecyclerView.Adapter<SearchResultAdapte
         return mDataList == null ? 0 : mDataList.length;
     }
 
-    public class ViewHolder extends RecyclerView.ViewHolder {
-
-        public SearchItemBinding binding;
+    public class ViewHolder extends SelectorViewHolder<SearchItemBinding> {
 
         public ViewHolder(SearchItemBinding binding) {
-            super(binding.getRoot());
-            this.binding = binding;
+            super(binding);
             binding.setHolder(this);
             binding.setHandler(mClickHandler);
         }



More information about the Android mailing list