Enable nonFinalResIds

This commit is contained in:
Niels van Velzen 2023-04-13 22:54:33 +02:00 committed by Niels van Velzen
parent 15ccc6b930
commit d28fa5db69
21 changed files with 146 additions and 188 deletions

View file

@ -1,11 +1,11 @@
package org.jellyfin.androidtv.auth.model package org.jellyfin.androidtv.auth.model
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class AuthenticationSortBy { enum class AuthenticationSortBy(
@EnumDisplayOptions(name = R.string.last_use) override val nameRes: Int
LAST_USE, ) : PreferenceEnum {
@EnumDisplayOptions(name = R.string.alphabetical) LAST_USE(R.string.last_use),
ALPHABETICAL ALPHABETICAL(R.string.alphabetical);
} }

View file

@ -1,18 +1,18 @@
package org.jellyfin.androidtv.constant package org.jellyfin.androidtv.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class GridDirection { enum class GridDirection(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Horizontal. * Horizontal.
*/ */
@EnumDisplayOptions(R.string.grid_direction_horizontal) HORIZONTAL(R.string.grid_direction_horizontal),
HORIZONTAL,
/** /**
* Vertical. * Vertical.
*/ */
@EnumDisplayOptions(R.string.grid_direction_vertical) VERTICAL(R.string.grid_direction_vertical),
VERTICAL,
} }

View file

@ -1,7 +1,6 @@
package org.jellyfin.androidtv.constant package org.jellyfin.androidtv.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions
import org.jellyfin.preference.PreferenceEnum import org.jellyfin.preference.PreferenceEnum
/** /**
@ -10,35 +9,17 @@ import org.jellyfin.preference.PreferenceEnum
* https://github.com/jellyfin/jellyfin-web/blob/master/src/components/homesections/homesections.js * https://github.com/jellyfin/jellyfin-web/blob/master/src/components/homesections/homesections.js
*/ */
enum class HomeSectionType( enum class HomeSectionType(
override val serializedName: String override val serializedName: String,
override val nameRes: Int,
) : PreferenceEnum { ) : PreferenceEnum {
@EnumDisplayOptions(R.string.home_section_latest_media) LATEST_MEDIA("latestmedia", R.string.home_section_latest_media),
LATEST_MEDIA("latestmedia"), LIBRARY_TILES_SMALL("smalllibrarytiles", R.string.home_section_library),
LIBRARY_BUTTONS("librarybuttons", R.string.home_section_library_small),
@EnumDisplayOptions(R.string.home_section_library) RESUME("resume", R.string.home_section_resume),
LIBRARY_TILES_SMALL("smalllibrarytiles"), RESUME_AUDIO("resumeaudio", R.string.home_section_resume_audio),
RESUME_BOOK("resumebook", R.string.home_section_resume_book),
@EnumDisplayOptions(R.string.home_section_library_small) ACTIVE_RECORDINGS("activerecordings", R.string.home_section_active_recordings),
LIBRARY_BUTTONS("librarybuttons"), NEXT_UP("nextup", R.string.home_section_next_up),
LIVE_TV("livetv", R.string.home_section_livetv),
@EnumDisplayOptions(R.string.home_section_resume) NONE("none", R.string.home_section_none),
RESUME("resume"),
@EnumDisplayOptions(R.string.home_section_resume_audio)
RESUME_AUDIO("resumeaudio"),
@EnumDisplayOptions(R.string.home_section_resume_book)
RESUME_BOOK("resumebook"),
@EnumDisplayOptions(R.string.home_section_active_recordings)
ACTIVE_RECORDINGS("activerecordings"),
@EnumDisplayOptions(R.string.home_section_next_up)
NEXT_UP("nextup"),
@EnumDisplayOptions(R.string.home_section_livetv)
LIVE_TV("livetv"),
@EnumDisplayOptions(R.string.home_section_none)
NONE("none"),
} }

View file

