From 6096a4da3e307cd2b8cbcb8935108b72fa21aa57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 31 Jul 2023 12:41:10 +0200 Subject: [PATCH] Always hide drawer and widgets on home button press --- app/src/main/AndroidManifest.xml | 27 ++++----------- .../launcher/activities/MainActivity.kt | 33 +++++++++++-------- .../launcher/fragments/AllAppsFragment.kt | 2 +- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a734e7ba..4f4e89cb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -44,13 +44,19 @@ android:configChanges="orientation|keyboardHidden|screenSize" android:excludeFromRecents="true" android:exported="true" - android:launchMode="singleTop" + android:launchMode="singleTask" android:screenOrientation="portrait" android:theme="@style/LauncherTheme"> + + + + + + - @@ -116,7 +121,6 @@ - @@ -135,7 +139,6 @@ - @@ -154,7 +157,6 @@ - @@ -173,7 +175,6 @@ - @@ -192,7 +193,6 @@ - @@ -211,7 +211,6 @@ - @@ -230,7 +229,6 @@ - @@ -249,7 +247,6 @@ - @@ -268,7 +265,6 @@ - @@ -287,7 +283,6 @@ - @@ -306,7 +301,6 @@ - @@ -325,7 +319,6 @@ - @@ -344,7 +337,6 @@ - @@ -363,7 +355,6 @@ - @@ -382,7 +373,6 @@ - @@ -401,7 +391,6 @@ - @@ -420,7 +409,6 @@ - @@ -439,7 +427,6 @@ - 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 dfc3b7fc..058c5d8a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -24,6 +24,7 @@ import android.os.Handler import android.os.Looper import android.provider.Telephony import android.telecom.TelecomManager +import android.util.Log import android.view.* import android.view.accessibility.AccessibilityNodeInfo import android.view.animation.DecelerateInterpolator @@ -112,19 +113,13 @@ class MainActivity : SimpleActivity(), FlingListener { override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) + closeAppDrawer() + closeWidgetsFragment() if (intent != null) { handleIntentAction(intent) } } - 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 @@ -495,25 +490,35 @@ class MainActivity : SimpleActivity(), FlingListener { } } - fun closeAppDrawer() { + fun closeAppDrawer(delayed: Boolean = false) { if (isAllAppsFragmentExpanded()) { - Handler(Looper.getMainLooper()).postDelayed({ + val close = { 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) + } + if (delayed) { + Handler(Looper.getMainLooper()).postDelayed(close, APP_DRAWER_CLOSE_DELAY) + } else { + close() + } } } - fun closeWidgetsFragment() { + fun closeWidgetsFragment(delayed: Boolean = false) { if (isWidgetsFragmentExpanded()) { - Handler(Looper.getMainLooper()).postDelayed({ + val close = { 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) + } + if (delayed) { + Handler(Looper.getMainLooper()).postDelayed(close, APP_DRAWER_CLOSE_DELAY) + } else { + close() + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt index 4ced1d84..7e5cfe52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt @@ -121,7 +121,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment LaunchersAdapter(activity!!, launchers, this) { activity?.launchApp((it as AppLauncher).packageName, it.activityName) if (activity?.config?.closeAppDrawer == true) { - activity?.closeAppDrawer() + activity?.closeAppDrawer(delayed = true) } ignoreTouches = false touchDownY = -1