From f82550ae34c1d2490964e18d71b66feb72edb63d Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 5 Feb 2018 10:23:38 +0100 Subject: [PATCH] call searchQueryChanged only when search is open --- .../gallery/activities/MediaActivity.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 97becbd1c..ca0e06ed0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -9,6 +9,7 @@ import android.graphics.Bitmap import android.net.Uri import android.os.Bundle import android.os.Handler +import android.support.v4.view.MenuItemCompat import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.SearchView import android.view.Menu @@ -52,6 +53,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mAllowPickingMultiple = false private var mShowAll = false private var mLoadedInitialPhotos = false + private var mIsSearchOpen = false private var mLatestMediaId = 0L private var mLastMediaHandler = Handler() private var mTempShowHiddenHandler = Handler() @@ -240,11 +242,25 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun onQueryTextSubmit(query: String) = false override fun onQueryTextChange(newText: String): Boolean { - searchQueryChanged(newText) + if (mIsSearchOpen) { + searchQueryChanged(newText) + } return true } }) } + + MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, object : MenuItemCompat.OnActionExpandListener { + override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + mIsSearchOpen = true + return true + } + + override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + mIsSearchOpen = false + return true + } + }) } private fun searchQueryChanged(text: String) {