2022-07-28 12:48:32 +05:30
|
|
|
package com.github.libretube.util
|
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewTreeObserver
|
2022-07-29 15:10:36 +05:30
|
|
|
import android.widget.LinearLayout
|
2022-07-28 12:48:32 +05:30
|
|
|
import com.github.libretube.preferences.PreferenceHelper
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shows the already watched time under the video
|
|
|
|
*/
|
|
|
|
fun View?.setWatchProgressLength(videoId: String, duration: Long) {
|
|
|
|
val view = this!!
|
|
|
|
val positions = PreferenceHelper.getWatchPositions()
|
|
|
|
var newWidth: Long? = null
|
|
|
|
view.getViewTreeObserver()
|
|
|
|
.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
|
|
|
override fun onGlobalLayout() {
|
|
|
|
this@setWatchProgressLength.getViewTreeObserver().removeOnGlobalLayoutListener(this)
|
|
|
|
positions.forEach {
|
|
|
|
if (it.videoId == videoId) {
|
2022-07-29 15:10:36 +05:30
|
|
|
val fullWidth = (parent as LinearLayout).width
|
|
|
|
newWidth = (fullWidth * (it.position / (duration))) / 1000
|
2022-07-28 12:48:32 +05:30
|
|
|
return@forEach
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newWidth != null) {
|
|
|
|
val lp = view.layoutParams
|
|
|
|
lp.apply {
|
|
|
|
width = newWidth!!.toInt()
|
|
|
|
}
|
|
|
|
view.layoutParams = lp
|
2022-07-29 15:10:36 +05:30
|
|
|
view.visibility = View.VISIBLE
|
2022-07-28 12:48:32 +05:30
|
|
|
} else {
|
|
|
|
view.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|