@@ -28,7 +28,6 @@ import android.os.Build
2828import android.os.Handler
2929import android.os.Message
3030import android.util.AttributeSet
31- import android.util.Log
3231import android.view.*
3332import android.view.animation.DecelerateInterpolator
3433import android.widget.FrameLayout
@@ -42,6 +41,7 @@ import me.thanel.swipeactionview.utils.marginStart
4241import me.thanel.swipeactionview.utils.radius
4342import me.thanel.swipeactionview.utils.setBoundsFrom
4443import me.thanel.swipeactionview.utils.totalWidth
44+ import kotlin.math.abs
4545import kotlin.math.absoluteValue
4646
4747
@@ -400,6 +400,7 @@ class SwipeActionView : FrameLayout {
400400 SwipeDirection .LEFT -> leftSwipeView?.let {
401401 container.translationX = - maxLeftSwipeDistance
402402 }
403+
403404 SwipeDirection .RIGHT -> rightSwipeView?.let {
404405 container.translationX = maxRightSwipeDistance
405406 }
@@ -620,6 +621,7 @@ class SwipeActionView : FrameLayout {
620621 leftSwipeRipple.draw(canvas)
621622 }
622623 }
624+
623625 SwipeDirection .RIGHT -> {
624626 if (rightSwipeRipple.hasColor) {
625627 rightSwipeRipple.draw(canvas)
@@ -727,13 +729,13 @@ class SwipeActionView : FrameLayout {
727729 *
728730 * @return Whether the user has moved their finger vertically.
729731 */
730- private fun hasMovedVertically (e : MotionEvent ) = Math . abs(e.rawY - initialRawY) >= touchSlop
732+ private fun hasMovedVertically (e : MotionEvent ) = abs(e.rawY - initialRawY) >= touchSlop
731733
732734 /* *
733735 * Tells whether the drag can be started by the user based on provided motion event.
734736 */
735737 private fun canStartDrag (e : MotionEvent ): Boolean {
736- val movedFarEnough = Math . abs(e.rawX - initialRawX) > touchSlop
738+ val movedFarEnough = abs(e.rawX - initialRawX) > touchSlop
737739 return movedFarEnough && isTouchValid
738740 }
739741
@@ -783,18 +785,18 @@ class SwipeActionView : FrameLayout {
783785
784786 val normalizedTranslation = swipeDistance.absoluteValue
785787 // swiping right
786- if (swipeDistance> 0 ) {
788+ if (swipeDistance > 0 ) {
787789 if (rightSwipeView is MultiSwipeActionView ) {
788790 val halfway = (rightSwipeView as MultiSwipeActionView ).getChildAt(0 )?.width ? : 0
789- if (halfway- distanceFromCenterpoint < normalizedTranslation) {
791+ if (halfway - distanceFromCenterpoint < normalizedTranslation) {
790792 return true
791793 }
792794 }
793795 } else {
794796 if (leftSwipeView is MultiSwipeActionView ) {
795797 val vg = (leftSwipeView as MultiSwipeActionView )
796- val halfway = vg.getChildAt(vg.childCount- 1 )?.width ? : 0
797- if (halfway- distanceFromCenterpoint < normalizedTranslation) {
798+ val halfway = vg.getChildAt(vg.childCount - 1 )?.width ? : 0
799+ if (halfway - distanceFromCenterpoint < normalizedTranslation) {
798800 return true
799801 }
800802 }
@@ -815,21 +817,23 @@ class SwipeActionView : FrameLayout {
815817 val resistanceMulitplier = 4
816818
817819 // swiping right
818- if (container.translationX> 0 ) {
820+ if (container.translationX > 0 ) {
819821 if (rightSwipeView is MultiSwipeActionView ) {
820822 val halfway = (rightSwipeView as MultiSwipeActionView ).getChildAt(0 )?.width ? : 0
821- if (halfway+ distanceFromCenterpoint > normalizedTranslation &&
822- normalizedTranslation > halfway- distanceFromCenterpoint) {
823- resistance * = resistanceMulitplier
823+ if (halfway + distanceFromCenterpoint > normalizedTranslation &&
824+ normalizedTranslation > halfway - distanceFromCenterpoint
825+ ) {
826+ resistance * = resistanceMulitplier
824827 }
825828 }
826829 } else {
827830 if (leftSwipeView is MultiSwipeActionView ) {
828831 val vg = (leftSwipeView as MultiSwipeActionView )
829- val halfway = vg.getChildAt(vg.childCount- 1 )?.width ? : 0
830- if (halfway+ distanceFromCenterpoint > normalizedTranslation &&
831- normalizedTranslation > halfway- distanceFromCenterpoint) {
832- resistance * = resistanceMulitplier
832+ val halfway = vg.getChildAt(vg.childCount - 1 )?.width ? : 0
833+ if (halfway + distanceFromCenterpoint > normalizedTranslation &&
834+ normalizedTranslation > halfway - distanceFromCenterpoint
835+ ) {
836+ resistance * = resistanceMulitplier
833837 }
834838 }
835839 }
@@ -869,7 +873,7 @@ class SwipeActionView : FrameLayout {
869873 cancelDrag(false )
870874 velocityTracker.computeCurrentVelocity(100 )
871875
872- val swipedFastEnough = Math . abs(velocityTracker.xVelocity) > minActivationSpeed
876+ val swipedFastEnough = abs(velocityTracker.xVelocity) > minActivationSpeed
873877
874878 if (swipedFastEnough && ! isValidDelta(velocityTracker.xVelocity)) {
875879 animateToOriginalPosition()
@@ -921,15 +925,18 @@ class SwipeActionView : FrameLayout {
921925 leftSwipeRipple.restart()
922926 }
923927
924- animateContainer(getTargetTranslationX(swipedRight, isHalfwaySwipe), swipeAnimationDuration) {
928+ animateContainer(
929+ getTargetTranslationX(swipedRight, isHalfwaySwipe),
930+ swipeAnimationDuration
931+ ) {
925932 val shouldFinish = if (swipedRight) {
926- if (isHalfwaySwipe) {
933+ if (isHalfwaySwipe) {
927934 swipeGestureListener?.onSwipedHalfwayRight(this )
928935 } else {
929936 swipeGestureListener?.onSwipedRight(this )
930937 }
931938 } else {
932- if (isHalfwaySwipe) {
939+ if (isHalfwaySwipe) {
933940 swipeGestureListener?.onSwipedHalfwayLeft(this )
934941 } else {
935942 swipeGestureListener?.onSwipedLeft(this )
@@ -1006,16 +1013,18 @@ class SwipeActionView : FrameLayout {
10061013 swipeView = leftSwipeView
10071014 animator = leftSwipeAnimator
10081015 }
1016+
10091017 swipeDistance > 0 -> {
10101018 swipeView = rightSwipeView
10111019 animator = rightSwipeAnimator
10121020 }
1021+
10131022 else -> return
10141023 }
10151024
10161025 if (swipeView == null || animator == null ) return
10171026
1018- val absTranslationX = Math . abs(swipeDistance)
1027+ val absTranslationX = abs(swipeDistance)
10191028 val maxSwipeDistance = getMaxSwipeDistance(swipeDistance)
10201029
10211030 val progress = absTranslationX / maxSwipeDistance
@@ -1046,11 +1055,13 @@ class SwipeActionView : FrameLayout {
10461055 * @return Translation Value
10471056 */
10481057 private fun getTargetTranslationX (swipedRight : Boolean , isHalfwaySwipe : Boolean ): Float {
1049- return if (isHalfwaySwipe) {
1058+ return if (isHalfwaySwipe) {
10501059 return if (swipedRight) {
1051- ((rightSwipeView as MultiSwipeActionView ).getChildAt(0 )?.width ? : maxRightSwipeDistance).toFloat()
1060+ ((rightSwipeView as MultiSwipeActionView ).getChildAt(0 )?.width
1061+ ? : maxRightSwipeDistance).toFloat()
10521062 } else {
1053- - ((leftSwipeView as MultiSwipeActionView ).getChildAt(0 )?.width ? : maxLeftSwipeDistance).toFloat()
1063+ - ((leftSwipeView as MultiSwipeActionView ).getChildAt(0 )?.width
1064+ ? : maxLeftSwipeDistance).toFloat()
10541065 }
10551066 } else {
10561067 if (swipedRight) maxRightSwipeDistance else - maxLeftSwipeDistance
@@ -1085,6 +1096,7 @@ class SwipeActionView : FrameLayout {
10851096 swipeActionView.inLongPress = true
10861097 swipeActionView.performLongClick()
10871098 }
1099+
10881100 TAP -> {
10891101 swipeActionView.startPress(x, y)
10901102 }
0 commit comments