@ -1,24 +1,23 @@
package org.jellyfin.androidtv.constant package org.jellyfin.androidtv.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class ImageType { enum class ImageType(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Poster. * Poster.
*/ */
@EnumDisplayOptions(R.string.image_type_poster) POSTER(R.string.image_type_poster),
POSTER,
/** /**
* Thumbnail. * Thumbnail.
*/ */
@EnumDisplayOptions(R.string.image_type_thumbnail) THUMB(R.string.image_type_thumbnail),
THUMB,
/** /**
* Banner. * Banner.
*/ */
@EnumDisplayOptions(R.string.image_type_banner) BANNER(R.string.image_type_banner),
BANNER
} }

View file

@ -1,35 +1,32 @@
package org.jellyfin.androidtv.constant package org.jellyfin.androidtv.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class PosterSize { enum class PosterSize(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Smallest. * Smallest.
*/ */
@EnumDisplayOptions(R.string.image_size_smallest) SMALLEST(R.string.image_size_smallest),
SMALLEST,
/** /**
* Small. * Small.
*/ */
@EnumDisplayOptions(R.string.image_size_small) SMALL(R.string.image_size_small),
SMALL,
/** /**
* Medium. * Medium.
*/ */
@EnumDisplayOptions(R.string.image_size_medium) MED(R.string.image_size_medium),
MED,
/** /**
* Large. * Large.
*/ */
@EnumDisplayOptions(R.string.image_size_large) LARGE(R.string.image_size_large),
LARGE,
/** /**
* Extra Large. * Extra Large.
*/ */
@EnumDisplayOptions(R.string.image_size_xlarge) X_LARGE(R.string.image_size_xlarge),
X_LARGE
} }

View file

@ -1,24 +1,23 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class AppTheme { enum class AppTheme(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* The default dark theme * The default dark theme
*/ */
@EnumDisplayOptions(R.string.pref_theme_dark) DARK(R.string.pref_theme_dark),
DARK,
/** /**
* The "classic" emerald theme * The "classic" emerald theme
*/ */
@EnumDisplayOptions(R.string.pref_theme_emerald) EMERALD(R.string.pref_theme_emerald),
EMERALD,
/** /**
* A theme with a more muted accent color, inspired by CTalvio's Monochromic CSS theme for Jellyfin Web * A theme with a more muted accent color, inspired by CTalvio's Monochromic CSS theme for Jellyfin Web
*/ */
@EnumDisplayOptions(R.string.pref_theme_muted_purple) MUTED_PURPLE(R.string.pref_theme_muted_purple),
MUTED_PURPLE,
} }

View file

@ -1,22 +1,22 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions
import org.jellyfin.androidtv.util.DeviceUtils import org.jellyfin.androidtv.util.DeviceUtils
import org.jellyfin.preference.PreferenceEnum
enum class AudioBehavior { enum class AudioBehavior(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Directly stream audio without any changes * Directly stream audio without any changes
*/ */
@EnumDisplayOptions(R.string.pref_audio_direct) DIRECT_STREAM(R.string.pref_audio_direct),
DIRECT_STREAM,
/** /**
* Downnmix audio to stereo. Disables the AC3, EAC3 and AAC_LATM audio codecs. * Downnmix audio to stereo. Disables the AC3, EAC3 and AAC_LATM audio codecs.
*/ */
@EnumDisplayOptions(R.string.pref_audio_compat) DOWNMIX_TO_STEREO(R.string.pref_audio_compat),
DOWNMIX_TO_STEREO
} }
val defaultAudioBehavior = if (DeviceUtils.isChromecastWithGoogleTV) AudioBehavior.DOWNMIX_TO_STEREO val defaultAudioBehavior = if (DeviceUtils.isChromecastWithGoogleTV) AudioBehavior.DOWNMIX_TO_STEREO
else AudioBehavior.DIRECT_STREAM else AudioBehavior.DIRECT_STREAM

View file

