Make popup menu height consistent with real number of items

This commit is contained in:
Ensar Sarajčić 2023-07-28 13:49:10 +02:00
parent 7f787cef08
commit 83a35664a4

View File

@ -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()
}
}