Skip to content

Commit

Permalink
Rework the logic for auto and button
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Oct 11, 2024
1 parent c0a185d commit 3a0d011
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ private void initActions(Context context) {
zoomAction.setLabels(new String[]{context.getString(R.string.lbl_zoom)});
selectSkipAction = new SelectSkipAction(context, this, KoinJavaComponent.get(UserPreferences.class));
selectSkipAction.setLabels(new String[]{
context.getString(SegmentMode.AUTO_SKIP.label()),
context.getString(SegmentMode.SHOW_SKIP_BUTTON.label()),
context.getString(SegmentMode.HIDE_SKIP_BUTTON.label())
context.getString(SegmentMode.AUTO_SKIP.getNameRes()),
context.getString(SegmentMode.SHOW_SKIP_BUTTON.getNameRes()),
context.getString(SegmentMode.HIDE_SKIP_BUTTON.getNameRes())
});
chapterAction = new ChapterAction(context, this);
chapterAction.setLabels(new String[]{context.getString(R.string.lbl_chapters)});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.PopupMenu
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.ui.playback.PlaybackController
import org.jellyfin.androidtv.ui.playback.overlay.CustomPlaybackTransportControlGlue
Expand All @@ -18,8 +19,15 @@ class SelectSkipAction(
private val preferences = userPreferences
private val customPlaybackTransportControlGlue1 = customPlaybackTransportControlGlue

private val SegmentMode.icon: Int
get() = when (this) {
SegmentMode.SHOW_SKIP_BUTTON -> R.drawable.ic_select_skip_show_button
SegmentMode.AUTO_SKIP -> R.drawable.ic_select_skip_auto_skip
SegmentMode.HIDE_SKIP_BUTTON -> R.drawable.ic_select_skip_hide_button
}

init {
initializeWithIcon(preferences[UserPreferences.skipMode].icon())
initializeWithIcon(preferences[UserPreferences.skipMode].icon)
}

override fun handleClickAction(
Expand All @@ -31,7 +39,7 @@ class SelectSkipAction(
videoPlayerAdapter.leanbackOverlayFragment.setFading(false)
PopupMenu(context, view, Gravity.END).apply {
SegmentMode.entries.forEach {
menu.add(0, it.ordinal, it.ordinal, context.getString(it.label())).apply {
menu.add(0, it.ordinal, it.ordinal, context.getString(it.nameRes)).apply {
isChecked = preferences[UserPreferences.skipMode] == it
}
}
Expand All @@ -44,7 +52,7 @@ class SelectSkipAction(
setOnMenuItemClickListener { item ->
preferences[UserPreferences.skipMode] = SegmentMode.entries[item.itemId]

initializeWithIcon(preferences[UserPreferences.skipMode].icon())
initializeWithIcon(preferences[UserPreferences.skipMode].icon)
customPlaybackTransportControlGlue1.notifyActionChanged(this@SelectSkipAction)
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import kotlinx.serialization.Serializable

@Serializable
data class SegmentButtonConfig(
@SerialName("SkipButtonIntroText")
val skipButtonIntroText: String,
@SerialName("SkipButtonEndCreditsText")
val skipButtonEndCreditsText: String,
@SerialName("SkipButtonVisible")
val skipButtonVisible: Boolean
@SerialName("SkipButtonIntroText")
val skipButtonIntroText: String,
@SerialName("SkipButtonEndCreditsText")
val skipButtonEndCreditsText: String,
@SerialName("SkipButtonVisible")
val skipButtonVisible: Boolean,
@SerialName("AutoSkip")
val autoSkip: Boolean,
@SerialName("AutoSkipCredits")
val autoSkipCredits: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,36 @@ class SegmentSkipFragment : Fragment() {
}

fun handleProgress(currentPosition: Long) {
// Check if server is full auto
if (buttonConfig?.autoSkip == true && buttonConfig?.autoSkipCredits == true) {
button.isVisible = false
return
}

val currentSegment = getCurrentSegment(currentPosition) ?: lastSegment ?: return
lastSegment = currentSegment

val isSkipSegment = currentPosition >= currentSegment.showAt.millis && currentPosition < currentSegment.hideAt.millis

if (!button.isVisible && isSkipSegment && preferences[UserPreferences.skipMode] == SegmentMode.SHOW_SKIP_BUTTON
&& buttonConfig?.skipButtonVisible == true) {
button.isVisible = true
updateButtonText(currentSegment)
button.requestFocus()
} else if (button.isVisible && (!isSkipSegment || preferences[UserPreferences.skipMode] != SegmentMode.SHOW_SKIP_BUTTON)) {
button.isVisible = false
}

if (isSkipSegment && preferences[UserPreferences.skipMode] == SegmentMode.AUTO_SKIP) {
doSkip()
preferences[UserPreferences.skipMode].let { setting ->
when {
isSkipSegment && setting == SegmentMode.AUTO_SKIP -> doSkip()
isSkipSegment && setting == SegmentMode.SHOW_SKIP_BUTTON -> {
if (!button.isVisible) {
button.isVisible = true
updateButtonText(currentSegment)
button.requestFocus()
}
}
else -> {
button.isVisible = false
}
}
}
}

suspend fun onStartItem(item: BaseItemDto) {
button.visibility = View.GONE
button.isVisible = false
segments = getSegments(item.id)
buttonConfig = getButtonConfig()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.jellyfin.androidtv.ui.playback.segments

import org.jellyfin.androidtv.R
import org.jellyfin.preference.PreferenceEnum

enum class SegmentMode {
SHOW_SKIP_BUTTON {
override fun icon(): Int = R.drawable.ic_select_skip_show_button
override fun label(): Int = R.string.lbl_show_skip_button
},
AUTO_SKIP {
override fun icon(): Int = R.drawable.ic_select_skip_auto_skip
override fun label(): Int = R.string.lbl_auto_skip
},
HIDE_SKIP_BUTTON {
override fun icon(): Int = R.drawable.ic_select_skip_hide_button
override fun label(): Int = R.string.lbl_hide_skip_button
};

abstract fun icon(): Int
abstract fun label(): Int
enum class SegmentMode(
override val nameRes: Int,
) : PreferenceEnum {
/**
* Show a skip button
*/
SHOW_SKIP_BUTTON(R.string.lbl_show_skip_button),
/**
* Automatically skip
*/
AUTO_SKIP(R.string.lbl_auto_skip),
/**
* No action is taken
*/
HIDE_SKIP_BUTTON(R.string.lbl_hide_skip_button),
}

0 comments on commit 3a0d011

Please sign in to comment.