mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
use the Search menu as the top bar
This commit is contained in:
@ -2,9 +2,7 @@ package com.simplemobiletools.filemanager.pro.activities
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
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.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
@ -13,12 +11,8 @@ import android.os.Bundle
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuItem
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.widget.SearchView
|
|
||||||
import androidx.core.view.MenuItemCompat
|
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
@ -54,12 +48,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
private val BACK_PRESS_TIMEOUT = 5000
|
private val BACK_PRESS_TIMEOUT = 5000
|
||||||
private val MANAGE_STORAGE_RC = 201
|
private val MANAGE_STORAGE_RC = 201
|
||||||
private val PICKED_PATH = "picked_path"
|
private val PICKED_PATH = "picked_path"
|
||||||
private var isSearchOpen = false
|
|
||||||
private var wasBackJustPressed = false
|
private var wasBackJustPressed = false
|
||||||
private var mIsPasswordProtectionPending = false
|
private var mIsPasswordProtectionPending = false
|
||||||
private var mWasProtectionHandled = false
|
private var mWasProtectionHandled = false
|
||||||
private var mTabsToShow = ArrayList<Int>()
|
private var mTabsToShow = ArrayList<Int>()
|
||||||
private var mSearchMenuItem: MenuItem? = null
|
|
||||||
|
|
||||||
private var mStoredFontSize = 0
|
private var mStoredFontSize = 0
|
||||||
private var mStoredDateFormat = ""
|
private var mStoredDateFormat = ""
|
||||||
@ -86,7 +78,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
setupTabs()
|
setupTabs()
|
||||||
|
|
||||||
updateMaterialActivityViews(main_coordinator, null, useTransparentNavigation = false, useTopSearchMenu = true)
|
updateMaterialActivityViews(main_coordinator, null, useTransparentNavigation = false, useTopSearchMenu = true)
|
||||||
setupMaterialScrollListener(null, main_toolbar)
|
|
||||||
|
|
||||||
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
||||||
|
|
||||||
@ -116,6 +107,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshMenuItems()
|
refreshMenuItems()
|
||||||
|
updateMenuColors()
|
||||||
setupTabColors()
|
setupTabColors()
|
||||||
|
|
||||||
getAllFragments().forEach {
|
getAllFragments().forEach {
|
||||||
@ -156,7 +148,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
val currentViewType = config.getFolderViewType(currentFragment.currentPath)
|
val currentViewType = config.getFolderViewType(currentFragment.currentPath)
|
||||||
val favorites = config.favorites
|
val favorites = config.favorites
|
||||||
|
|
||||||
main_toolbar.menu.apply {
|
main_menu.getToolbar().menu.apply {
|
||||||
findItem(R.id.sort).isVisible = currentFragment is ItemsFragment
|
findItem(R.id.sort).isVisible = currentFragment is ItemsFragment
|
||||||
findItem(R.id.change_view_type).isVisible = currentFragment !is StorageFragment
|
findItem(R.id.change_view_type).isVisible = currentFragment !is StorageFragment
|
||||||
|
|
||||||
@ -182,8 +174,25 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOptionsMenu() {
|
private fun setupOptionsMenu() {
|
||||||
setupSearch(main_toolbar.menu)
|
main_menu.getToolbar().inflateMenu(R.menu.menu)
|
||||||
main_toolbar.setOnMenuItemClickListener { menuItem ->
|
main_menu.toggleHideOnScroll(false)
|
||||||
|
main_menu.setupMenu()
|
||||||
|
|
||||||
|
main_menu.onSearchOpenListener = {
|
||||||
|
(getCurrentFragment() as? ItemsFragment)?.searchOpened()
|
||||||
|
}
|
||||||
|
|
||||||
|
main_menu.onSearchClosedListener = {
|
||||||
|
getAllFragments().forEach {
|
||||||
|
(it as? ItemOperationsListener)?.searchQueryChanged("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main_menu.onSearchTextChangedListener = { text ->
|
||||||
|
(getCurrentFragment() as? ItemOperationsListener)?.searchQueryChanged(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
main_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
|
||||||
if (getCurrentFragment() == null) {
|
if (getCurrentFragment() == null) {
|
||||||
return@setOnMenuItemClickListener true
|
return@setOnMenuItemClickListener true
|
||||||
}
|
}
|
||||||
@ -255,38 +264,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSearch(menu: Menu) {
|
private fun updateMenuColors() {
|
||||||
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
updateStatusbarColor(getProperBackgroundColor())
|
||||||
mSearchMenuItem = menu.findItem(R.id.search)
|
main_menu.updateColors()
|
||||||
(mSearchMenuItem!!.actionView as SearchView).apply {
|
|
||||||
setSearchableInfo(searchManager.getSearchableInfo(componentName))
|
|
||||||
isSubmitButtonEnabled = false
|
|
||||||
queryHint = getString(R.string.search)
|
|
||||||
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
|
||||||
override fun onQueryTextSubmit(query: String) = false
|
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
|
||||||
if (isSearchOpen) {
|
|
||||||
(getCurrentFragment() as? ItemOperationsListener)?.searchQueryChanged(newText)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
|
||||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
|
||||||
isSearchOpen = true
|
|
||||||
(getCurrentFragment() as? ItemsFragment)?.searchOpened()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
|
||||||
isSearchOpen = false
|
|
||||||
(getCurrentFragment() as? ItemsFragment)?.searchClosed()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
private fun storeStateVariables() {
|
||||||
@ -462,7 +442,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
|
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
|
||||||
},
|
},
|
||||||
tabSelectedAction = {
|
tabSelectedAction = {
|
||||||
closeSearch()
|
main_menu.closeSearch()
|
||||||
main_view_pager.currentItem = it.position
|
main_view_pager.currentItem = it.position
|
||||||
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
|
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
|
||||||
}
|
}
|
||||||
@ -516,15 +496,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun closeSearch() {
|
|
||||||
if (isSearchOpen) {
|
|
||||||
getAllFragments().forEach {
|
|
||||||
(it as? ItemOperationsListener)?.searchQueryChanged("")
|
|
||||||
}
|
|
||||||
mSearchMenuItem?.collapseActionView()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun openPath(path: String, forceRefresh: Boolean = false) {
|
private fun openPath(path: String, forceRefresh: Boolean = false) {
|
||||||
if (mIsPasswordProtectionPending && !mWasProtectionHandled) {
|
if (mIsPasswordProtectionPending && !mWasProtectionHandled) {
|
||||||
return
|
return
|
||||||
@ -632,12 +603,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun launchSettings() {
|
private fun launchSettings() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
closeSearch()
|
|
||||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchAbout() {
|
private fun launchAbout() {
|
||||||
closeSearch()
|
|
||||||
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEW_PAGER or LICENSE_AUTOFITTEXTVIEW
|
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEW_PAGER or LICENSE_AUTOFITTEXTVIEW
|
||||||
|
|
||||||
val faqItems = arrayListOf(
|
val faqItems = arrayListOf(
|
||||||
@ -661,8 +630,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSearchOpen && mSearchMenuItem != null) {
|
if (main_menu.isSearchOpen) {
|
||||||
mSearchMenuItem!!.collapseActionView()
|
main_menu.closeSearch()
|
||||||
} else if (getCurrentFragment()!!.breadcrumbs.getItemCount() <= 1) {
|
} else if (getCurrentFragment()!!.breadcrumbs.getItemCount() <= 1) {
|
||||||
if (!wasBackJustPressed && config.pressBackTwice) {
|
if (!wasBackJustPressed && config.pressBackTwice) {
|
||||||
wasBackJustPressed = true
|
wasBackJustPressed = true
|
||||||
@ -761,8 +730,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun openedDirectory() {
|
fun openedDirectory() {
|
||||||
if (mSearchMenuItem != null) {
|
if (main_menu.isSearchOpen) {
|
||||||
MenuItemCompat.collapseActionView(mSearchMenuItem)
|
main_menu.closeSearch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,16 +80,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
|
|||||||
val currentViewType = config.getFolderViewType(currentMimeType)
|
val currentViewType = config.getFolderViewType(currentMimeType)
|
||||||
|
|
||||||
mimetypes_toolbar.menu.apply {
|
mimetypes_toolbar.menu.apply {
|
||||||
findItem(R.id.add_favorite).isVisible = false
|
|
||||||
findItem(R.id.remove_favorite).isVisible = false
|
|
||||||
findItem(R.id.go_to_favorite).isVisible = false
|
|
||||||
|
|
||||||
findItem(R.id.toggle_filename).isVisible = currentViewType == VIEW_TYPE_GRID
|
findItem(R.id.toggle_filename).isVisible = currentViewType == VIEW_TYPE_GRID
|
||||||
findItem(R.id.go_home).isVisible = false
|
|
||||||
findItem(R.id.set_as_home).isVisible = false
|
|
||||||
findItem(R.id.more_apps_from_us).isVisible = false
|
|
||||||
findItem(R.id.settings).isVisible = false
|
|
||||||
findItem(R.id.about).isVisible = false
|
|
||||||
|
|
||||||
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
|
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
|
||||||
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
|
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
|
||||||
|
@ -5,13 +5,10 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
<com.simplemobiletools.commons.views.MySearchMenu
|
||||||
android:id="@+id/main_toolbar"
|
android:id="@+id/main_menu"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="wrap_content" />
|
||||||
android:background="@color/color_primary"
|
|
||||||
app:menu="@menu/menu"
|
|
||||||
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/main_holder"
|
android:id="@+id/main_holder"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:background="@color/color_primary"
|
android:background="@color/color_primary"
|
||||||
app:menu="@menu/menu"
|
app:menu="@menu/menu_mimetypes"
|
||||||
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -3,12 +3,6 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:ignore="AppCompatResource">
|
tools:ignore="AppCompatResource">
|
||||||
<item
|
|
||||||
android:id="@+id/search"
|
|
||||||
android:icon="@drawable/ic_search_vector"
|
|
||||||
android:title="@string/search"
|
|
||||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
|
||||||
app:showAsAction="collapseActionView|always" />
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/go_home"
|
android:id="@+id/go_home"
|
||||||
android:icon="@drawable/ic_home_vector"
|
android:icon="@drawable/ic_home_vector"
|
||||||
|
47
app/src/main/res/menu/menu_mimetypes.xml
Normal file
47
app/src/main/res/menu/menu_mimetypes.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?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"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:ignore="AppCompatResource">
|
||||||
|
<item
|
||||||
|
android:id="@+id/search"
|
||||||
|
android:icon="@drawable/ic_search_vector"
|
||||||
|
android:title="@string/search"
|
||||||
|
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||||
|
app:showAsAction="collapseActionView|always" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/sort"
|
||||||
|
android:icon="@drawable/ic_sort_vector"
|
||||||
|
android:title="@string/sort_by"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/toggle_filename"
|
||||||
|
android:icon="@drawable/ic_label_vector"
|
||||||
|
android:title="@string/toggle_filename"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/change_view_type"
|
||||||
|
android:icon="@drawable/ic_change_view_vector"
|
||||||
|
android:title="@string/change_view_type"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/temporarily_show_hidden"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/temporarily_show_hidden"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/stop_showing_hidden"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/stop_showing_hidden"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/increase_column_count"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/increase_column_count"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/reduce_column_count"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/reduce_column_count"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
</menu>
|
Reference in New Issue
Block a user