diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index aa2a48308..25f4250ff 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -36,14 +36,6 @@
android:name=".activities.MainActivity"
android:resizeableActivity="true">
-
-
-
-
-
-
@@ -81,6 +73,21 @@
+
+
+
+
+
+
+
+
+
()
private var mStoredAnimateGifs = true
@@ -224,8 +218,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
override fun onStop() {
super.onStop()
- mSearchMenuItem?.collapseActionView()
-
if (config.temporarilyShowHidden || config.tempSkipDeleteConfirmation) {
mTempShowHiddenHandler.postDelayed({
config.temporarilyShowHidden = false
@@ -276,7 +268,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
findItem(R.id.reduce_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt > 1
findItem(R.id.hide_the_recycle_bin).isVisible = useBin && config.showRecycleBinAtFolders
findItem(R.id.show_the_recycle_bin).isVisible = useBin && !config.showRecycleBinAtFolders
- setupSearch(this)
}
}
@@ -288,6 +279,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
+ R.id.search -> launchSearchActivity()
R.id.sort -> showSortingDialog()
R.id.filter -> showFilterMediaDialog()
R.id.open_camera -> launchCamera()
@@ -331,43 +323,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
}
}
- private fun setupSearch(menu: Menu) {
- val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
- mSearchMenuItem = menu.findItem(R.id.search)
- (mSearchMenuItem?.actionView as? SearchView)?.apply {
- setSearchableInfo(searchManager.getSearchableInfo(componentName))
- isSubmitButtonEnabled = false
- setOnQueryTextListener(object : SearchView.OnQueryTextListener {
- override fun onQueryTextSubmit(query: String) = false
-
- override fun onQueryTextChange(newText: String): Boolean {
- if (mIsSearchOpen) {
- setupAdapter(mDirs, newText)
- }
- return true
- }
- })
- }
-
- MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, object : MenuItemCompat.OnActionExpandListener {
- override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
- mIsSearchOpen = true
- directories_refresh_layout.isEnabled = false
- return true
- }
-
- // this triggers on device rotation too, avoid doing anything
- override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
- if (mIsSearchOpen) {
- mIsSearchOpen = false
- directories_refresh_layout.isEnabled = config.enablePullToRefresh
- setupAdapter(mDirs, "")
- }
- return true
- }
- })
- }
-
private fun startNewPhotoFetcher() {
if (isNougatPlus()) {
val photoFetcher = NewPhotoFetcher()
@@ -467,6 +422,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
}
}
+ private fun launchSearchActivity() {
+ Intent(this, SearchActivity::class.java).apply {
+ startActivity(this)
+ }
+ }
+
private fun showSortingDialog() {
ChangeSortingDialog(this, true, false) {
directories_grid.adapter = null
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt
new file mode 100644
index 000000000..d0fb5c1c9
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SearchActivity.kt
@@ -0,0 +1,59 @@
+package com.simplemobiletools.gallery.pro.activities
+
+import android.app.SearchManager
+import android.content.Context
+import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
+import androidx.appcompat.widget.SearchView
+import androidx.core.view.MenuItemCompat
+import com.simplemobiletools.gallery.pro.R
+
+class SearchActivity : SimpleActivity() {
+ private var mIsSearchOpen = false
+ private var mSearchMenuItem: MenuItem? = null
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_search)
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mSearchMenuItem?.collapseActionView()
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.menu_search, menu)
+ setupSearch(menu)
+ return true
+ }
+
+ private fun setupSearch(menu: Menu) {
+ val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
+ mSearchMenuItem = menu.findItem(R.id.search)
+ (mSearchMenuItem?.actionView as? SearchView)?.apply {
+ setSearchableInfo(searchManager.getSearchableInfo(componentName))
+ isSubmitButtonEnabled = false
+ setOnQueryTextListener(object : SearchView.OnQueryTextListener {
+ override fun onQueryTextSubmit(query: String) = false
+
+ override fun onQueryTextChange(newText: String): Boolean {
+ return true
+ }
+ })
+ }
+
+ MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, object : MenuItemCompat.OnActionExpandListener {
+ override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
+ return true
+ }
+
+ // this triggers on device rotation too, avoid doing anything
+ override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
+ return true
+ }
+ })
+ mSearchMenuItem?.expandActionView()
+ }
+}
diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml
new file mode 100644
index 000000000..852cec099
--- /dev/null
+++ b/app/src/main/res/layout/activity_search.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index 1de075c0c..0d9b32e12 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -5,8 +5,7 @@
android:id="@+id/search"
android:icon="@drawable/ic_search"
android:title="@string/search"
- app:actionViewClass="androidx.appcompat.widget.SearchView"
- app:showAsAction="collapseActionView|ifRoom"/>
+ app:showAsAction="always"/>
-
+