adding initial search menu on the main screen

This commit is contained in:
tibbi 2023-01-09 23:03:00 +01:00
parent a15ff47313
commit f6b563d0bc
3 changed files with 20 additions and 31 deletions

View file

@ -87,6 +87,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private var mStoredStyleString = "" private var mStoredStyleString = ""
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
appLaunched(BuildConfig.APPLICATION_ID) appLaunched(BuildConfig.APPLICATION_ID)
@ -113,6 +114,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
setupOptionsMenu() setupOptionsMenu()
refreshMenuItems() refreshMenuItems()
updateMaterialActivityViews(directories_coordinator, directories_grid, useTransparentNavigation = true, useTopSearchMenu = true)
directories_refresh_layout.setOnRefreshListener { getDirectories() } directories_refresh_layout.setOnRefreshListener { getDirectories() }
storeStateVariables() storeStateVariables()
checkWhatsNewDialog() checkWhatsNewDialog()
@ -183,11 +186,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateMenuColors()
config.isThirdPartyIntent = false config.isThirdPartyIntent = false
mDateFormat = config.dateFormat mDateFormat = config.dateFormat
mTimeFormat = getTimeFormat() mTimeFormat = getTimeFormat()
setupToolbar(directories_toolbar, searchMenuItem = mSearchMenuItem)
refreshMenuItems() refreshMenuItems()
if (mStoredAnimateGifs != config.animateGifs) { if (mStoredAnimateGifs != config.animateGifs) {
@ -289,8 +292,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
override fun onBackPressed() { override fun onBackPressed() {
if (mIsSearchOpen && mSearchMenuItem != null) { if (main_menu.isSearchOpen) {
mSearchMenuItem!!.collapseActionView() main_menu.closeSearch()
} else if (config.groupDirectSubfolders) { } else if (config.groupDirectSubfolders) {
if (mCurrentPathPrefix.isEmpty()) { if (mCurrentPathPrefix.isEmpty()) {
super.onBackPressed() super.onBackPressed()
@ -306,16 +309,15 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun refreshMenuItems() { private fun refreshMenuItems() {
if (!mIsThirdPartyIntent) { if (!mIsThirdPartyIntent) {
directories_toolbar.menu.apply { main_menu.getToolbar().menu.apply {
findItem(R.id.increase_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt < MAX_COLUMN_COUNT findItem(R.id.increase_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt < MAX_COLUMN_COUNT
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.set_as_default_folder).isVisible = !config.defaultFolder.isEmpty() findItem(R.id.set_as_default_folder).isVisible = !config.defaultFolder.isEmpty()
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations) findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
setupSearch(this)
} }
} }
directories_toolbar.menu.apply { main_menu.getToolbar().menu.apply {
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 = (!isRPlus() || isExternalStorageManager()) && config.temporarilyShowHidden findItem(R.id.stop_showing_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && config.temporarilyShowHidden
@ -331,13 +333,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
R.menu.menu_main R.menu.menu_main
} }
directories_toolbar.inflateMenu(menuId) main_menu.getToolbar().inflateMenu(menuId)
main_menu.toggleHideOnScroll(true)
main_menu.setupMenu()
if (!mIsThirdPartyIntent) { main_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
setupSearch(directories_toolbar.menu)
}
directories_toolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.sort -> showSortingDialog() R.id.sort -> showSortingDialog()
R.id.filter -> showFilterMediaDialog() R.id.filter -> showFilterMediaDialog()
@ -371,6 +371,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false) mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
} }
private fun updateMenuColors() {
updateStatusbarColor(getProperBackgroundColor())
main_menu.updateColors()
}
private fun getRecyclerAdapter() = directories_grid.adapter as? DirectoryAdapter private fun getRecyclerAdapter() = directories_grid.adapter as? DirectoryAdapter
private fun storeStateVariables() { private fun storeStateVariables() {

View file

@ -5,20 +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.AppBarLayout <com.simplemobiletools.commons.views.MySearchMenu
android:id="@+id/directories_app_bar_layout" android:id="@+id/main_menu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content" />
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/directories_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:title="@string/app_launcher_name"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
</com.google.android.material.appbar.AppBarLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/directories_holder" android:id="@+id/directories_holder"

View file

@ -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/open_camera" android:id="@+id/open_camera"
android:icon="@drawable/ic_camera_vector" android:icon="@drawable/ic_camera_vector"