reactive the previous way of searching folders

This commit is contained in:
tibbi 2019-07-09 21:54:53 +02:00
parent 4ae5e4623e
commit dfcecb31bf
3 changed files with 56 additions and 2 deletions

View file

@ -36,6 +36,14 @@
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:resizeableActivity="true"> android:resizeableActivity="true">
<meta-data
android:name="android.app.default_searchable"
android:resource="@xml/searchable"/>
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.PICK"/> <action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>

View file

@ -1,7 +1,9 @@
package com.simplemobiletools.gallery.pro.activities package com.simplemobiletools.gallery.pro.activities
import android.app.Activity import android.app.Activity
import android.app.SearchManager
import android.content.ClipData import android.content.ClipData
import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
@ -12,6 +14,8 @@ import android.view.MenuItem
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog
@ -61,6 +65,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private var mIsPasswordProtectionPending = false private var mIsPasswordProtectionPending = false
private var mWasProtectionHandled = false private var mWasProtectionHandled = false
private var mShouldStopFetching = false private var mShouldStopFetching = false
private var mIsSearchOpen = false
private var mLatestMediaId = 0L private var mLatestMediaId = 0L
private var mLatestMediaDateId = 0L private var mLatestMediaDateId = 0L
private var mCurrentPathPrefix = "" // used at "Group direct subfolders" for navigation private var mCurrentPathPrefix = "" // used at "Group direct subfolders" for navigation
@ -68,6 +73,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private var mLastMediaHandler = Handler() private var mLastMediaHandler = Handler()
private var mTempShowHiddenHandler = Handler() private var mTempShowHiddenHandler = Handler()
private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null
private var mSearchMenuItem: MenuItem? = null
private var mDirs = ArrayList<Directory>() private var mDirs = ArrayList<Directory>()
private var mStoredAnimateGifs = true private var mStoredAnimateGifs = true
@ -218,6 +224,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
override fun onStop() { override fun onStop() {
super.onStop() super.onStop()
mSearchMenuItem?.collapseActionView()
if (config.temporarilyShowHidden || config.tempSkipDeleteConfirmation) { if (config.temporarilyShowHidden || config.tempSkipDeleteConfirmation) {
mTempShowHiddenHandler.postDelayed({ mTempShowHiddenHandler.postDelayed({
config.temporarilyShowHidden = false config.temporarilyShowHidden = false
@ -268,6 +276,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
findItem(R.id.reduce_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt > 1 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.hide_the_recycle_bin).isVisible = useBin && config.showRecycleBinAtFolders
findItem(R.id.show_the_recycle_bin).isVisible = useBin && !config.showRecycleBinAtFolders findItem(R.id.show_the_recycle_bin).isVisible = useBin && !config.showRecycleBinAtFolders
setupSearch(this)
} }
} }
@ -279,7 +288,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.search -> launchSearchActivity()
R.id.sort -> showSortingDialog() R.id.sort -> showSortingDialog()
R.id.filter -> showFilterMediaDialog() R.id.filter -> showFilterMediaDialog()
R.id.open_camera -> launchCamera() R.id.open_camera -> launchCamera()
@ -323,6 +331,43 @@ 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() { private fun startNewPhotoFetcher() {
if (isNougatPlus()) { if (isNougatPlus()) {
val photoFetcher = NewPhotoFetcher() val photoFetcher = NewPhotoFetcher()

View file

@ -5,7 +5,8 @@
android:id="@+id/search" android:id="@+id/search"
android:icon="@drawable/ic_search" android:icon="@drawable/ic_search"
android:title="@string/search" android:title="@string/search"
app:showAsAction="always"/> app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|always"/>
<item <item
android:id="@+id/open_camera" android:id="@+id/open_camera"
android:icon="@drawable/ic_camera" android:icon="@drawable/ic_camera"