[Android] Factorize adapters LayoutInflater

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


vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov  2 15:41:27 2017 +0100| [3582518cbbf8f6c54679fc906e07d4e6a4df98a1] | committer: Geoffrey Métais

Factorize adapters LayoutInflater

(cherry picked from commit 95bcf6579833efa82d3e693293a93a6b1a737bf4)

> https://code.videolan.org/videolan/vlc-android/commit/3582518cbbf8f6c54679fc906e07d4e6a4df98a1
---

 vlc-android/src/org/videolan/vlc/gui/SearchActivity.java | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
index a2a768c5a..1dd3cd9f0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
@@ -17,6 +17,7 @@ import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.view.KeyEvent;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.WindowManager;
 import android.view.inputmethod.EditorInfo;
@@ -45,12 +46,12 @@ public class SearchActivity extends AppCompatActivity implements TextWatcher, Te
         super.onCreate(savedInstanceState);
         if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("enable_black_theme", false))
             setTheme(R.style.Theme_VLC_Black);
-        Intent intent = getIntent();
+        final Intent intent = getIntent();
+        mBinding = DataBindingUtil.setContentView(this, R.layout.search_activity);
+        mBinding.setHandler(mClickHandler);
+        mMedialibrary = VLCApplication.getMLInstance();
         if (Intent.ACTION_SEARCH.equals(intent.getAction()) || "com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) {
-            mBinding = DataBindingUtil.setContentView(this, R.layout.search_activity);
-            mBinding.setHandler(mClickHandler);
-            mMedialibrary = VLCApplication.getMLInstance();
-            String query = intent.getStringExtra(SearchManager.QUERY);
+            final String query = intent.getStringExtra(SearchManager.QUERY);
             initializeLists();
             if (!TextUtils.isEmpty(query)) {
                 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
@@ -93,10 +94,11 @@ public class SearchActivity extends AppCompatActivity implements TextWatcher, Te
 
     private void initializeLists() {
         int count = mBinding.resultsContainer.getChildCount();
+        final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         for (int i = 0; i < count; ++i) {
             View v = mBinding.resultsContainer.getChildAt(i);
             if (v instanceof ContextMenuRecyclerView) {
-                ((RecyclerView)v).setAdapter(new SearchResultAdapter());
+                ((RecyclerView)v).setAdapter(new SearchResultAdapter(inflater));
                 ((RecyclerView)v).setLayoutManager(new LinearLayoutManager(this));
                 ((SearchResultAdapter)((RecyclerView)v).getAdapter()).setClickHandler(mClickHandler);
             }



More information about the Android mailing list