From 36bd2290e9a224398169b3f5132841f2fd1ef880 Mon Sep 17 00:00:00 2001 From: Tobias Preuss Date: Tue, 23 Jun 2020 18:31:16 +0200 Subject: [PATCH] Use Kotlin math functions. --- .../room/detail/RoomMessageTouchHelperCallback.kt | 11 ++++++----- .../riotx/features/reactions/widget/DotsView.kt | 10 ++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt index 33e18595a0..4616cb4b25 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomMessageTouchHelperCallback.kt @@ -33,6 +33,7 @@ import com.airbnb.epoxy.EpoxyTouchHelperCallback import com.airbnb.epoxy.EpoxyViewHolder import timber.log.Timber import kotlin.math.abs +import kotlin.math.min class RoomMessageTouchHelperCallback(private val context: Context, @DrawableRes actionIcon: Int, @@ -92,7 +93,7 @@ class RoomMessageTouchHelperCallback(private val context: Context, setTouchListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) } val size = triggerDistance - if (Math.abs(viewHolder.itemView.translationX) < size || dX > this.dX /*going back*/) { + if (abs(viewHolder.itemView.translationX) < size || dX > this.dX /*going back*/) { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) this.dX = dX startTracking = true @@ -127,9 +128,9 @@ class RoomMessageTouchHelperCallback(private val context: Context, private fun drawReplyButton(canvas: Canvas, itemView: View) { // Timber.v("drawReplyButton") - val translationX = Math.abs(itemView.translationX) + val translationX = abs(itemView.translationX) val newTime = System.currentTimeMillis() - val dt = Math.min(17, newTime - lastReplyButtonAnimationTime) + val dt = min(17, newTime - lastReplyButtonAnimationTime) lastReplyButtonAnimationTime = newTime val showing = translationX >= minShowDistance if (showing) { @@ -163,10 +164,10 @@ class RoomMessageTouchHelperCallback(private val context: Context, } else { 1.2f - 0.2f * ((replyButtonProgress - 0.8f) / 0.2f) } - alpha = Math.min(255f, 255 * (replyButtonProgress / 0.8f)).toInt() + alpha = min(255f, 255 * (replyButtonProgress / 0.8f)).toInt() } else { scale = replyButtonProgress - alpha = Math.min(255f, 255 * replyButtonProgress).toInt() + alpha = min(255f, 255 * replyButtonProgress).toInt() } imageDrawable.alpha = alpha diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt b/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt index 292b17ce9f..a0dc4a4ae5 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/widget/DotsView.kt @@ -22,6 +22,8 @@ import android.graphics.Paint import android.util.AttributeSet import android.util.Property import android.view.View +import kotlin.math.cos +import kotlin.math.sin /** * This view will draw dots floating around the center of it's view @@ -84,16 +86,16 @@ class DotsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? private fun drawOuterDotsFrame(canvas: Canvas) { for (i in 0 until DOTS_COUNT) { - val cX = (centerX + currentRadius1 * Math.cos(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() - val cY = (centerY + currentRadius1 * Math.sin(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() + val cX = (centerX + currentRadius1 * cos(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() + val cY = (centerY + currentRadius1 * sin(i.toDouble() * OUTER_DOTS_POSITION_ANGLE.toDouble() * Math.PI / 180)).toFloat() canvas.drawCircle(cX, cY, currentDotSize1, circlePaints[i % circlePaints.size]) } } private fun drawInnerDotsFrame(canvas: Canvas) { for (i in 0 until DOTS_COUNT) { - val cX = (centerX + currentRadius2 * Math.cos((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() - val cY = (centerY + currentRadius2 * Math.sin((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() + val cX = (centerX + currentRadius2 * cos((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() + val cY = (centerY + currentRadius2 * sin((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)).toFloat() canvas.drawCircle(cX, cY, currentDotSize2, circlePaints[(i + 1) % circlePaints.size]) } }