Skip to content

Commit

Permalink
Just perform the action if it's the only one in the popup menu
Browse files Browse the repository at this point in the history
  • Loading branch information
nevenz committed Nov 10, 2022
1 parent 9539156 commit c67d5fe
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/com/orgzly/android/ui/notes/NotePopup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ object NotePopup {
fun showWindow(anchor: View, location: Location, direction: Int, e1: MotionEvent, e2: MotionEvent, listener: NotePopupListener) {
val context = anchor.context

val actions = getActionsForLocation(context, location, direction)

// If there is only one button just perform the action
if (actions.size == 1) {
listener.onPopupButtonClick(actions.first().id)
return

} else if (actions.isEmpty()) {
// TODO: Don't allow in preference, and/or show a snackbar here
return
}

val popupView = context.getLayoutInflater().inflate(R.layout.note_popup_buttons, null)

val width = LinearLayout.LayoutParams.WRAP_CONTENT
Expand All @@ -44,8 +56,6 @@ object NotePopup {
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}

val actions = getActionsForLocation(context, location, direction)

val group = popupView.findViewById<ViewGroup>(R.id.group)

val inflater = context.getLayoutInflater()
Expand Down Expand Up @@ -77,7 +87,6 @@ object NotePopup {
popupWindow.showAtLocation(anchor, gravity, x, y)
}

// TODO: Allow selecting the action only, without showing the popup (e.g. swipe right to toggle state).
private fun getActionsForLocation(context: Context, location: Location, direction: Int): List<Action> {
val keyId = preferenceKeyForLocation(location, direction)
val key = context.getString(keyId)
Expand Down

0 comments on commit c67d5fe

Please sign in to comment.