hide AllAppsFragment on long pressing an icon

This commit is contained in:
tibbi 2022-09-22 21:09:25 +02:00
parent 9321db3cec
commit 5ccaf8ce43
4 changed files with 16 additions and 8 deletions

View File

@ -233,8 +233,7 @@ class MainActivity : SimpleActivity(), FlingListener {
main_holder.performHapticFeedback() main_holder.performHapticFeedback()
val clickedGridItem = home_screen_grid.isClickingGridItem(getGridTouchedX(x), getGridTouchedY(y)) val clickedGridItem = home_screen_grid.isClickingGridItem(getGridTouchedX(x), getGridTouchedY(y))
if (clickedGridItem != null) { if (clickedGridItem != null) {
mLongPressedIcon = clickedGridItem showHomeIconMenu(x, y - resources.getDimension(R.dimen.icon_long_press_anchor_offset_y), clickedGridItem, false)
showHomeIconMenu(x, y - resources.getDimension(R.dimen.icon_long_press_anchor_offset_y), clickedGridItem.packageName)
return return
} }
@ -254,10 +253,15 @@ class MainActivity : SimpleActivity(), FlingListener {
private fun getGridTouchedY(y: Float) = Math.min(Math.max(y.toInt() - home_screen_grid.marginTop, 0), home_screen_grid.height).toInt() private fun getGridTouchedY(y: Float) = Math.min(Math.max(y.toInt() - home_screen_grid.marginTop, 0), home_screen_grid.height).toInt()
fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) { fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem, isFromAllAppsFragment: Boolean) {
if (isFromAllAppsFragment) {
hideFragment(all_apps_fragment)
}
mLongPressedIcon = gridItem
home_screen_popup_menu_anchor.x = x home_screen_popup_menu_anchor.x = x
home_screen_popup_menu_anchor.y = y home_screen_popup_menu_anchor.y = y
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, clickedPackageName) mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, gridItem.packageName)
} }
private fun showMainLongPressMenu(x: Float, y: Float) { private fun showMainLongPressMenu(x: Float, y: Float) {

View File

@ -89,7 +89,7 @@ class LaunchersAdapter(
setOnClickListener { itemClick(launcher) } setOnClickListener { itemClick(launcher) }
setOnLongClickListener { view -> setOnLongClickListener { view ->
allAppsListener.onIconLongPressed(view.x, view.y, launcher.packageName) allAppsListener.onAppLauncherLongPressed(view.x, view.y, launcher)
true true
} }
} }

View File

@ -16,6 +16,7 @@ import com.simplemobiletools.launcher.extensions.getColumnCount
import com.simplemobiletools.launcher.extensions.launchApp import com.simplemobiletools.launcher.extensions.launchApp
import com.simplemobiletools.launcher.interfaces.AllAppsListener import com.simplemobiletools.launcher.interfaces.AllAppsListener
import com.simplemobiletools.launcher.models.AppLauncher import com.simplemobiletools.launcher.models.AppLauncher
import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.android.synthetic.main.all_apps_fragment.view.* import kotlinx.android.synthetic.main.all_apps_fragment.view.*
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener { class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener {
@ -120,7 +121,8 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0) all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
} }
override fun onIconLongPressed(x: Float, y: Float, packageName: String) { override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
activity?.showHomeIconMenu(x, y, packageName) val gridItem = HomeScreenGridItem(null, -1, -1, -1, 1, appLauncher.packageName, appLauncher.title)
activity?.showHomeIconMenu(x, y, gridItem, true)
} }
} }

View File

@ -1,5 +1,7 @@
package com.simplemobiletools.launcher.interfaces package com.simplemobiletools.launcher.interfaces
import com.simplemobiletools.launcher.models.AppLauncher
interface AllAppsListener { interface AllAppsListener {
fun onIconLongPressed(x: Float, y: Float, packageName: String) fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher)
} }