mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Simplify watch progress length extension
This commit is contained in:
parent
25c0d3c0c8
commit
c634cd9c9c
@ -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!!
|
|
||||||
|
|
||||||
view.apply {
|
|
||||||
updateLayoutParams<ConstraintLayout.LayoutParams> {
|
updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||||
matchConstraintPercentWidth = 0f
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user