[Android] Prevent search with too short queries

Geoffrey Métais git at videolan.org
Thu Apr 4 18:43:24 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr  4 18:41:17 2019 +0200| [b92107fdc423e9fe9ea745b2f133792dd28eb6ec] | committer: Geoffrey Métais

Prevent search with too short queries

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

 vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt  |  2 +-
 vlc-android/src/org/videolan/vlc/gui/SearchActivity.java  | 14 ++++++++------
 vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt |  1 +
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 6531654b1..007717ecf 100644
--- a/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -108,7 +108,7 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
                 vsp.isGenreFocus -> items = playbackService.medialibrary.searchGenre(vsp.genre)
                 vsp.isSongFocus -> tracks = playbackService.medialibrary.searchMedia(vsp.song)!!
             }
-            if (Tools.isArrayEmpty(tracks)) playbackService.medialibrary.search(query)?.run {
+            if (Tools.isArrayEmpty(tracks) && query !== null && query.length > 2) playbackService.medialibrary.search(query)?.run {
                 when {
                     !Tools.isArrayEmpty(albums) -> tracks = albums[0].tracks
                     !Tools.isArrayEmpty(artists) -> tracks = artists[0].tracks
diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
index 9cb034028..8c0e32898 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
@@ -5,13 +5,7 @@ import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import androidx.databinding.DataBindingUtil;
 import android.os.Bundle;
-import androidx.annotation.Nullable;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
@@ -33,6 +27,13 @@ import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.util.Settings;
 import org.videolan.vlc.util.WorkersKt;
 
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.databinding.DataBindingUtil;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
 public class SearchActivity extends AppCompatActivity implements TextWatcher, TextView.OnEditorActionListener {
 
     public final static String TAG = "VLC/SearchActivity";
@@ -68,6 +69,7 @@ public class SearchActivity extends AppCompatActivity implements TextWatcher, Te
     }
 
     private void performSearh(final String query) {
+        if (query == null || query.length() < 3) return;
         WorkersKt.runIO(new Runnable() {
             @Override
             public void run() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
index 319160fcc..856e18f1f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
@@ -78,6 +78,7 @@ class SearchFragment : SearchSupportFragment(), SearchSupportFragment.SearchResu
     }
 
     private fun loadRows(query: String?) = coroutineScope.launch {
+        if (query == null || query.length < 3) return at launch
         val searchAggregate = context?.getFromMl { search(query) }
         val empty = searchAggregate == null || searchAggregate.isEmpty
         updateEmtyView(empty)



More information about the Android mailing list