@ -1,30 +1,28 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class ClockBehavior { enum class ClockBehavior(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Always show clock. * Always show clock.
*/ */
@EnumDisplayOptions(R.string.lbl_always) ALWAYS(R.string.lbl_always),
ALWAYS,
/** /**
* Show clock in menus only. * Show clock in menus only.
*/ */
@EnumDisplayOptions(R.string.pref_clock_display_browsing) IN_MENUS(R.string.pref_clock_display_browsing),
IN_MENUS,
/** /**
* Show clock in video only. * Show clock in video only.
*/ */
@EnumDisplayOptions(R.string.pref_clock_display_playback) IN_VIDEO(R.string.pref_clock_display_playback),
IN_VIDEO,
/** /**
* Show clock never. * Show clock never.
*/ */
@EnumDisplayOptions(R.string.lbl_never) NEVER(R.string.lbl_never),
NEVER
} }

View file

@ -1,17 +1,15 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
import org.jellyfin.sdk.model.constant.ItemSortBy import org.jellyfin.sdk.model.constant.ItemSortBy
enum class LiveTvChannelOrder( enum class LiveTvChannelOrder(
val stringValue: String override val nameRes: Int,
) { val stringValue: String,
@EnumDisplayOptions(R.string.lbl_guide_option_played) ) : PreferenceEnum {
LAST_PLAYED(ItemSortBy.DatePlayed), LAST_PLAYED(R.string.lbl_guide_option_played, ItemSortBy.DatePlayed),
CHANNEL_NUMBER(R.string.lbl_guide_option_number, ItemSortBy.SortName);
@EnumDisplayOptions(R.string.lbl_guide_option_number)
CHANNEL_NUMBER(ItemSortBy.SortName);
companion object { companion object {
fun fromString(value: String) = values() fun fromString(value: String) = values()

View file

@ -1,26 +1,25 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class NextUpBehavior { enum class NextUpBehavior(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Enable the Next Up screen - show the item's thumbnail * Enable the Next Up screen - show the item's thumbnail
*/ */
@EnumDisplayOptions(R.string.lbl_next_up_extended) EXTENDED(R.string.lbl_next_up_extended),
EXTENDED,
/** /**
* Enable the Next Up screen - hide the item's thumbnail * Enable the Next Up screen - hide the item's thumbnail
*/ */
@EnumDisplayOptions(R.string.lbl_next_up_minimal) MINIMAL(R.string.lbl_next_up_minimal),
MINIMAL,
/** /**
* Disable the Next Up screen * Disable the Next Up screen
*/ */
@EnumDisplayOptions(R.string.lbl_never) DISABLED(R.string.lbl_never),
DISABLED
} }
const val NEXTUP_TIMER_DISABLED: Int = 0 const val NEXTUP_TIMER_DISABLED: Int = 0

View file

@ -1,36 +1,33 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class PreferredVideoPlayer { enum class PreferredVideoPlayer(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Automatically selects between exoplayer and vlc * Automatically selects between exoplayer and vlc
*/ */
@EnumDisplayOptions(R.string.pref_video_player_auto) AUTO(R.string.pref_video_player_auto),
AUTO,
/** /**
* Force ExoPlayer * Force ExoPlayer
*/ */
@EnumDisplayOptions(R.string.pref_video_player_exoplayer) EXOPLAYER(R.string.pref_video_player_exoplayer),
EXOPLAYER,
/** /**
* Force libVLC * Force libVLC
*/ */
@EnumDisplayOptions(R.string.pref_video_player_vlc) VLC(R.string.pref_video_player_vlc),
VLC,
/** /**
* Use external player * Use external player
*/ */
@EnumDisplayOptions(R.string.pref_video_player_external) EXTERNAL(R.string.pref_video_player_external),
EXTERNAL,
/** /**
* Choose a player - play with button * Choose a player - play with button
*/ */
@EnumDisplayOptions(R.string.pref_video_player_choose) CHOOSE(R.string.pref_video_player_choose),
CHOOSE
} }

View file

@ -1,24 +1,23 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class RatingType { enum class RatingType(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Sets default rating type to tomatoes. * Sets default rating type to tomatoes.
*/ */
@EnumDisplayOptions(R.string.lbl_tomatoes) RATING_TOMATOES(R.string.lbl_tomatoes),
RATING_TOMATOES,
/** /**
* Sets the default rating type to stars. * Sets the default rating type to stars.
*/ */
@EnumDisplayOptions(R.string.lbl_stars) RATING_STARS(R.string.lbl_stars),
RATING_STARS,
/** /**
* Sets the default rating type to hidden. * Sets the default rating type to hidden.
*/ */
@EnumDisplayOptions(R.string.lbl_hidden) RATING_HIDDEN(R.string.lbl_hidden),
RATING_HIDDEN
} }

View file

@ -1,22 +1,21 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class RefreshRateSwitchingBehavior { enum class RefreshRateSwitchingBehavior(
@EnumDisplayOptions(R.string.state_disabled) override val nameRes: Int,
DISABLED, ) : PreferenceEnum {
DISABLED(R.string.state_disabled),
/** /**
* When comparing modes, use difference in resolution to rank modes. * When comparing modes, use difference in resolution to rank modes.
*/ */
@EnumDisplayOptions(R.string.pref_refresh_rate_scale_on_tv) SCALE_ON_TV(R.string.pref_refresh_rate_scale_on_tv),
SCALE_ON_TV,
/** /**
* When comparing modes, rank native resolution modes highest. * When comparing modes, rank native resolution modes highest.
* Otherwise use difference in resolution to rank modes. * Otherwise use difference in resolution to rank modes.
*/ */
@EnumDisplayOptions(R.string.pref_refresh_rate_scale_on_device) SCALE_ON_DEVICE(R.string.pref_refresh_rate_scale_on_device),
SCALE_ON_DEVICE,
} }

View file

@ -1,30 +1,28 @@
package org.jellyfin.androidtv.preference.constant package org.jellyfin.androidtv.preference.constant
import org.jellyfin.androidtv.R import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions import org.jellyfin.preference.PreferenceEnum
enum class WatchedIndicatorBehavior { enum class WatchedIndicatorBehavior(
override val nameRes: Int,
) : PreferenceEnum {
/** /**
* Always show watched indicators. * Always show watched indicators.
*/ */
@EnumDisplayOptions(R.string.lbl_always) ALWAYS(R.string.lbl_always),
ALWAYS,
/** /**
* Hide unwatched count indicator, show watched check mark only. * Hide unwatched count indicator, show watched check mark only.
*/ */
@EnumDisplayOptions(R.string.lbl_hide_unwatched_count) HIDE_UNWATCHED(R.string.lbl_hide_unwatched_count),
HIDE_UNWATCHED,
/** /**
* Hide unwatched count indicator, show watched check mark on individual episodes only. * Hide unwatched count indicator, show watched check mark on individual episodes only.
*/ */
@EnumDisplayOptions(R.string.lbl_episode_marks) EPISODES_ONLY(R.string.lbl_episode_marks),
EPISODES_ONLY,
/** /**
* Never show watched indicators. * Never show watched indicators.
*/ */
@EnumDisplayOptions(R.string.lbl_never) NEVER(R.string.lbl_never),
NEVER
} }

View file

@ -119,7 +119,7 @@ abstract class DisplayPreferencesStore(
override fun <V : Enum<V>> setEnum(preference: Preference<*>, value: Enum<V>) = override fun <V : Enum<V>> setEnum(preference: Preference<*>, value: Enum<V>) =
setString( setString(
preference.key, when (value) { preference.key, when (value) {
is PreferenceEnum -> value.serializedName is PreferenceEnum -> value.serializedName ?: value.toString()
else -> value.toString() else -> value.toString()
} }
) )

View file

@ -1500,23 +1500,22 @@ public class FullDetailsFragment extends Fragment implements RecordingIndicatorV
PopupMenu.OnMenuItemClickListener moreMenuListener = new PopupMenu.OnMenuItemClickListener() { PopupMenu.OnMenuItemClickListener moreMenuListener = new PopupMenu.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.addFav: if (itemId == R.id.addFav || itemId == R.id.remFav) {
case R.id.remFav: toggleFavorite();
toggleFavorite(); return true;
return true; } else if (itemId == R.id.playTrailers) {
case R.id.playTrailers: playTrailers();
playTrailers(); return true;
return true; } else if (itemId == R.id.gotoSeries) {
case R.id.gotoSeries: gotoSeries();
gotoSeries(); return true;
return true; } else if (itemId == R.id.shuffleAll) {
case R.id.shuffleAll: play(mBaseItem, 0, true);
play(mBaseItem, 0, true); return true;
return true; } else if (itemId == R.id.addQueue) {
case R.id.addQueue: addItemToQueue();
addItemToQueue(); return true;
return true;
} }
return false; return false;
} }

View file

@ -1,13 +0,0 @@
package org.jellyfin.androidtv.ui.preference.dsl
import androidx.annotation.StringRes
/**
* Annotation used in the [OptionsItemEnum] to add display options to enum entries.
* @param name The id of the name resource. -1 for "none" (default).
* @param hidden True to hide this option or false (default) to display.
*/
annotation class EnumDisplayOptions(
@StringRes val name: Int = -1,
val hidden: Boolean = false
)

View file

@ -5,6 +5,7 @@ import androidx.annotation.StringRes
import androidx.preference.PreferenceCategory import androidx.preference.PreferenceCategory
import org.jellyfin.androidtv.ui.preference.custom.RichListPreference import org.jellyfin.androidtv.ui.preference.custom.RichListPreference
import org.jellyfin.preference.Preference import org.jellyfin.preference.Preference
import org.jellyfin.preference.PreferenceEnum
import org.jellyfin.preference.store.PreferenceStore import org.jellyfin.preference.store.PreferenceStore
import java.util.UUID import java.util.UUID
@ -26,17 +27,10 @@ class OptionsItemEnum<T : Enum<T>>(
private fun getEntries(): Map<T, String> { private fun getEntries(): Map<T, String> {
return clazz.enumConstants?.mapNotNull { entry -> return clazz.enumConstants?.mapNotNull { entry ->
val options = clazz
.getDeclaredField(entry.name)
.getAnnotation(EnumDisplayOptions::class.java)
when { when {
// Options set but entry is hidden entry is PreferenceEnum && entry.hidden -> null
options?.hidden == true -> null entry is PreferenceEnum && entry.nameRes != -1 -> Pair(entry, context.getString(entry.nameRes))
// Options not set or name not set else -> Pair(entry, entry.name)
options == null || options.name == -1 -> Pair(entry, entry.name)
// Options set and name set
else -> Pair(entry, context.getString(options.name))
} }
}?.toMap().orEmpty() }?.toMap().orEmpty()
} }
@ -66,7 +60,7 @@ class OptionsItemEnum<T : Enum<T>>(
} }
} }
container += { container += {
pref.isEnabled = dependencyCheckFun() && enabled pref.isEnabled = dependencyCheckFun() && enabled
} }
} }

