From 1b9908377c8b38b8ebb67086ffa30a706553ddc9 Mon Sep 17 00:00:00 2001 From: Haafingar Date: Wed, 27 May 2020 17:40:08 +1000 Subject: [PATCH] Change button behaviour to match usr expectations --- .../views/NewConversationButtonSetView.kt | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/views/NewConversationButtonSetView.kt b/src/org/thoughtcrime/securesms/loki/views/NewConversationButtonSetView.kt index c0596dc5fa..1737478ca0 100644 --- a/src/org/thoughtcrime/securesms/loki/views/NewConversationButtonSetView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/NewConversationButtonSetView.kt @@ -209,23 +209,26 @@ class NewConversationButtonSetView : RelativeLayout { // region Interaction override fun onTouchEvent(event: MotionEvent): Boolean { val touch = PointF(event.x, event.y) - val expandedButton = expandedButton val allButtons = listOf( mainButton, sessionButton, closedGroupButton, openGroupButton ) val buttonsExcludingMainButton = listOf( sessionButton, closedGroupButton, openGroupButton ) if (allButtons.none { it.contains(touch) }) { return false } when (event.action) { MotionEvent.ACTION_DOWN -> { + if (isExpanded) { + if (sessionButton.contains(touch)) { delegate?.createNewPrivateChat(); collapse()} + else if (closedGroupButton.contains(touch)) { delegate?.createNewClosedGroup(); collapse() } + else if (openGroupButton.contains(touch)) { delegate?.joinOpenGroup(); collapse() } + else if (mainButton.contains(touch)) { collapse() } + } else { + isExpanded = !isExpanded + expand() + } val vibrator = context.getSystemService(VIBRATOR_SERVICE) as Vibrator if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { vibrator.vibrate(VibrationEffect.createOneShot(50, DEFAULT_AMPLITUDE)) } else { vibrator.vibrate(50) } - if (!isExpanded && mainButton.contains(touch)) { - expand() - } else if (buttonsExcludingMainButton.none { it.contains(touch) }) { - collapse() - } } MotionEvent.ACTION_MOVE -> { mainButton.x = touch.x - mainButton.expandedSize / 2 @@ -249,22 +252,27 @@ class NewConversationButtonSetView : RelativeLayout { } } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { - if (previousAction == MotionEvent.ACTION_MOVE || isExpanded) { + val distanceFromRestPosition = touch.distanceTo(buttonRestPosition) + if (distanceFromRestPosition > (minDragDistance + mainButton.collapsedSize / 2)) { + if (sessionButton.contains(touch) || touch.isAbove(sessionButton, dragMargin)) { delegate?.createNewPrivateChat(); collapse()} + else if (closedGroupButton.contains(touch) || touch.isRightOf(closedGroupButton, dragMargin)) { delegate?.createNewClosedGroup(); collapse() } + else if (openGroupButton.contains(touch) || touch.isLeftOf(openGroupButton, dragMargin)) { delegate?.joinOpenGroup(); collapse() } + else { + isExpanded = !isExpanded + if (!isExpanded) { collapse() } + } + } else { + val currentPosition = PointF(mainButton.x, mainButton.y) + mainButton.animatePositionChange(currentPosition, buttonRestPosition) + val endAlpha = 1.0f + mainButton.animateAlphaChange(mainButton.alpha, endAlpha) expandedButton?.collapse() this.expandedButton = null - collapse() - val distanceFromRestPosition = touch.distanceTo(buttonRestPosition) - if (event.action == MotionEvent.ACTION_UP && distanceFromRestPosition > (minDragDistance + mainButton.collapsedSize / 2)) { - if (sessionButton.contains(touch) || touch.isAbove(sessionButton, dragMargin)) { delegate?.createNewPrivateChat() } - else if (closedGroupButton.contains(touch) || touch.isRightOf(closedGroupButton, dragMargin)) { delegate?.createNewClosedGroup() } - else if (openGroupButton.contains(touch) || touch.isLeftOf(openGroupButton, dragMargin)) { delegate?.joinOpenGroup() } - } } } } previousAction = event.action return true - } private fun expand() { val buttonsExcludingMainButton = listOf( sessionButton, closedGroupButton, openGroupButton ) @@ -295,4 +303,4 @@ interface NewConversationButtonSetViewDelegate { fun createNewPrivateChat() fun createNewClosedGroup() } -// endregion \ No newline at end of file +// endregion