From c634cd9c9c8ad034e52830bf796a6ab57fea8055 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 31 Jan 2023 15:37:10 +0100 Subject: [PATCH] Simplify watch progress length extension --- .../ui/extensions/SetWatchProgressLength.kt | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt index 333975bb4..05bbede85 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt @@ -12,15 +12,11 @@ import com.github.libretube.extensions.awaitQuery * @param duration The duration of the video in seconds * @return Whether the video is already watched more than 90% */ -fun View?.setWatchProgressLength(videoId: String, duration: Long): Boolean { - val view = this!! - - view.apply { - updateLayoutParams { - matchConstraintPercentWidth = 0f - } - visibility = View.GONE +fun View.setWatchProgressLength(videoId: String, duration: Long): Boolean { + updateLayoutParams { + matchConstraintPercentWidth = 0f } + visibility = View.GONE val progress = try { awaitQuery { @@ -35,12 +31,10 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long): Boolean { return false } - view.apply { - updateLayoutParams { - matchConstraintPercentWidth = (progress / duration.toFloat()) - } - visibility = View.VISIBLE + updateLayoutParams { + matchConstraintPercentWidth = progress / duration.toFloat() } + visibility = View.VISIBLE return progress / duration.toFloat() > 0.9 }