From 4fa8131f21d195e6b17c3d7e67ef184a06c5ff61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 27 Jul 2023 17:41:32 +0200 Subject: [PATCH 1/7] Add a setting for always closing drawers when using home button This closes #57 --- .../launcher/activities/MainActivity.kt | 20 +++++++++++++++++++ .../launcher/activities/SettingsActivity.kt | 9 +++++++++ .../launcher/helpers/Config.kt | 4 ++++ .../launcher/helpers/Constants.kt | 1 + app/src/main/res/layout/activity_settings.xml | 16 +++++++++++++++ app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values-ca/strings.xml | 1 + app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-el/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-et/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-gl/strings.xml | 1 + app/src/main/res/values-hr/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-in/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-iw/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-lt/strings.xml | 1 + app/src/main/res/values-ml/strings.xml | 1 + app/src/main/res/values-nb-rNO/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pa-rPK/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ro/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sk/strings.xml | 1 + app/src/main/res/values-sl/strings.xml | 1 + app/src/main/res/values-sr/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-uk/strings.xml | 1 + app/src/main/res/values-zgh/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 42 files changed, 87 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt index ba0289f..3af880a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -118,6 +118,14 @@ class MainActivity : SimpleActivity(), FlingListener { } } + override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) { + super.onTopResumedActivityChanged(isTopResumedActivity) + if (!isTopResumedActivity && config.closeAppDrawerOnHome) { + closeAppDrawer() + closeWidgetsFragment() + } + } + private fun handleIntentAction(intent: Intent) { if (intent.action == LauncherApps.ACTION_CONFIRM_PIN_SHORTCUT) { val launcherApps = applicationContext.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps @@ -492,6 +500,18 @@ class MainActivity : SimpleActivity(), FlingListener { Handler(Looper.getMainLooper()).postDelayed({ all_apps_fragment.y = mScreenHeight.toFloat() all_apps_fragment.all_apps_grid.scrollToPosition(0) + (all_apps_fragment as AllAppsFragment).touchDownY = -1 + home_screen_grid.fragmentCollapsed() + }, APP_DRAWER_CLOSE_DELAY) + } + } + + fun closeWidgetsFragment() { + if (isWidgetsFragmentExpanded()) { + Handler(Looper.getMainLooper()).postDelayed({ + widgets_fragment.y = mScreenHeight.toFloat() + widgets_fragment.widgets_list.scrollToPosition(0) + (widgets_fragment as WidgetsFragment).touchDownY = -1 home_screen_grid.fragmentCollapsed() }, APP_DRAWER_CLOSE_DELAY) } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt index 94bdea5..8630c81 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/SettingsActivity.kt @@ -39,6 +39,7 @@ class SettingsActivity : SimpleActivity() { setupCustomizeColors() setupUseEnglish() setupCloseAppDrawerOnOtherAppOpen() + setupCloseAppDrawerOnHome() setupDrawerColumnCount() setupDrawerSearchBar() setupHomeRowCount() @@ -106,6 +107,14 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupCloseAppDrawerOnHome() { + settings_close_app_drawer_on_home.isChecked = config.closeAppDrawer + settings_close_app_drawer_on_home_holder.setOnClickListener { + settings_close_app_drawer_on_home.toggle() + config.closeAppDrawerOnHome = settings_close_app_drawer_on_home.isChecked + } + } + private fun setupDrawerColumnCount() { val currentColumnCount = config.drawerColumnCount settings_drawer_column_count.text = currentColumnCount.toString() diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt index b88b168..a910e09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt @@ -32,4 +32,8 @@ class Config(context: Context) : BaseConfig(context) { var closeAppDrawer: Boolean get() = prefs.getBoolean(CLOSE_APP_DRAWER, false) set(closeAppDrawer) = prefs.edit().putBoolean(CLOSE_APP_DRAWER, closeAppDrawer).apply() + + var closeAppDrawerOnHome: Boolean + get() = prefs.getBoolean(CLOSE_APP_DRAWER_ON_HOME, false) + set(closeAppDrawerOnHome) = prefs.edit().putBoolean(CLOSE_APP_DRAWER_ON_HOME, closeAppDrawerOnHome).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt index 65e7bcd..534545b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt @@ -10,6 +10,7 @@ const val HOME_COLUMN_COUNT = "home_column_count" const val DRAWER_COLUMN_COUNT = "drawer_column_count" const val SHOW_SEARCH_BAR = "show_search_bar" const val CLOSE_APP_DRAWER = "close_app_drawer" +const val CLOSE_APP_DRAWER_ON_HOME = "close_app_drawer_on_home" // default home screen grid size const val ROW_COUNT = 6 diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 385d4ed..e46af51 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -203,6 +203,22 @@ + + + + + + diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index b0c76a3..83b247e 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -13,6 +13,7 @@ لا يمكن إلغاء تثبيت بعض التطبيقات بسبب قيود النظام، ولكن يمكن إخفاء أيقوناتها لتجنب ظهورها. درج التطبيق Close app drawer on opening an app + Close app drawer when home button is used Home screen Widget is too big for current home screen size