Fix various new conversation button issues

This commit is contained in:
nielsandriesse 2020-06-09 13:35:27 +10:00
parent 07737262ca
commit 9c8c23c5d9

View File

@ -14,7 +14,6 @@ import android.os.VibrationEffect
import android.os.VibrationEffect.DEFAULT_AMPLITUDE import android.os.VibrationEffect.DEFAULT_AMPLITUDE
import android.os.Vibrator import android.os.Vibrator
import android.support.annotation.ColorRes import android.support.annotation.ColorRes
import android.support.annotation.DimenRes
import android.support.annotation.DrawableRes import android.support.annotation.DrawableRes
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent import android.view.MotionEvent
@ -198,12 +197,9 @@ class NewConversationButtonSetView : RelativeLayout {
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
if (isExpanded) { if (isExpanded) {
if (sessionButton.contains(touch)) { delegate?.createNewPrivateChat(); collapse() } if (mainButton.contains(touch)) { collapse() }
else if (closedGroupButton.contains(touch)) { delegate?.createNewClosedGroup(); collapse() }
else if (openGroupButton.contains(touch)) { delegate?.joinOpenGroup(); collapse() }
else if (mainButton.contains(touch)) { collapse() }
} else { } else {
isExpanded = !isExpanded isExpanded = true
expand() expand()
} }
val vibrator = context.getSystemService(VIBRATOR_SERVICE) as Vibrator val vibrator = context.getSystemService(VIBRATOR_SERVICE) as Vibrator
@ -235,15 +231,17 @@ class NewConversationButtonSetView : RelativeLayout {
} }
} }
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
val distanceFromRestPosition = touch.distanceTo(buttonRestPosition) val mainButtonCenter = PointF(width.toFloat() / 2, height.toFloat() - bottomMargin - mainButton.expandedSize / 2)
if (distanceFromRestPosition > (minDragDistance + mainButton.collapsedSize / 2)) { val distanceFromMainButtonCenter = touch.distanceTo(mainButtonCenter)
fun collapse() {
isExpanded = false
this.collapse()
}
if (distanceFromMainButtonCenter > (minDragDistance + mainButton.collapsedSize / 2)) {
if (sessionButton.contains(touch) || touch.isAbove(sessionButton, dragMargin)) { delegate?.createNewPrivateChat(); collapse() } 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 (closedGroupButton.contains(touch) || touch.isRightOf(closedGroupButton, dragMargin)) { delegate?.createNewClosedGroup(); collapse() }
else if (openGroupButton.contains(touch) || touch.isLeftOf(openGroupButton, dragMargin)) { delegate?.joinOpenGroup(); collapse() } else if (openGroupButton.contains(touch) || touch.isLeftOf(openGroupButton, dragMargin)) { delegate?.joinOpenGroup(); collapse() }
else { else { collapse() }
isExpanded = !isExpanded
if (!isExpanded) { collapse() }
}
} else { } else {
val currentPosition = PointF(mainButton.x, mainButton.y) val currentPosition = PointF(mainButton.x, mainButton.y)
mainButton.animatePositionChange(currentPosition, buttonRestPosition) mainButton.animatePositionChange(currentPosition, buttonRestPosition)