mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 14:50:30 +05:30
Merge pull request #2117 from Bnyro/master
add a button to toggle SponsorBlock while playing a video
This commit is contained in:
commit
c8a301bb4e
@ -143,7 +143,10 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
*/
|
||||
private lateinit var exoPlayer: ExoPlayer
|
||||
private lateinit var trackSelector: DefaultTrackSelector
|
||||
private lateinit var segmentData: SegmentData
|
||||
|
||||
/**
|
||||
* Chapters and comments
|
||||
*/
|
||||
private lateinit var chapters: List<ChapterSegment>
|
||||
private val comments: MutableList<Comment> = mutableListOf()
|
||||
private var commentsNextPage: String? = null
|
||||
@ -159,6 +162,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
*/
|
||||
private lateinit var nowPlayingNotification: NowPlayingNotification
|
||||
|
||||
/**
|
||||
* SponsorBlock
|
||||
*/
|
||||
private lateinit var segmentData: SegmentData
|
||||
private var sponsorBlockEnabled = PlayerHelper.sponsorBlockEnabled
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
@ -354,6 +363,17 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
}
|
||||
|
||||
val updateSbImageResource = {
|
||||
playerBinding.sbToggle.setImageResource(
|
||||
if (sponsorBlockEnabled) R.drawable.ic_sb_enabled else R.drawable.ic_sb_disabled
|
||||
)
|
||||
}
|
||||
updateSbImageResource()
|
||||
playerBinding.sbToggle.setOnClickListener {
|
||||
sponsorBlockEnabled = !sponsorBlockEnabled
|
||||
updateSbImageResource()
|
||||
}
|
||||
|
||||
// share button
|
||||
binding.relPlayerShare.setOnClickListener {
|
||||
if (!this::streams.isInitialized) return@setOnClickListener
|
||||
@ -517,6 +537,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
|
||||
Handler(Looper.getMainLooper()).postDelayed(this::checkForSegments, 100)
|
||||
|
||||
if (!sponsorBlockEnabled) return
|
||||
|
||||
if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) return
|
||||
|
||||
val currentPosition = exoPlayer.currentPosition
|
||||
@ -535,12 +557,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
if (PlayerHelper.sponsorBlockNotifications) {
|
||||
Toast
|
||||
.makeText(
|
||||
context,
|
||||
R.string.segment_skipped,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
Toast.makeText(context, R.string.segment_skipped, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
// skip the segment automatically
|
||||
@ -553,7 +570,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
private fun playVideo() {
|
||||
// reset the player view
|
||||
playerBinding.exoProgress.clearSegments()
|
||||
playerBinding.sbToggle.visibility = View.GONE
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
streams = try {
|
||||
@ -641,6 +660,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
ObjectMapper().writeValueAsString(categories)
|
||||
)
|
||||
playerBinding.exoProgress.setSegments(segmentData.segments)
|
||||
runOnUiThread {
|
||||
playerBinding.sbToggle.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
app/src/main/res/drawable/ic_sb_disabled.xml
Normal file
13
app/src/main/res/drawable/ic_sb_disabled.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="@android:color/white"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,22.7994C11.55,22.7994 11.1,22.7094 10.74,22.4394 4.89,18.8394 1.29,12.6294 1.2,5.7894 1.2,4.8894 1.65,3.9894 2.46,3.5394 8.4,0.3894 15.6,0.3894 21.54,3.6294 22.35,3.9894 22.8,4.8894 22.8,5.7894 22.71,12.6294 19.11,18.8394 13.35,22.4394 12.9,22.7094 12.45,22.7994 12,22.7994ZM12,1.9194c-3.15,0 -6.3,0.81 -9.18,2.34 -0.54,0.27 -0.9,0.9 -0.9,1.53 0.09,6.57 3.51,12.51 9.18,16.02 0.54,0.36 1.26,0.36 1.8,0C18.57,18.3894 21.9,12.3594 22.08,5.7894 22.08,5.1594 21.72,4.5294 21.18,4.2594 18.3,2.7294 15.15,1.9194 12,1.9194Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20.73,4.9794C15.24,2.0994 8.76,2.0994 3.27,4.9794 3,5.1594 2.82,5.4294 2.82,5.7894c0.09,6.48 3.51,12.06 8.73,15.3 0.27,0.18 0.63,0.18 0.9,0 5.13,-3.15 8.64,-8.82 8.73,-15.3C21.18,5.4294 21,5.1594 20.73,4.9794ZM12,15.4194c0,0 -4.5,-3.6 -4.5,-5.94 0,-1.53 0.99,-2.43 2.25,-2.43 1.08,0 2.25,1.17 2.25,1.17 0,0 1.08,-1.17 2.25,-1.17 1.26,0 2.25,0.81 2.25,2.43 0,2.34 -4.5,5.94 -4.5,5.94z"/>
|
||||
</vector>
|
19
app/src/main/res/drawable/ic_sb_enabled.xml
Normal file
19
app/src/main/res/drawable/ic_sb_enabled.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="@android:color/white"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,22.7994C11.55,22.7994 11.1,22.7094 10.74,22.4394 4.89,18.8394 1.29,12.6294 1.2,5.7894 1.2,4.8894 1.65,3.9894 2.46,3.5394 8.4,0.3894 15.6,0.3894 21.54,3.6294 22.35,3.9894 22.8,4.8894 22.8,5.7894 22.71,12.6294 19.11,18.8394 13.35,22.4394 12.9,22.7094 12.45,22.7994 12,22.7994ZM12,1.9194c-3.15,0 -6.3,0.81 -9.18,2.34 -0.54,0.27 -0.9,0.9 -0.9,1.53 0.09,6.57 3.51,12.51 9.18,16.02 0.54,0.36 1.26,0.36 1.8,0C18.57,18.3894 21.9,12.3594 22.08,5.7894 22.08,5.1594 21.72,4.5294 21.18,4.2594 18.3,2.7294 15.15,1.9194 12,1.9194Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20.73,4.9794C15.24,2.0994 8.76,2.0994 3.27,4.9794 3,5.1594 2.82,5.4294 2.82,5.7894c0.09,6.48 3.51,12.06 8.73,15.3 0.27,0.18 0.63,0.18 0.9,0 5.13,-3.15 8.64,-8.82 8.73,-15.3C21.18,5.4294 21,5.1594 20.73,4.9794ZM12,15.8694c-2.79,0 -4.95,-2.25 -4.95,-4.95 0,-2.7 2.25,-4.95 4.95,-4.95 2.7,0 4.95,2.25 4.95,4.95 0,2.79 -2.16,4.95 -4.95,4.95z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m15.15,13.4394c0.54,-0.72 0.9,-1.53 0.9,-2.52 0,-2.25 -1.8,-4.05 -4.05,-4.05 -0.9,0 -1.8,0.36 -2.52,0.9z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m8.85,8.4894c-0.54,0.72 -0.9,1.53 -0.9,2.52 0,2.25 1.8,4.05 4.05,4.05 0.9,0 1.8,-0.36 2.52,-0.9z"/>
|
||||
</vector>
|
@ -67,6 +67,14 @@
|
||||
android:layout_gravity="center"
|
||||
android:layoutDirection="ltr">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/sb_toggle"
|
||||
style="@style/PlayerControlTop"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:src="@drawable/ic_sb_enabled"
|
||||
android:visibility="gone"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/queue_toggle"
|
||||
style="@style/PlayerControlTop"
|
||||
|
Loading…
Reference in New Issue
Block a user