mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Improve the responsiveness of the timebar preview
This commit is contained in:
parent
b92bfa87ed
commit
c4a2d91fd4
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.ui.extensions
|
package com.github.libretube.ui.extensions
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
|
@ -17,29 +17,19 @@ class SeekbarPreviewListener(
|
|||||||
) : TimeBar.OnScrubListener {
|
) : TimeBar.OnScrubListener {
|
||||||
private var moving = false
|
private var moving = false
|
||||||
|
|
||||||
override fun onScrubStart(timeBar: TimeBar, position: Long) {}
|
override fun onScrubStart(timeBar: TimeBar, position: Long) {
|
||||||
|
moving = true
|
||||||
|
|
||||||
|
processPreview(position)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a preview of the scrubber position
|
* Show a preview of the scrubber position
|
||||||
*/
|
*/
|
||||||
override fun onScrubMove(timeBar: TimeBar, position: Long) {
|
override fun onScrubMove(timeBar: TimeBar, position: Long) {
|
||||||
moving = true
|
moving = true
|
||||||
val previewFrame = getPreviewFrame(position) ?: return
|
|
||||||
|
|
||||||
// update the offset of the preview image view
|
processPreview(position)
|
||||||
updatePreviewX(position)
|
|
||||||
|
|
||||||
val request = ImageRequest.Builder(previewIv.context)
|
|
||||||
.data(previewFrame.previewUrl)
|
|
||||||
.target {
|
|
||||||
if (!moving) return@target
|
|
||||||
val frame = cutOutBitmap(it.toBitmap(), previewFrame)
|
|
||||||
previewIv.setImageBitmap(frame)
|
|
||||||
previewIv.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
.build()
|
|
||||||
|
|
||||||
ImageHelper.imageLoader.enqueue(request)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,6 +50,28 @@ class SeekbarPreviewListener(
|
|||||||
.start()
|
.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a request to get the image frame and update its position
|
||||||
|
*/
|
||||||
|
private fun processPreview(position: Long) {
|
||||||
|
val previewFrame = getPreviewFrame(position) ?: return
|
||||||
|
|
||||||
|
// update the offset of the preview image view
|
||||||
|
updatePreviewX(position)
|
||||||
|
|
||||||
|
val request = ImageRequest.Builder(previewIv.context)
|
||||||
|
.data(previewFrame.previewUrl)
|
||||||
|
.target {
|
||||||
|
if (!moving) return@target
|
||||||
|
val frame = cutOutBitmap(it.toBitmap(), previewFrame)
|
||||||
|
previewIv.setImageBitmap(frame)
|
||||||
|
previewIv.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
|
||||||
|
ImageHelper.imageLoader.enqueue(request)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the preview frame according to the current position
|
* Get the preview frame according to the current position
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user