[Android] Handle search if Medialibrary is initializing

Geoffrey Métais git at videolan.org
Wed Apr 5 14:01:09 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr  5 12:02:20 2017 +0200| [6312d961f8a6fd45f7b0c48db8f9767c7b67baab] | committer: Geoffrey Métais

Handle search if Medialibrary is initializing

> https://code.videolan.org/videolan/vlc-android/commit/6312d961f8a6fd45f7b0c48db8f9767c7b67baab
---

 .../src/org/videolan/vlc/gui/SearchActivity.java   | 26 +++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
index a876320..b009fa1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
@@ -1,11 +1,15 @@
 package org.videolan.vlc.gui;
 
 import android.app.SearchManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.databinding.DataBindingUtil;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.annotation.Nullable;
+import android.support.v4.content.LocalBroadcastManager;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
@@ -14,6 +18,7 @@ import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.view.KeyEvent;
 import android.view.View;
+import android.view.WindowManager;
 import android.view.inputmethod.EditorInfo;
 import android.widget.TextView;
 
@@ -48,9 +53,12 @@ public class SearchActivity extends AppCompatActivity implements TextWatcher, Te
             String query = intent.getStringExtra(SearchManager.QUERY);
             initializeLists();
             if (!TextUtils.isEmpty(query)) {
-                mBinding.searchEditText.setText(query);
-                mBinding.searchEditText.setSelection(query.length());
-                performSearh(query);
+                if (mMedialibrary.isInitiated()) {
+                    mBinding.searchEditText.setText(query);
+                    mBinding.searchEditText.setSelection(query.length());
+                    performSearh(query);
+                } else
+                    setupMediaLibraryReceiver(query);
             }
         }
         mBinding.searchEditText.addTextChangedListener(this);
@@ -136,4 +144,16 @@ public class SearchActivity extends AppCompatActivity implements TextWatcher, Te
             finish();
         }
     }
+    protected void setupMediaLibraryReceiver(final String query) {
+        final BroadcastReceiver libraryReadyReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                LocalBroadcastManager.getInstance(SearchActivity.this).unregisterReceiver(this);
+                mBinding.searchEditText.setText(query);
+                mBinding.searchEditText.setSelection(query.length());
+                performSearh(query);
+            }
+        };
+        LocalBroadcastManager.getInstance(this).registerReceiver(libraryReadyReceiver, new IntentFilter(VLCApplication.ACTION_MEDIALIBRARY_READY));
+    }
 }



More information about the Android mailing list