From 43cd82cce660a1677dd52487f26df45e885bb9f1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Jan 2023 22:11:13 +0100 Subject: [PATCH] adding the initial search menu bar --- .../voicerecorder/activities/MainActivity.kt | 25 ++++++++++++++++--- app/src/main/res/layout/activity_main.xml | 9 +++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt index 59f5414..b238d2d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt @@ -26,7 +26,7 @@ class MainActivity : SimpleActivity() { setupOptionsMenu() refreshMenuItems() - updateMaterialActivityViews(main_coordinator, main_holder, useTransparentNavigation = false, useTopSearchMenu = false) + updateMaterialActivityViews(main_coordinator, main_holder, useTransparentNavigation = false, useTopSearchMenu = true) if (checkAppSideloading()) { return @@ -54,7 +54,7 @@ class MainActivity : SimpleActivity() { override fun onResume() { super.onResume() setupTabColors() - setupToolbar(main_toolbar, statusBarColor = getProperBackgroundColor()) + updateMenuColors() getPagerAdapter()?.onResume() } @@ -76,14 +76,26 @@ class MainActivity : SimpleActivity() { } } + override fun onBackPressed() { + if (main_menu.isSearchOpen) { + main_menu.closeSearch() + } else { + super.onBackPressed() + } + } + private fun refreshMenuItems() { - main_toolbar.menu.apply { + main_menu.getToolbar().menu.apply { findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations) } } private fun setupOptionsMenu() { - main_toolbar.setOnMenuItemClickListener { menuItem -> + main_menu.getToolbar().inflateMenu(R.menu.menu) + main_menu.toggleHideOnScroll(false) + main_menu.setupMenu() + + main_menu.getToolbar().setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.more_apps_from_us -> launchMoreAppsFromUsIntent() R.id.settings -> launchSettings() @@ -94,6 +106,11 @@ class MainActivity : SimpleActivity() { } } + private fun updateMenuColors() { + updateStatusbarColor(getProperBackgroundColor()) + main_menu.updateColors() + } + private fun tryInitVoiceRecorder() { if (isRPlus()) { setupViewPager() diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 54a2241..1128f7a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,13 +5,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="wrap_content" />