View file

@ -10,8 +10,6 @@ sdk.version=default
# Android # Android
android.useAndroidX=true android.useAndroidX=true
# FIXME: Remove this once EnumDisplayOptions is updated
android.nonFinalResIds=false
# FIXME: Remove this once all uses of R have correct imports # FIXME: Remove this once all uses of R have correct imports
android.nonTransitiveRClass=false android.nonTransitiveRClass=false

View file

@ -1,5 +1,21 @@
package org.jellyfin.preference package org.jellyfin.preference
import androidx.annotation.StringRes
interface PreferenceEnum { interface PreferenceEnum {
val serializedName: String /**
* True to hide this option or false (default) to display.
*/
val hidden: Boolean get() = false
/**
* The id of the name resource or -1 for "none".
*/
@get:StringRes
val nameRes: Int
/**
* The name used to store the preference or null to use the name property.
*/
val serializedName: String? get() = null
} }

View file

@ -70,7 +70,7 @@ abstract class SharedPreferenceStore(
override fun <V : Enum<V>> setEnum(preference: Preference<*>, value: Enum<V>) = override fun <V : Enum<V>> setEnum(preference: Preference<*>, value: Enum<V>) =
setString(preference.key, when (value) { setString(preference.key, when (value) {
is PreferenceEnum -> value.serializedName is PreferenceEnum -> value.serializedName ?: value.toString()
else -> value.toString() else -> value.toString()
}) })