mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Cleanup #2504
This commit is contained in:
parent
2180f503fe
commit
d339e044c8
@ -5,6 +5,8 @@ import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.core.view.marginLeft
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.obj.Segment
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
@ -13,7 +15,6 @@ import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.ui.DefaultTimeBar
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* TimeBar that can be marked with SponsorBlock Segments
|
||||
@ -27,6 +28,8 @@ class MarkableTimeBar(
|
||||
private var player: Player? = null
|
||||
private var length: Int = 0
|
||||
|
||||
private val progressBarHeight = (2).toPixel().toInt()
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
drawSegments(canvas)
|
||||
@ -37,17 +40,19 @@ class MarkableTimeBar(
|
||||
|
||||
if (!PreferenceHelper.getBoolean(PreferenceKeys.SB_SHOW_MARKERS, true)) return
|
||||
|
||||
canvas.save()
|
||||
length = canvas.width - 2 * HORIZONTAL_OFFSET
|
||||
val horizontalOffset = (parent as View).marginLeft
|
||||
|
||||
val marginY = canvas.height / 2 - PROGRESS_BAR_HEIGHT / 2
|
||||
canvas.save()
|
||||
length = canvas.width - 2 * horizontalOffset
|
||||
|
||||
val marginY = canvas.height / 2 - progressBarHeight / 2
|
||||
|
||||
segments.forEach {
|
||||
canvas.drawRect(
|
||||
Rect(
|
||||
(it.segment.first() + HORIZONTAL_OFFSET).toLength(),
|
||||
(it.segment.first() + horizontalOffset).toLength(),
|
||||
marginY,
|
||||
(it.segment.last() + HORIZONTAL_OFFSET).toLength(),
|
||||
(it.segment.last() + horizontalOffset).toLength(),
|
||||
canvas.height - marginY
|
||||
),
|
||||
Paint().apply {
|
||||
@ -73,9 +78,4 @@ class MarkableTimeBar(
|
||||
fun setPlayer(player: Player) {
|
||||
this.player = player
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val HORIZONTAL_OFFSET = 10
|
||||
val PROGRESS_BAR_HEIGHT = (2).toPixel().roundToInt()
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +289,7 @@
|
||||
<LinearLayout
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="15dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user