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
|
||||||
|
@ -185,29 +185,29 @@ class PlaylistFragment : BaseFragment() {
|
|||||||
|
|
||||||
// listen for playlist items to become deleted
|
// listen for playlist items to become deleted
|
||||||
playlistAdapter!!.registerAdapterDataObserver(object :
|
playlistAdapter!!.registerAdapterDataObserver(object :
|
||||||
RecyclerView.AdapterDataObserver() {
|
RecyclerView.AdapterDataObserver() {
|
||||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||||
if (positionStart == 0) {
|
if (positionStart == 0) {
|
||||||
ImageHelper.loadImage(
|
ImageHelper.loadImage(
|
||||||
playlistFeed.firstOrNull()?.thumbnail ?: "",
|
playlistFeed.firstOrNull()?.thumbnail ?: "",
|
||||||
binding.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()
|
|
||||||
)
|
)
|
||||||
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.playlistRecView.adapter = playlistAdapter
|
||||||
binding.playlistScrollview.viewTreeObserver
|
binding.playlistScrollview.viewTreeObserver
|
||||||
|
@ -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