Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import com.lagradost.cloudstream3.isEpisodeBased
import com.lagradost.cloudstream3.isLiveStream
import com.lagradost.cloudstream3.isMovieType
import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.launchSafe
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.mvvm.observeNullable
Expand Down Expand Up @@ -131,13 +132,15 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.io.Serializable
import java.util.Calendar
import kotlin.coroutines.cancellation.CancellationException

@OptIn(UnstableApi::class)
class GeneratorPlayer : FullScreenPlayer() {
companion object {
const val NOTIFICATION_ID = 2326
const val CHANNEL_ID = 7340
const val STOP_ACTION = "stopcs3"
private const val SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS = 5

private var lastUsedGenerator: IGenerator? = null
fun newInstance(generator: IGenerator, syncData: HashMap<String, String>? = null): Bundle {
Expand Down Expand Up @@ -1996,12 +1999,70 @@ class GeneratorPlayer : FullScreenPlayer() {
}

override fun onDestroyView() {
clearSkipChapterAutoClick()
binding = null
super.onDestroyView()
}

var skipAnimator: ValueAnimator? = null
var skipIndex = 0
private var skipAutoClickJob: Job? = null

private fun isAutoSkipPopupEnabled(): Boolean {
val ctx = context ?: return false
return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean(
ctx.getString(R.string.auto_skip_popup_key),
false
)
}

private fun updateSkipChapterButtonText(
timestamp: VideoSkipStamp,
secondsRemaining: Int? = null
) {
val text = if (isAutoSkipPopupEnabled() && secondsRemaining != null) {
txt(R.string.skip_chapter_countdown_format, timestamp.uiText, secondsRemaining)
} else {
timestamp.uiText
}

playerBinding?.skipChapterButton?.setText(text)
}

private fun clearSkipChapterAutoClick() {
skipAutoClickJob?.cancel()
skipAutoClickJob = null
}

private fun startSkipChapterAutoClick(timestamp: VideoSkipStamp, currentIndex: Int) {
clearSkipChapterAutoClick()
if (!isAutoSkipPopupEnabled()) {
updateSkipChapterButtonText(timestamp)
return
}

skipAutoClickJob = viewModel.viewModelScope.launchSafe {
try {
for (secondsRemaining in SKIP_CHAPTER_AUTO_CLICK_COUNTDOWN_SECONDS downTo 1) {
if (!isActive) return@launchSafe
if (skipIndex != currentIndex) return@launchSafe

updateSkipChapterButtonText(timestamp, secondsRemaining)
delay(1000)
}

if (isActive && skipIndex == currentIndex) {
player.handleEvent(CSPlayerEvent.SkipCurrentChapter)
}
} catch (_: CancellationException) {
// If we get canceled, do nothing.
} finally {
Comment thread
phisher98 marked this conversation as resolved.
if (isActive) {
clearSkipChapterAutoClick()
}
}
}
}

private fun displayTimeStamp(show: Boolean) {
if (timestampShowState == show) return
Expand Down Expand Up @@ -2035,7 +2096,6 @@ class GeneratorPlayer : FullScreenPlayer() {
} else {
playerBinding?.skipChapterButton?.isVisible = false
if (!isShowing) {
// Automatically return focus to play pause
playerBinding?.playerPausePlay?.requestFocus()
}
}
Expand All @@ -2053,6 +2113,7 @@ class GeneratorPlayer : FullScreenPlayer() {
}

override fun onTimestampSkipped(timestamp: VideoSkipStamp) {
clearSkipChapterAutoClick()
displayTimeStamp(false)
}

Expand All @@ -2065,7 +2126,9 @@ class GeneratorPlayer : FullScreenPlayer() {
if (skipIndex == currentIndex)
displayTimeStamp(false)
}, 6000)
startSkipChapterAutoClick(timestamp, currentIndex)
} else {
clearSkipChapterAutoClick()
displayTimeStamp(false)
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/player_custom_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,12 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/skip_chapter_button"
style="@style/NiceButton"
android:layout_width="150dp"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="100dp"
android:backgroundTint="@color/skipOpTransparent"
android:ellipsize="end"
android:maxLines="1"
android:padding="10dp"
android:textColor="@color/white"
Expand Down Expand Up @@ -1137,4 +1138,4 @@

</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</FrameLayout>
</FrameLayout>
5 changes: 3 additions & 2 deletions app/src/main/res/layout/player_custom_layout_tv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,11 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/skip_chapter_button"
style="@style/NiceButton"
android:layout_width="150dp"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginEnd="100dp"
android:backgroundTint="@color/skipOpTransparent"
android:ellipsize="end"
android:maxLines="1"
android:nextFocusLeft="@id/player_pause_play"
android:nextFocusUp="@id/player_restart"
Expand Down Expand Up @@ -1145,4 +1146,4 @@
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>

</FrameLayout>
</FrameLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/donottranslate-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="android_tv_interface_on_seek_key">android_tv_interface_on_seek_key</string>
<string name="swipe_vertical_enabled_key">swipe_vertical_enabled_key</string>
<string name="autoplay_next_key">autoplay_next_key</string>
<string name="auto_skip_popup_key">auto_skip_popup_key</string>
<string name="display_sub_key">display_sub_key</string>
<string name="show_fillers_key">show_fillers_key</string>
<string name="show_player_metadata_key">show_player_metadata_key</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
<string name="swipe_to_change_settings_des">Slide up or down on the left or right side to change brightness or volume</string>
<string name="autoplay_next_settings">Autoplay next episode</string>
<string name="autoplay_next_settings_des">Start the next episode when the current one ends</string>
<string name="auto_skip_popup_settings">Auto-skip OP</string>
<string name="auto_skip_popup_settings_des">Automatically SKIP OP after 5 seconds</string>
<string name="double_tap_to_seek_settings">Double tap to seek</string>
<string name="double_tap_to_pause_settings">Double tap to pause</string>
<string name="double_tap_to_seek_amount_settings">Player seek amount (Seconds)</string>
Expand Down Expand Up @@ -561,6 +563,7 @@
<string name="skip_type_mixed_op">Mixed opening</string>
<string name="skip_type_creddits">Credits</string>
<string name="skip_type_intro">Intro</string>
<string name="skip_chapter_countdown_format" formatted="true">%1$s (%2$d)</string>
<string name="clear_history">Clear history</string>
<string name="history">History</string>
<string name="enable_skip_op_from_database_des">Show skip popups for opening/ending</string>
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/xml/settings_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
android:title="@string/video_skip_op"
app:defaultValue="true"
app:key="@string/enable_skip_op_from_database" />
<SwitchPreference
android:icon="@drawable/ic_baseline_skip_next_24"
android:summary="@string/auto_skip_popup_settings_des"
android:title="@string/auto_skip_popup_settings"
app:defaultValue="false"
app:key="@string/auto_skip_popup_key" />
<SwitchPreference
android:icon="@drawable/screen_rotation"
android:summary="@string/rotate_video_desc"
Expand Down Expand Up @@ -222,4 +228,4 @@
app:seekBarIncrement="5"
app:showSeekBarValue="true" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>