mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
add option for manually skipping sponsorblock segments
This commit is contained in:
parent
f6929ee00c
commit
5034d461ae
@ -75,6 +75,7 @@ object PreferenceKeys {
|
|||||||
const val SKIP_BUTTONS = "skip_buttons"
|
const val SKIP_BUTTONS = "skip_buttons"
|
||||||
const val PICTURE_IN_PICTURE = "picture_in_picture"
|
const val PICTURE_IN_PICTURE = "picture_in_picture"
|
||||||
const val PLAYER_RESIZE_MODE = "player_resize_mode"
|
const val PLAYER_RESIZE_MODE = "player_resize_mode"
|
||||||
|
const val SB_SKIP_MANUALLY = "sb_skip_manually"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Background mode
|
* Background mode
|
||||||
|
@ -169,6 +169,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
private var sponsorBlockNotifications = true
|
private var sponsorBlockNotifications = true
|
||||||
private var skipButtonsEnabled = false
|
private var skipButtonsEnabled = false
|
||||||
private var pipEnabled = true
|
private var pipEnabled = true
|
||||||
|
private var skipSegmentsManually = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for autoplay
|
* for autoplay
|
||||||
@ -336,6 +337,11 @@ class PlayerFragment : BaseFragment() {
|
|||||||
PreferenceKeys.PICTURE_IN_PICTURE,
|
PreferenceKeys.PICTURE_IN_PICTURE,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
skipSegmentsManually = PreferenceHelper.getBoolean(
|
||||||
|
PreferenceKeys.SB_SKIP_MANUALLY,
|
||||||
|
false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@ -709,21 +715,36 @@ class PlayerFragment : BaseFragment() {
|
|||||||
|
|
||||||
Handler(Looper.getMainLooper()).postDelayed(this::checkForSegments, 100)
|
Handler(Looper.getMainLooper()).postDelayed(this::checkForSegments, 100)
|
||||||
|
|
||||||
if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) {
|
if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
val currentPosition = exoPlayer.currentPosition
|
||||||
segmentData.segments.forEach { segment: Segment ->
|
segmentData.segments.forEach { segment: Segment ->
|
||||||
val segmentStart = (segment.segment!![0] * 1000f).toLong()
|
val segmentStart = (segment.segment!![0] * 1000f).toLong()
|
||||||
val segmentEnd = (segment.segment[1] * 1000f).toLong()
|
val segmentEnd = (segment.segment[1] * 1000f).toLong()
|
||||||
val currentPosition = exoPlayer.currentPosition
|
|
||||||
if (currentPosition in segmentStart until segmentEnd) {
|
if (currentPosition in segmentStart until segmentEnd) {
|
||||||
if (sponsorBlockNotifications) {
|
if (skipSegmentsManually) {
|
||||||
Toast.makeText(context, R.string.segment_skipped, Toast.LENGTH_SHORT).show()
|
binding.sbSkipBtn.visibility = View.VISIBLE
|
||||||
|
binding.sbSkipBtn.setOnClickListener {
|
||||||
|
exoPlayer.seekTo(segmentEnd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sponsorBlockNotifications) {
|
||||||
|
Toast
|
||||||
|
.makeText(
|
||||||
|
context,
|
||||||
|
R.string.segment_skipped,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
|
||||||
exoPlayer.seekTo(segmentEnd)
|
exoPlayer.seekTo(segmentEnd)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (skipSegmentsManually) binding.sbSkipBtn.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun playVideo() {
|
private fun playVideo() {
|
||||||
|
@ -378,8 +378,34 @@
|
|||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center" />
|
android:gravity="center" />
|
||||||
|
|
||||||
</com.github.libretube.views.CustomExoPlayerView>
|
<LinearLayout
|
||||||
|
android:id="@+id/sb_skip_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_marginBottom="60dp"
|
||||||
|
android:background="@android:color/black"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/skip_segment"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="20dp"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginHorizontal="10dp"
|
||||||
|
android:src="@drawable/ic_next"
|
||||||
|
app:tint="@android:color/white" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.github.libretube.views.CustomExoPlayerView>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/close_imageView"
|
android:id="@+id/close_imageView"
|
||||||
|
@ -321,4 +321,7 @@
|
|||||||
<string name="mobile_data">Mobile data</string>
|
<string name="mobile_data">Mobile data</string>
|
||||||
<string name="new_videos_badge">Indicator for new videos</string>
|
<string name="new_videos_badge">Indicator for new videos</string>
|
||||||
<string name="new_videos_badge_summary">Show a badge with the amount of new videos if there are some.</string>
|
<string name="new_videos_badge_summary">Show a badge with the amount of new videos if there are some.</string>
|
||||||
|
<string name="skip_segment">Skip segment</string>
|
||||||
|
<string name="sb_skip_manual">Skip manually</string>
|
||||||
|
<string name="sb_skip_manual_summary">Don\'t skip segments automatically, always prompt before.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -16,6 +16,12 @@
|
|||||||
app:key="sb_notifications_key"
|
app:key="sb_notifications_key"
|
||||||
app:title="@string/sponsorblock_notifications" />
|
app:title="@string/sponsorblock_notifications" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:summary="@string/sb_skip_manual_summary"
|
||||||
|
app:defaultValue="false"
|
||||||
|
app:key="sb_skip_manually_key"
|
||||||
|
app:title="@string/sb_skip_manual" />
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/category_segments">
|
<PreferenceCategory app:title="@string/category_segments">
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
|
Loading…
Reference in New Issue
Block a user