[Android] Reopen searchview on tab change for the audio screen

Nicolas Pomepuy git at videolan.org
Mon Mar 29 05:56:51 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Mar 26 10:59:28 2021 +0100| [c1ec13a9b24d929afeb9d36fe7db36c7e6f167ad] | committer: Nicolas Pomepuy

Reopen searchview on tab change for the audio screen

Fixes #1829

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

 .../src/org/videolan/vlc/gui/ContentActivity.kt           | 14 ++++++++++++++
 .../videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt    |  1 +
 .../org/videolan/vlc/gui/audio/AudioBrowserFragment.kt    |  1 +
 .../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt    | 15 ++++++++++++++-
 4 files changed, 30 insertions(+), 1 deletion(-)

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 43a0c31c5..aa3e87ec9 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
@@ -201,6 +201,20 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
         toolbar.menu?.findItem(R.id.ml_menu_filter)?.collapseActionView()
     }
 
+    fun openSearchView() {
+        toolbar.menu?.findItem(R.id.ml_menu_filter)?.expandActionView()
+    }
+
+    fun isSearchViewVisible() =
+        toolbar.menu?.findItem(R.id.ml_menu_filter)?.isActionViewExpanded ?: false
+
+    fun getCurrentQuery() = searchView.query.toString()
+
+    fun setCurrentQuery(query:String) {
+        searchView.setQuery(query, false)
+    }
+
+
     private fun restoreCurrentList() {
         (currentFragment as? Filterable)?.restoreList()
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
index 96d3b3db0..e65e5b49d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
@@ -185,6 +185,7 @@ class AudioAlbumsSongsFragment : BaseAudioBrowser<AlbumSongsViewModel>(), SwipeR
             menu.findItem(R.id.ml_menu_sortby_media_number).isVisible = canSortByMediaNumber()
         }
         sortMenuTitles()
+        reopenSearchIfNeeded()
     }
 
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
index 357b53014..ee36a9d80 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -242,6 +242,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
             showAllArtistsItem.isChecked = Settings.getInstance(context).getBoolean(KEY_ARTISTS_SHOW_ALL, false)
         }
         sortMenuTitles()
+        reopenSearchIfNeeded()
     }
 
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index c8072f117..78d1e55a6 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -88,6 +88,9 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
 
     open fun getCurrentAdapter() = adapter
 
+    var needToReopenSearch = false
+    var lastQuery = ""
+
     protected var currentTab
         get() = if (::viewPager.isInitialized) viewPager.currentItem else 0
         set(value) {
@@ -214,7 +217,8 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
 
     override fun onTabUnselected(tab: TabLayout.Tab) {
         stopActionMode()
-        (activity as? ContentActivity)?.closeSearchView()
+        needToReopenSearch = (activity as? ContentActivity)?.isSearchViewVisible() ?: false
+        lastQuery = (activity as? ContentActivity)?.getCurrentQuery() as String
     }
 
     override fun onTabReselected(tab: TabLayout.Tab) {}
@@ -268,6 +272,15 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
         return true
     }
 
+    fun reopenSearchIfNeeded() {
+        if (needToReopenSearch) {
+            (activity as? ContentActivity)?.openSearchView()
+            (activity as? ContentActivity)?.setCurrentQuery(lastQuery)
+            lastQuery = ""
+            needToReopenSearch = false
+        }
+    }
+
     override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
         if (!isStarted()) return false
         val list = getCurrentAdapter()?.multiSelectHelper?.getSelection()



More information about the Android mailing list