diff --git a/app/src/main/java/org/jellyfin/androidtv/di/PreferenceModule.kt b/app/src/main/java/org/jellyfin/androidtv/di/PreferenceModule.kt index 71e5a19fb6..c01174a6d4 100644 --- a/app/src/main/java/org/jellyfin/androidtv/di/PreferenceModule.kt +++ b/app/src/main/java/org/jellyfin/androidtv/di/PreferenceModule.kt @@ -2,6 +2,7 @@ package org.jellyfin.androidtv.di import org.jellyfin.androidtv.preference.* import org.koin.android.ext.koin.androidApplication +import org.koin.dsl.binds import org.koin.dsl.module val preferenceModule = module { @@ -10,6 +11,9 @@ val preferenceModule = module { single { LiveTvPreferences(get(userApiClient)) } single { UserSettingPreferences(get(userApiClient)) } single { AuthenticationPreferences(androidApplication()) } - single { UserPreferences(androidApplication()) } + single { UserPreferences(androidApplication()) } binds arrayOf( + UserPreferences::class, + IUserPreferences::class + ) single { SystemPreferences(androidApplication()) } } diff --git a/app/src/main/java/org/jellyfin/androidtv/preference/IUserPreferences.kt b/app/src/main/java/org/jellyfin/androidtv/preference/IUserPreferences.kt new file mode 100644 index 0000000000..19fee811f8 --- /dev/null +++ b/app/src/main/java/org/jellyfin/androidtv/preference/IUserPreferences.kt @@ -0,0 +1,4 @@ +package org.jellyfin.androidtv.preference + +// Stub interface to allow Koin to resolve between different preference stores +interface IUserPreferences : PreferenceStore {} diff --git a/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt b/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt index 3188137937..327277475d 100644 --- a/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt +++ b/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt @@ -13,7 +13,7 @@ import org.jellyfin.androidtv.util.DeviceUtils * * @param context Context to get the SharedPreferences from */ -class UserPreferences(context: Context) : SharedPreferenceStore( +class UserPreferences(context: Context) : IUserPreferences, SharedPreferenceStore( sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) ) { companion object { @@ -127,12 +127,14 @@ class UserPreferences(context: Context) : SharedPreferenceStore( /** * Shortcut used for changing the audio track */ - var shortcutAudioTrack = Preference.int("shortcut_audio_track", KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK) + var shortcutAudioTrack = + Preference.int("shortcut_audio_track", KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK) /** * Shortcut used for changing the subtitle track */ - var shortcutSubtitleTrack = Preference.int("shortcut_subtitle_track", KeyEvent.KEYCODE_CAPTIONS) + var shortcutSubtitleTrack = + Preference.int("shortcut_subtitle_track", KeyEvent.KEYCODE_CAPTIONS) /* Developer options */ /** @@ -174,13 +176,14 @@ class UserPreferences(context: Context) : SharedPreferenceStore( /** * Set when watched indicators should show on MyImageCardViews */ - var watchedIndicatorBehavior = Preference.enum("pref_watched_indicator_behavior", WatchedIndicatorBehavior.ALWAYS) + var watchedIndicatorBehavior = + Preference.enum("pref_watched_indicator_behavior", WatchedIndicatorBehavior.ALWAYS) /** * Enable series thumbnails in home screen rows */ var seriesThumbnailsEnabled = Preference.boolean("pref_enable_series_thumbnails", true) - + /** * Enable subtitles background */ @@ -206,21 +209,40 @@ class UserPreferences(context: Context) : SharedPreferenceStore( // Migrate to video player enum // Note: This is the only time we need to check if the value is not set yet because the version numbers were reset if (!it.contains("video_player")) - putEnum("video_player", if (it.getBoolean("pref_video_use_external", false)) PreferredVideoPlayer.EXTERNAL else PreferredVideoPlayer.AUTO) + putEnum( + "video_player", + if (it.getBoolean( + "pref_video_use_external", + false + ) + ) PreferredVideoPlayer.EXTERNAL else PreferredVideoPlayer.AUTO + ) } // v0.11.x to v0.12.x migration(toVersion = 5) { // Migrate to audio behavior enum - putEnum("audio_behavior", if (it.getString("pref_audio_option", "0") == "1") AudioBehavior.DOWNMIX_TO_STEREO else AudioBehavior.DIRECT_STREAM) + putEnum( + "audio_behavior", + if (it.getString( + "pref_audio_option", + "0" + ) == "1" + ) AudioBehavior.DOWNMIX_TO_STEREO else AudioBehavior.DIRECT_STREAM + ) // Migrate live tv player to use enum - putEnum("live_tv_video_player", + putEnum( + "live_tv_video_player", when { - it.getBoolean("pref_live_tv_use_external", false) -> PreferredVideoPlayer.EXTERNAL + it.getBoolean( + "pref_live_tv_use_external", + false + ) -> PreferredVideoPlayer.EXTERNAL it.getBoolean("pref_enable_vlc_livetv", false) -> PreferredVideoPlayer.VLC else -> PreferredVideoPlayer.AUTO - }) + } + ) // Change audio delay type from long to int putInt("libvlc_audio_delay", it.getLong("libvlc_audio_delay", 0).toInt()) diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java index 4841d94831..86f74197a5 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java @@ -20,6 +20,7 @@ import org.jellyfin.androidtv.data.compat.SubtitleStreamInfo; import org.jellyfin.androidtv.data.compat.VideoOptions; import org.jellyfin.androidtv.data.model.DataRefreshService; +import org.jellyfin.androidtv.preference.IUserPreferences; import org.jellyfin.androidtv.preference.SystemPreferences; import org.jellyfin.androidtv.preference.UserPreferences; import org.jellyfin.androidtv.preference.UserSettingPreferences; @@ -67,7 +68,7 @@ public class PlaybackController { private Lazy apiClient = inject(ApiClient.class); private Lazy playbackManager = inject(PlaybackManager.class); - private Lazy userPreferences = inject(UserPreferences.class); + private Lazy userPreferences = inject(IUserPreferences.class); private Lazy systemPreferences = inject(SystemPreferences.class); private Lazy mediaManager = inject(MediaManager.class); diff --git a/app/src/test/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerTest.kt b/app/src/test/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerTest.kt index e92f2f73cd..6820e1ccda 100644 --- a/app/src/test/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerTest.kt +++ b/app/src/test/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerTest.kt @@ -1,17 +1,16 @@ package org.jellyfin.androidtv.ui.playback -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.unmockkAll +import io.mockk.verify +import org.jellyfin.androidtv.preference.IUserPreferences import org.jellyfin.androidtv.preference.Preference -import org.jellyfin.androidtv.preference.UserPreferences import org.jellyfin.androidtv.preference.constant.PreferredVideoPlayer -import org.jellyfin.androidtv.util.Utils import org.jellyfin.apiclient.interaction.ApiClient import org.jellyfin.apiclient.model.dto.BaseItemDto -import org.jellyfin.apiclient.model.dto.BaseItemType -import org.jellyfin.apiclient.model.entities.LocationType -import org.jellyfin.apiclient.model.library.PlayAccess import org.junit.After -import org.junit.Assert.* +import org.junit.Assert.assertNotNull import org.junit.Before import org.junit.Test import org.koin.core.context.startKoin @@ -29,7 +28,7 @@ class PlaybackControllerTest : KoinTest { // Koin managed modules lateinit var mockApiClient: ApiClient - lateinit var mockUserPreferences: UserPreferences + lateinit var mockUserPreferences: IUserPreferences private fun prepDiMocks(): Module { mockApiClient = mockk(relaxed = true) @@ -41,8 +40,8 @@ class PlaybackControllerTest : KoinTest { } returns PreferredVideoPlayer.EXOPLAYER return module { - single { mockApiClient } - single { mockUserPreferences } + single { mockApiClient } + single { mockUserPreferences } } }