[Android] Remove the filter char limit

Nicolas Pomepuy git at videolan.org
Wed Aug 3 15:07:43 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug  2 11:30:44 2022 +0200| [61f5b047b7dae848261c93f14f71e7d0455fc85c] | committer: Nicolas Pomepuy

Remove the filter char limit

Fixes #2078

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

 .../src/main/java/org/videolan/television/ui/SearchFragment.kt      | 4 ++--
 .../vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt        | 6 ++++--
 application/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt | 2 +-
 .../vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt | 2 +-
 application/vlc-android/src/org/videolan/vlc/gui/SearchActivity.kt  | 4 ++--
 application/vlc-android/src/org/videolan/vlc/util/FilterDelegate.kt | 2 +-
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/SearchFragment.kt b/application/television/src/main/java/org/videolan/television/ui/SearchFragment.kt
index 242b16162..c844b95d5 100644
--- a/application/television/src/main/java/org/videolan/television/ui/SearchFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/SearchFragment.kt
@@ -62,7 +62,7 @@ class SearchFragment : SearchSupportFragment(), SearchSupportFragment.SearchResu
     override fun getResultsAdapter() = rowsAdapter
 
     private fun queryByWords(words: String?) {
-        if (words == null || words.length < 3) return
+        if (words == null || words.isEmpty()) return
         rowsAdapter.clear()
         if (words.isNotEmpty()) loadRows(words)
     }
@@ -75,7 +75,7 @@ class SearchFragment : SearchSupportFragment(), SearchSupportFragment.SearchResu
     }
 
     private fun loadRows(query: String?) = lifecycleScope.launch {
-        if (query == null || query.length < 3) return at launch
+        if (query == null || query.isEmpty()) return at launch
         val searchAggregate = context?.getFromMl { search(query, Settings.includeMissing) }
         val empty = searchAggregate == null || searchAggregate.isEmpty
         updateEmtyView(empty)
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index d55d42eae..f0a4fcc84 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -33,7 +33,9 @@ import android.util.Log
 import android.view.KeyEvent
 import androidx.core.net.toUri
 import androidx.lifecycle.lifecycleScope
-import kotlinx.coroutines.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.isActive
+import kotlinx.coroutines.launch
 import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
@@ -295,7 +297,7 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
                 else -> null
             }
             if (!isActive) return at launch
-            if (tracks.isNullOrEmpty() && items.isNullOrEmpty() && query?.length ?: 0 > 2) {
+            if (tracks.isNullOrEmpty() && items.isNullOrEmpty() && query?.isNotEmpty() == true) {
                 playbackService.medialibrary.search(query, Settings.includeMissing)?.run {
                     tracks = when {
                         !albums.isNullOrEmpty() -> albums!!.flatMap { it.tracks.toList() }.toTypedArray()
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
index 6566fcd06..3aa8c006a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
@@ -135,7 +135,7 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
     override fun onQueryTextChange(filterQueryString: String): Boolean {
         val current = currentFragment
         if (current is Filterable) {
-            if (filterQueryString.length < 3)
+            if (filterQueryString.isEmpty())
                 (current as Filterable).restoreList()
             else
                 (current as Filterable).filter(filterQueryString)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index 40fe692c6..85b59146b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -509,7 +509,7 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
     override fun onQueryTextSubmit(query: String?) = false
 
     override fun onQueryTextChange(newText: String?): Boolean {
-        if (newText?.length ?: 0 < 3)
+        if (newText?.length  == 0)
             restoreList()
         else
             filter(newText ?: "")
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/SearchActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/SearchActivity.kt
index a73fc180c..c78d7c8c9 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/SearchActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/SearchActivity.kt
@@ -55,7 +55,7 @@ open class SearchActivity : BaseActivity(), TextWatcher, TextView.OnEditorAction
     }
 
     private fun performSearh(query: String?) {
-        if (query != null && query.length > 2) lifecycleScope.launchWhenStarted {
+        if (query != null && query.isNotEmpty()) lifecycleScope.launchWhenStarted {
             val searchAggregate = getFromMl { search(query, Settings.includeMissing) }
             binding.searchAggregate = searchAggregate
             searchAggregate?.let { result ->
@@ -86,7 +86,7 @@ open class SearchActivity : BaseActivity(), TextWatcher, TextView.OnEditorAction
     override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
 
     override fun afterTextChanged(s: Editable?) {
-        if (s == null || s.length < 3)
+        if (s == null || s.isEmpty())
             binding.searchAggregate = SearchAggregate()
         else
             performSearh(s.toString())
diff --git a/application/vlc-android/src/org/videolan/vlc/util/FilterDelegate.kt b/application/vlc-android/src/org/videolan/vlc/util/FilterDelegate.kt
index 1c0d9745c..8d6774ec8 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/FilterDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/FilterDelegate.kt
@@ -22,7 +22,7 @@ open class FilterDelegate<T : MediaLibraryItem>(protected val dataset: MutableLi
     protected open suspend fun filteringJob(charSequence: CharSequence?) : MutableList<T>? {
         if (charSequence !== null) initSource()?.let {
             return withContext(Dispatchers.Default) { mutableListOf<T>().apply {
-                val queryStrings = charSequence.trim().toString().split(" ").filter { it.length > 2 }
+                val queryStrings = charSequence.trim().toString().split(" ")
                 for (item in it) for (query in queryStrings)
                     if (item.title.contains(query, true)) {
                         this.add(item)



More information about the Android mailing list