[Android] TV: Handle search if Medialibrary is initializing

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


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr  5 14:10:07 2017 +0200| [ff0cdba1eb1bad40e8334b504475c211d111ed74] | committer: Geoffrey Métais

TV: Handle search if Medialibrary is initializing

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

 .../src/org/videolan/vlc/gui/tv/SearchFragment.java  | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.java
index e6b212c..9770454 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.java
@@ -22,6 +22,10 @@ package org.videolan.vlc.gui.tv;
 
 import android.annotation.TargetApi;
 import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
@@ -34,6 +38,7 @@ import android.support.v17.leanback.widget.OnItemViewClickedListener;
 import android.support.v17.leanback.widget.Presenter;
 import android.support.v17.leanback.widget.Row;
 import android.support.v17.leanback.widget.RowPresenter;
+import android.support.v4.content.LocalBroadcastManager;
 import android.text.TextUtils;
 
 import org.videolan.medialibrary.media.MediaLibraryItem;
@@ -77,9 +82,22 @@ public class SearchFragment extends android.support.v17.leanback.app.SearchFragm
         mRowsAdapter.clear();
         if (!TextUtils.isEmpty(words) && words.length() > 2) {
             mDelayedLoad.setSearchQuery(words);
-            VLCApplication.runBackground(mDelayedLoad);
+            if (VLCApplication.getMLInstance().isInitiated())
+                VLCApplication.runBackground(mDelayedLoad);
+            else
+                setupMediaLibraryReceiver();
         }
     }
+    protected void setupMediaLibraryReceiver() {
+        final BroadcastReceiver libraryReadyReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(this);
+                VLCApplication.runBackground(mDelayedLoad);
+            }
+        };
+        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(libraryReadyReceiver, new IntentFilter(VLCApplication.ACTION_MEDIALIBRARY_READY));
+    }
 
     @Override
     public boolean onQueryTextChange(String newQuery) {



More information about the Android mailing list