mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Use Kotlin math functions.
This commit is contained in:
parent
372a5ba1ec
commit
36bd2290e9
2 changed files with 12 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue