Skip to content

Commit

Permalink
Remove the need to override icon()
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Oct 11, 2024
1 parent 94d0965 commit 58c4925
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
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 @@ -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 @@ -6,16 +6,16 @@ import org.jellyfin.preference.PreferenceEnum
enum class SegmentMode(
override val nameRes: Int,
) : PreferenceEnum {

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

abstract fun icon(): Int
/**
* 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 58c4925

Please sign in to comment.