start migrating search related functionality into SearchActivity
This commit is contained in:
parent
58ba160571
commit
6ee3f04d8f
6 changed files with 163 additions and 56 deletions
|
@ -36,14 +36,6 @@
|
||||||
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"/>
|
||||||
|
@ -81,6 +73,21 @@
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SearchActivity"
|
||||||
|
android:label="@string/search"
|
||||||
|
android:parentActivityName=".activities.MainActivity"
|
||||||
|
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>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.ViewPagerActivity"
|
android:name=".activities.ViewPagerActivity"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
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
|
||||||
|
@ -14,8 +12,6 @@ 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
|
||||||
|
@ -65,7 +61,6 @@ 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
|
||||||
|
@ -73,7 +68,6 @@ 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
|
||||||
|
@ -224,8 +218,6 @@ 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
|
||||||
|
@ -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.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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,6 +279,7 @@ 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()
|
||||||
|
@ -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() {
|
private fun startNewPhotoFetcher() {
|
||||||
if (isNougatPlus()) {
|
if (isNougatPlus()) {
|
||||||
val photoFetcher = NewPhotoFetcher()
|
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() {
|
private fun showSortingDialog() {
|
||||||
ChangeSortingDialog(this, true, false) {
|
ChangeSortingDialog(this, true, false) {
|
||||||
directories_grid.adapter = null
|
directories_grid.adapter = null
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
71
app/src/main/res/layout/activity_search.xml
Normal file
71
app/src/main/res/layout/activity_search.xml
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/media_refresh_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/media_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/media_empty_text_label"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingLeft="@dimen/big_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingRight="@dimen/big_margin"
|
||||||
|
android:text="@string/no_media_with_filters"
|
||||||
|
android:textSize="@dimen/bigger_text_size"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/media_empty_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/media_empty_text_label"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:padding="@dimen/activity_margin"
|
||||||
|
android:text="@string/change_filters_underlined"
|
||||||
|
android:textSize="@dimen/bigger_text_size"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/media_grid"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scrollbars="none"
|
||||||
|
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
|
||||||
|
app:spanCount="@integer/media_columns_vertical_scroll"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.FastScroller
|
||||||
|
android:id="@+id/media_vertical_fastscroller"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:paddingStart="@dimen/normal_margin"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.FastScroller>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.FastScroller
|
||||||
|
android:id="@+id/media_horizontal_fastscroller"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:paddingTop="@dimen/normal_margin"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<include layout="@layout/fastscroller_handle_horizontal"/>
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.FastScroller>
|
||||||
|
</RelativeLayout>
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
|
@ -5,8 +5,7 @@
|
||||||
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:actionViewClass="androidx.appcompat.widget.SearchView"
|
app:showAsAction="always"/>
|
||||||
app:showAsAction="collapseActionView|ifRoom"/>
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/open_camera"
|
android:id="@+id/open_camera"
|
||||||
android:icon="@drawable/ic_camera"
|
android:icon="@drawable/ic_camera"
|
||||||
|
|
10
app/src/main/res/menu/menu_search.xml
Normal file
10
app/src/main/res/menu/menu_search.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/search"
|
||||||
|
android:icon="@drawable/ic_search"
|
||||||
|
android:title="@string/search"
|
||||||
|
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||||
|
app:showAsAction="collapseActionView|ifRoom"/>
|
||||||
|
</menu>
|
Loading…
Reference in a new issue