aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-06 00:45:36 -0700
committerAllan Wang <me@allanwang.ca>2019-08-06 00:45:36 -0700
commit8ef5d04f28f63a34ca099a9b7e3b887f0ed122a6 (patch)
tree19c8ed9e4d4ebc131192adf0aa6edeef5368fcfb /app/src/main/kotlin/com/pitchedapps/frost/views
parente5b3dbf51bfd63b230bedcaa67893dda82dd66e2 (diff)
downloadfrost-8ef5d04f28f63a34ca099a9b7e3b887f0ed122a6.tar.gz
frost-8ef5d04f28f63a34ca099a9b7e3b887f0ed122a6.tar.bz2
frost-8ef5d04f28f63a34ca099a9b7e3b887f0ed122a6.zip
Use kotlin math
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt21
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt16
2 files changed, 24 insertions, 13 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
index f21476fb..351f2236 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
@@ -35,6 +35,9 @@ import com.devbrackets.android.exomedia.ui.widget.VideoView
import com.pitchedapps.frost.R
import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.utils.L
+import kotlin.math.abs
+import kotlin.math.max
+import kotlin.math.min
/**
* Created by Allan Wang on 2017-10-13.
@@ -119,11 +122,11 @@ class FrostVideoView @JvmOverloads constructor(
private fun mapBounds(): Triple<Float, Float, Float> {
if (videoDimensions.x <= 0f || videoDimensions.y <= 0f) {
L.d { "Attempted to toggle video expansion when points have not been finalized" }
- val dimen = Math.min(height, width).toFloat()
+ val dimen = min(height, width).toFloat()
videoDimensions.set(dimen, dimen)
}
val portrait = height > width
- val scale = Math.min(
+ val scale = min(
height / (if (portrait) 4f else 2.3f) / videoDimensions.y,
width / (if (portrait) 2.3f else 4f) / videoDimensions.x
)
@@ -167,10 +170,8 @@ class FrostVideoView @JvmOverloads constructor(
v.setOnTouchListener(VideoTouchListener(context))
setOnVideoSizedChangedListener { intrinsicWidth, intrinsicHeight, pixelWidthHeightRatio ->
// todo use provided ratio?
- val ratio = Math.min(
- width.toFloat() / intrinsicWidth,
- height.toFloat() / intrinsicHeight.toFloat()
- )
+ val ratio =
+ min(width.toFloat() / intrinsicWidth, height.toFloat() / intrinsicHeight.toFloat())
/**
* Only remap if not expanded and if dimensions have changed
*/
@@ -240,7 +241,7 @@ class FrostVideoView @JvmOverloads constructor(
private fun onHorizontalSwipe(offset: Float) {
val alpha =
- Math.max((1f - Math.abs(offset / SWIPE_TO_CLOSE_OFFSET_THRESHOLD)) * 0.5f + 0.5f, 0f)
+ max((1f - abs(offset / SWIPE_TO_CLOSE_OFFSET_THRESHOLD)) * 0.5f + 0.5f, 0f)
this.alpha = alpha
}
@@ -305,9 +306,9 @@ class FrostVideoView @JvmOverloads constructor(
translationX = baseTranslateX - dx
onHorizontalSwipe(dx)
} else if (checkForDismiss) {
- if (Math.abs(event.rawY - downLoc.y) > SWIPE_TO_CLOSE_VERTICAL_THRESHOLD)
+ if (abs(event.rawY - downLoc.y) > SWIPE_TO_CLOSE_VERTICAL_THRESHOLD)
checkForDismiss = false
- else if (Math.abs(event.rawX - downLoc.x) > SWIPE_TO_CLOSE_HORIZONTAL_THRESHOLD) {
+ else if (abs(event.rawX - downLoc.x) > SWIPE_TO_CLOSE_HORIZONTAL_THRESHOLD) {
onSwipe = true
baseSwipeX = event.rawX
baseTranslateX = translationX
@@ -316,7 +317,7 @@ class FrostVideoView @JvmOverloads constructor(
}
MotionEvent.ACTION_UP -> {
if (onSwipe) {
- if (Math.abs(baseSwipeX - event.rawX) > SWIPE_TO_CLOSE_OFFSET_THRESHOLD)
+ if (abs(baseSwipeX - event.rawX) > SWIPE_TO_CLOSE_OFFSET_THRESHOLD)
destroy()
else
animate().translationX(baseTranslateX).setDuration(
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
index 1dd027fd..cbcd1054 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -43,6 +43,9 @@ import com.pitchedapps.frost.web.FrostJSI
import com.pitchedapps.frost.web.FrostWebViewClient
import com.pitchedapps.frost.web.NestedWebView
import com.pitchedapps.frost.web.shouldUseDesktopAgent
+import kotlin.math.abs
+import kotlin.math.max
+import kotlin.math.min
/**
* Created by Allan Wang on 2017-05-29.
@@ -89,7 +92,14 @@ class FrostWebView @JvmOverloads constructor(
setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
context.ctxCoroutine.launchMain {
val cookie = db.cookieDao().currentCookie() ?: return@launchMain
- context.frostDownload(cookie, url, userAgent, contentDisposition, mimetype, contentLength)
+ context.frostDownload(
+ cookie,
+ url,
+ userAgent,
+ contentDisposition,
+ mimetype,
+ contentLength
+ )
}
}
return this
@@ -163,14 +173,14 @@ class FrostWebView @JvmOverloads constructor(
private fun smoothScrollTo(y: Int) {
ValueAnimator.ofInt(scrollY, y).apply {
- duration = Math.min(Math.abs(scrollY - y), 500).toLong()
+ duration = min(abs(scrollY - y), 500).toLong()
interpolator = AnimHolder.fastOutSlowInInterpolator(context)
addUpdateListener { scrollY = it.animatedValue as Int }
start()
}
}
- private fun smoothScrollBy(y: Int) = smoothScrollTo(Math.max(0, scrollY + y))
+ private fun smoothScrollBy(y: Int) = smoothScrollTo(max(0, scrollY + y))
override var active: Boolean = true
set(value) {