[Android] Hide all menu items when launching a search + restore

Nicolas Pomepuy git at videolan.org
Mon Jul 29 16:37:13 CEST 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon Jul 29 08:38:46 2019 +0200| [dd14d8a27bd9b928ed7f0e37f9925b829556cc7b] | committer: Geoffrey Métais

Hide all menu items when launching a search + restore

(cherry picked from commit 039a770a761489d51b9acb7d895ff021077a761a)

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

 .../src/org/videolan/vlc/gui/ContentActivity.kt    | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
index 2d83f7dcc..2f66409b9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
@@ -31,7 +31,6 @@ import android.view.Menu
 import android.view.MenuItem
 import android.view.View
 import androidx.appcompat.widget.SearchView
-import androidx.fragment.app.Fragment
 import androidx.lifecycle.Observer
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
@@ -39,13 +38,9 @@ import org.videolan.libvlc.RendererItem
 import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
 import org.videolan.vlc.RendererDelegate
-import org.videolan.vlc.gui.audio.AudioBrowserFragment
 import org.videolan.vlc.gui.browser.ExtensionBrowser
-import org.videolan.vlc.gui.browser.MediaBrowserFragment
 import org.videolan.vlc.gui.dialogs.RenderersDialog
-import org.videolan.vlc.gui.folders.FoldersFragment
 import org.videolan.vlc.gui.helpers.UiTools
-import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.interfaces.Filterable
 import org.videolan.vlc.util.AndroidDevices
 import org.videolan.vlc.util.Settings
@@ -58,6 +53,8 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
 
     private lateinit var searchView: SearchView
     private var showRenderers = !AndroidDevices.isChromeBook && !Util.isListEmpty(RendererDelegate.renderers.value)
+    private val searchHiddenMenuItem = ArrayList<MenuItem>()
+
 
     override fun initAudioPlayerContainerActivity() {
         super.initAudioPlayerContainerActivity()
@@ -172,22 +169,25 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
         val current = currentFragment
         if (current is Filterable) {
             (current as Filterable).setSearchVisibility(visible)
-            makeRoomForSearch(current, visible)
+            makeRoomForSearch(visible)
         }
     }
 
     // Hide options menu items to make room for filter EditText
-    private fun makeRoomForSearch(current: Fragment, hide: Boolean) {
+    private fun makeRoomForSearch(hide: Boolean) {
         val menu = toolbar.menu
-        val renderersItem = menu.findItem(R.id.ml_menu_renderers)
-        if (renderersItem != null) renderersItem.isVisible = !hide && showRenderers
-        if (current is MediaBrowserFragment<*>) {
-            menu.findItem(R.id.ml_menu_sortby)?.isVisible = !hide && current.viewModel.canSortByName()
-        }
-        if (current is VideoGridFragment || current is AudioBrowserFragment
-                || current is FoldersFragment) {
-            val lastItem = menu.findItem(R.id.ml_menu_last_playlist)
-            if (lastItem != null) lastItem.isVisible = !hide
+        if (!hide) {
+            searchHiddenMenuItem.forEach {
+                it.isVisible = true
+            }
+        } else {
+            for (i in 0 until menu.size()) {
+                val menuItem = menu.getItem(i)
+                if (menuItem.isVisible) {
+                    menuItem.isVisible = false
+                    searchHiddenMenuItem.add(menuItem)
+                }
+            }
         }
     }
 



More information about the Android mailing list