From 83a35664a40acd13e3be4cff111074a5998baa35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 28 Jul 2023 13:49:10 +0200 Subject: [PATCH] Make popup menu height consistent with real number of items --- .../launcher/activities/MainActivity.kt | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) 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 25d1821..6069576 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -31,6 +31,7 @@ import android.widget.PopupMenu import androidx.core.graphics.drawable.toBitmap import androidx.core.view.GestureDetectorCompat import androidx.core.view.isVisible +import androidx.core.view.iterator import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.launcher.BuildConfig @@ -563,23 +564,6 @@ class MainActivity : SimpleActivity(), FlingListener { } private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu { - var visibleMenuButtons = 6 - visibleMenuButtons -= when (gridItem.type) { - ITEM_TYPE_ICON -> 1 - ITEM_TYPE_WIDGET -> 3 - else -> 4 - } - - if (isOnAllAppsFragment) { - visibleMenuButtons-- - } - - if (gridItem.type != ITEM_TYPE_WIDGET) { - visibleMenuButtons-- - } - - val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuButtons - 1) - anchorView.y -= yOffset val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme()) return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply { @@ -612,6 +596,15 @@ class MainActivity : SimpleActivity(), FlingListener { resetFragmentTouches() } + var visibleMenuItems = 0 + for (item in menu.iterator()) { + if (item.isVisible) { + visibleMenuItems++ + } + } + val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuItems - 1) + anchorView.y -= yOffset + show() } }