@@ -30,6 +30,18 @@ object NotePopup {
3030 fun showWindow (anchor : View , location : Location , direction : Int , e1 : MotionEvent , e2 : MotionEvent , listener : NotePopupListener ) {
3131 val context = anchor.context
3232
33+ val actions = getActionsForLocation(context, location, direction)
34+
35+ // If there is only one button just perform the action
36+ if (actions.size == 1 ) {
37+ listener.onPopupButtonClick(actions.first().id)
38+ return
39+
40+ } else if (actions.isEmpty()) {
41+ // TODO: Don't allow in preference, and/or show a snackbar here
42+ return
43+ }
44+
3345 val popupView = context.getLayoutInflater().inflate(R .layout.note_popup_buttons, null )
3446
3547 val width = LinearLayout .LayoutParams .WRAP_CONTENT
@@ -44,8 +56,6 @@ object NotePopup {
4456 setBackgroundDrawable(ColorDrawable (Color .TRANSPARENT ))
4557 }
4658
47- val actions = getActionsForLocation(context, location, direction)
48-
4959 val group = popupView.findViewById<ViewGroup >(R .id.group)
5060
5161 val inflater = context.getLayoutInflater()
@@ -77,7 +87,6 @@ object NotePopup {
7787 popupWindow.showAtLocation(anchor, gravity, x, y)
7888 }
7989
80- // TODO: Allow selecting the action only, without showing the popup (e.g. swipe right to toggle state).
8190 private fun getActionsForLocation (context : Context , location : Location , direction : Int ): List <Action > {
8291 val keyId = preferenceKeyForLocation(location, direction)
8392 val key = context.getString(keyId)
0 commit comments