mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Allow user to tap as well
This commit is contained in:
parent
83feb26225
commit
f94bf6301b
@ -27,6 +27,8 @@ import org.thoughtcrime.securesms.loki.toPx
|
|||||||
|
|
||||||
class NewConversationButtonSetView : RelativeLayout {
|
class NewConversationButtonSetView : RelativeLayout {
|
||||||
private var expandedButton: Button? = null
|
private var expandedButton: Button? = null
|
||||||
|
private var previousAction: Int? = null
|
||||||
|
private var isExpanded = false
|
||||||
var delegate: NewConversationButtonSetViewDelegate? = null
|
var delegate: NewConversationButtonSetViewDelegate? = null
|
||||||
|
|
||||||
// region Convenience
|
// region Convenience
|
||||||
@ -205,9 +207,7 @@ class NewConversationButtonSetView : RelativeLayout {
|
|||||||
|
|
||||||
// region Interaction
|
// region Interaction
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
val touchX = event.x
|
val touch = PointF(event.x, event.y)
|
||||||
val touchY = event.y
|
|
||||||
val touch = PointF(touchX, touchY)
|
|
||||||
val expandedButton = expandedButton
|
val expandedButton = expandedButton
|
||||||
val buttonsExcludingMainButton = listOf( sessionButton, closedGroupButton, openGroupButton )
|
val buttonsExcludingMainButton = listOf( sessionButton, closedGroupButton, openGroupButton )
|
||||||
when (event.action) {
|
when (event.action) {
|
||||||
@ -218,14 +218,15 @@ class NewConversationButtonSetView : RelativeLayout {
|
|||||||
} else {
|
} else {
|
||||||
vibrator.vibrate(50)
|
vibrator.vibrate(50)
|
||||||
}
|
}
|
||||||
sessionButton.animatePositionChange(buttonRestPosition, sessionButtonExpandedPosition)
|
if (!isExpanded && mainButton.contains(touch)) {
|
||||||
closedGroupButton.animatePositionChange(buttonRestPosition, closedGroupButtonExpandedPosition)
|
expand()
|
||||||
openGroupButton.animatePositionChange(buttonRestPosition, openGroupButtonExpandedPosition)
|
} else if (buttonsExcludingMainButton.none { it.contains(touch) }) {
|
||||||
buttonsExcludingMainButton.forEach { it.animateAlphaChange(0.0f, 1.0f) }
|
collapse()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
mainButton.x = touchX - mainButton.expandedSize / 2
|
mainButton.x = touch.x - mainButton.expandedSize / 2
|
||||||
mainButton.y = touchY - mainButton.expandedSize / 2
|
mainButton.y = touch.y - mainButton.expandedSize / 2
|
||||||
mainButton.alpha = 1 - (PointF(mainButton.x, mainButton.y).distanceTo(buttonRestPosition) / maxDragDistance)
|
mainButton.alpha = 1 - (PointF(mainButton.x, mainButton.y).distanceTo(buttonRestPosition) / maxDragDistance)
|
||||||
val buttonToExpand = buttonsExcludingMainButton.firstOrNull { button ->
|
val buttonToExpand = buttonsExcludingMainButton.firstOrNull { button ->
|
||||||
var hasUserDraggedBeyondButton = false
|
var hasUserDraggedBeyondButton = false
|
||||||
@ -245,24 +246,41 @@ class NewConversationButtonSetView : RelativeLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
expandedButton?.collapse()
|
if (previousAction == MotionEvent.ACTION_MOVE || isExpanded) {
|
||||||
this.expandedButton = null
|
expandedButton?.collapse()
|
||||||
val allButtons = listOf( mainButton ) + buttonsExcludingMainButton
|
this.expandedButton = null
|
||||||
allButtons.forEach {
|
collapse()
|
||||||
val currentPosition = PointF(it.x, it.y)
|
if (event.action == MotionEvent.ACTION_UP) {
|
||||||
it.animatePositionChange(currentPosition, buttonRestPosition)
|
if (sessionButton.contains(touch) || touch.isAbove(sessionButton, dragMargin)) { delegate?.createNewPrivateChat() }
|
||||||
val endAlpha = if (it == mainButton) 1.0f else 0.0f
|
else if (closedGroupButton.contains(touch) || touch.isRightOf(closedGroupButton, dragMargin)) { delegate?.createNewClosedGroup() }
|
||||||
it.animateAlphaChange(it.alpha, endAlpha)
|
else if (openGroupButton.contains(touch) || touch.isLeftOf(openGroupButton, dragMargin)) { delegate?.joinOpenGroup() }
|
||||||
}
|
}
|
||||||
if (event.action == MotionEvent.ACTION_UP) {
|
|
||||||
if (openGroupButton.contains(touch) || touch.isLeftOf(openGroupButton, dragMargin)) { delegate?.joinOpenGroup() }
|
|
||||||
else if (sessionButton.contains(touch) || touch.isAbove(sessionButton, dragMargin)) { delegate?.createNewPrivateChat() }
|
|
||||||
else if (closedGroupButton.contains(touch) || touch.isRightOf(closedGroupButton, dragMargin)) { delegate?.createNewClosedGroup() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
previousAction = event.action
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun expand() {
|
||||||
|
val buttonsExcludingMainButton = listOf( sessionButton, closedGroupButton, openGroupButton )
|
||||||
|
sessionButton.animatePositionChange(buttonRestPosition, sessionButtonExpandedPosition)
|
||||||
|
closedGroupButton.animatePositionChange(buttonRestPosition, closedGroupButtonExpandedPosition)
|
||||||
|
openGroupButton.animatePositionChange(buttonRestPosition, openGroupButtonExpandedPosition)
|
||||||
|
buttonsExcludingMainButton.forEach { it.animateAlphaChange(0.0f, 1.0f) }
|
||||||
|
postDelayed({ isExpanded = true }, Button.animationDuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun collapse() {
|
||||||
|
val allButtons = listOf( mainButton, sessionButton, closedGroupButton, openGroupButton )
|
||||||
|
allButtons.forEach {
|
||||||
|
val currentPosition = PointF(it.x, it.y)
|
||||||
|
it.animatePositionChange(currentPosition, buttonRestPosition)
|
||||||
|
val endAlpha = if (it == mainButton) 1.0f else 0.0f
|
||||||
|
it.animateAlphaChange(it.alpha, endAlpha)
|
||||||
|
}
|
||||||
|
postDelayed({ isExpanded = false }, Button.animationDuration)
|
||||||
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user