mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
Merge pull request #2638 from Bnyro/master
Improve the responsiveness of the timebar preview
This commit is contained in:
commit
a0289c652a
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.ui.extensions
|
||||
|
||||
import android.util.Log
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.material.button.MaterialButton
|
||||
|
@ -185,29 +185,29 @@ class PlaylistFragment : BaseFragment() {
|
||||
|
||||
// listen for playlist items to become deleted
|
||||
playlistAdapter!!.registerAdapterDataObserver(object :
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (positionStart == 0) {
|
||||
ImageHelper.loadImage(
|
||||
playlistFeed.firstOrNull()?.thumbnail ?: "",
|
||||
binding.thumbnail
|
||||
)
|
||||
}
|
||||
|
||||
val info = binding.playlistInfo.text.split(TextUtils.SEPARATOR)
|
||||
binding.playlistInfo.text = (
|
||||
if (info.size == 2) {
|
||||
info[0] + TextUtils.SEPARATOR
|
||||
} else {
|
||||
""
|
||||
}
|
||||
) + getString(
|
||||
R.string.videoCount,
|
||||
playlistAdapter!!.itemCount.toString()
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (positionStart == 0) {
|
||||
ImageHelper.loadImage(
|
||||
playlistFeed.firstOrNull()?.thumbnail ?: "",
|
||||
binding.thumbnail
|
||||
)
|
||||
super.onItemRangeRemoved(positionStart, itemCount)
|
||||
}
|
||||
})
|
||||
|
||||
val info = binding.playlistInfo.text.split(TextUtils.SEPARATOR)
|
||||
binding.playlistInfo.text = (
|
||||
if (info.size == 2) {
|
||||
info[0] + TextUtils.SEPARATOR
|
||||
} else {
|
||||
""
|
||||
}
|
||||
) + getString(
|
||||
R.string.videoCount,
|
||||
playlistAdapter!!.itemCount.toString()
|
||||
)
|
||||
super.onItemRangeRemoved(positionStart, itemCount)
|
||||
}
|
||||
})
|
||||
|
||||
binding.playlistRecView.adapter = playlistAdapter
|
||||
binding.playlistScrollview.viewTreeObserver
|
||||
|
@ -17,29 +17,19 @@ class SeekbarPreviewListener(
|
||||
) : TimeBar.OnScrubListener {
|
||||
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
|
||||
*/
|
||||
override fun onScrubMove(timeBar: TimeBar, position: Long) {
|
||||
moving = true
|
||||
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)
|
||||
processPreview(position)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,6 +50,28 @@ class SeekbarPreviewListener(
|
||||
.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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user