Simplify watch progress length extension

This commit is contained in:
Bnyro 2023-01-31 15:37:10 +01:00
parent 25c0d3c0c8
commit c634cd9c9c

View File

@ -12,15 +12,11 @@ import com.github.libretube.extensions.awaitQuery
* @param duration The duration of the video in seconds * @param duration The duration of the video in seconds
* @return Whether the video is already watched more than 90% * @return Whether the video is already watched more than 90%
*/ */
fun View?.setWatchProgressLength(videoId: String, duration: Long): Boolean { fun View.setWatchProgressLength(videoId: String, duration: Long): Boolean {
val view = this!! updateLayoutParams<ConstraintLayout.LayoutParams> {
matchConstraintPercentWidth = 0f
view.apply {
updateLayoutParams<ConstraintLayout.LayoutParams> {
matchConstraintPercentWidth = 0f
}
visibility = View.GONE
} }
visibility = View.GONE
val progress = try { val progress = try {
awaitQuery { awaitQuery {
@ -35,12 +31,10 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long): Boolean {
return false return false
} }
view.apply { updateLayoutParams<ConstraintLayout.LayoutParams> {
updateLayoutParams<ConstraintLayout.LayoutParams> { matchConstraintPercentWidth = progress / duration.toFloat()
matchConstraintPercentWidth = (progress / duration.toFloat())
}
visibility = View.VISIBLE
} }
visibility = View.VISIBLE
return progress / duration.toFloat() > 0.9 return progress / duration.toFloat() > 0.9
} }