add option for manually skipping sponsorblock segments

This commit is contained in:
Bnyro 2022-09-17 18:47:46 +02:00
parent f6929ee00c
commit 5034d461ae
5 changed files with 64 additions and 7 deletions

View File

@ -75,6 +75,7 @@ object PreferenceKeys {
const val SKIP_BUTTONS = "skip_buttons"
const val PICTURE_IN_PICTURE = "picture_in_picture"
const val PLAYER_RESIZE_MODE = "player_resize_mode"
const val SB_SKIP_MANUALLY = "sb_skip_manually"
/**
* Background mode

View File

@ -169,6 +169,7 @@ class PlayerFragment : BaseFragment() {
private var sponsorBlockNotifications = true
private var skipButtonsEnabled = false
private var pipEnabled = true
private var skipSegmentsManually = false
/**
* for autoplay
@ -336,6 +337,11 @@ class PlayerFragment : BaseFragment() {
PreferenceKeys.PICTURE_IN_PICTURE,
true
)
skipSegmentsManually = PreferenceHelper.getBoolean(
PreferenceKeys.SB_SKIP_MANUALLY,
false
)
}
@SuppressLint("ClickableViewAccessibility")
@ -709,21 +715,36 @@ class PlayerFragment : BaseFragment() {
Handler(Looper.getMainLooper()).postDelayed(this::checkForSegments, 100)
if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) {
return
}
if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) return
val currentPosition = exoPlayer.currentPosition
segmentData.segments.forEach { segment: Segment ->
val segmentStart = (segment.segment!![0] * 1000f).toLong()
val segmentEnd = (segment.segment[1] * 1000f).toLong()
val currentPosition = exoPlayer.currentPosition
if (currentPosition in segmentStart until segmentEnd) {
if (sponsorBlockNotifications) {
Toast.makeText(context, R.string.segment_skipped, Toast.LENGTH_SHORT).show()
if (skipSegmentsManually) {
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)
return
}
}
if (skipSegmentsManually) binding.sbSkipBtn.visibility = View.GONE
}
private fun playVideo() {

View File

@ -378,8 +378,34 @@
android:layout_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
android:id="@+id/close_imageView"

View File

@ -321,4 +321,7 @@
<string name="mobile_data">Mobile data</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="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>

View File

@ -16,6 +16,12 @@
app:key="sb_notifications_key"
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">
<SwitchPreferenceCompat