mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Show app options menu on long click
As many people interact in this way with a list. Does not change the normal interaction with the apps list.
This commit is contained in:
parent
d36daa6006
commit
1e79993563
1 changed files with 36 additions and 23 deletions
|
@ -62,35 +62,48 @@ class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forAp
|
||||||
|
|
||||||
if (getSavedTheme(activity) == "dark") transformGrayscale(viewHolder.img)
|
if (getSavedTheme(activity) == "dark") transformGrayscale(viewHolder.img)
|
||||||
|
|
||||||
viewHolder.menuDots.setOnClickListener{ //creating a popup menu
|
// decide when to show the options popup menu about
|
||||||
|
if (isSystemApp || action == "pick") {
|
||||||
|
viewHolder.menuDots.visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
viewHolder.menuDots.visibility = View.VISIBLE
|
||||||
|
|
||||||
val popup = PopupMenu(activity, viewHolder.menuDots)
|
viewHolder.menuDots.setOnClickListener{ showOptionsPopup(viewHolder, appPackageName) }
|
||||||
popup.inflate(R.menu.menu_app)
|
viewHolder.menuDots.setOnLongClickListener{ showOptionsPopup(viewHolder, appPackageName) }
|
||||||
|
viewHolder.textView.setOnLongClickListener{ showOptionsPopup(viewHolder, appPackageName) }
|
||||||
|
viewHolder.img.setOnLongClickListener{ showOptionsPopup(viewHolder, appPackageName) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
popup.setOnMenuItemClickListener {
|
private fun showOptionsPopup(viewHolder: ViewHolder, appPackageName: String): Boolean {
|
||||||
when (it.itemId) {
|
//create the popup menu
|
||||||
R.id.app_menu_delete -> { // delete
|
|
||||||
intendedChoosePause = true
|
|
||||||
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE)
|
|
||||||
intent.data = Uri.parse("package:$appPackageName")
|
|
||||||
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
|
||||||
activity.startActivityForResult(intent, REQUEST_UNINSTALL)
|
|
||||||
|
|
||||||
true
|
val popup = PopupMenu(activity, viewHolder.menuDots)
|
||||||
}
|
popup.inflate(R.menu.menu_app)
|
||||||
R.id.app_menu_info -> { // open app settings
|
|
||||||
intendedChoosePause = true
|
popup.setOnMenuItemClickListener {
|
||||||
openAppSettings(appPackageName, activity)
|
when (it.itemId) {
|
||||||
true
|
R.id.app_menu_delete -> { // delete
|
||||||
}
|
intendedChoosePause = true
|
||||||
else -> false
|
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE)
|
||||||
|
intent.data = Uri.parse("package:$appPackageName")
|
||||||
|
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||||
|
activity.startActivityForResult(intent, REQUEST_UNINSTALL)
|
||||||
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
R.id.app_menu_info -> { // open app settings
|
||||||
|
intendedChoosePause = true
|
||||||
|
openAppSettings(appPackageName, activity)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
popup.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
viewHolder.menuDots.visibility = if(isSystemApp || action == "pick") View.INVISIBLE else View.VISIBLE
|
popup.show()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int { return appsList.size }
|
override fun getItemCount(): Int { return appsList.size }
|
||||||
|
|
Loading…
Add table
Reference in a new issue