@@ -106,10 +106,22 @@ abstract class CustomExoPlayerView(
106106 updateCurrentPosition()
107107 }
108108
109- /* *
110- * Preferences
111- */
112- private var resizeModePref = PlayerHelper .resizeModePref
109+ private var resizeModePref: Int
110+ set(value) {
111+ PreferenceHelper .putInt(
112+ PreferenceKeys .PLAYER_RESIZE_MODE ,
113+ value
114+ )
115+ }
116+ get() = PreferenceHelper .getInt(
117+ PreferenceKeys .PLAYER_RESIZE_MODE ,
118+ AspectRatioFrameLayout .RESIZE_MODE_FIT
119+ )
120+ private val resizeModes = listOf (
121+ AspectRatioFrameLayout .RESIZE_MODE_FIT to R .string.resize_mode_fit,
122+ AspectRatioFrameLayout .RESIZE_MODE_ZOOM to R .string.resize_mode_zoom,
123+ AspectRatioFrameLayout .RESIZE_MODE_FILL to R .string.resize_mode_fill
124+ )
113125
114126 val activity get() = context as BaseActivity
115127
@@ -167,11 +179,7 @@ abstract class CustomExoPlayerView(
167179 if (isFullscreen()) toggleSystemBars(! isPlayerLocked)
168180 }
169181
170- resizeMode = when (resizeModePref) {
171- " fill" -> AspectRatioFrameLayout .RESIZE_MODE_FILL
172- " zoom" -> AspectRatioFrameLayout .RESIZE_MODE_ZOOM
173- else -> AspectRatioFrameLayout .RESIZE_MODE_FIT
174- }
182+ resizeMode = resizeModePref
175183
176184 binding.playPauseBTN.setOnClickListener {
177185 player?.togglePlayPauseState()
@@ -418,16 +426,8 @@ abstract class CustomExoPlayerView(
418426 context.getString(R .string.player_resize_mode),
419427 R .drawable.ic_aspect_ratio,
420428 {
421- when (resizeMode) {
422- AspectRatioFrameLayout .RESIZE_MODE_FIT -> context.getString(
423- R .string.resize_mode_fit
424- )
425-
426- AspectRatioFrameLayout .RESIZE_MODE_FILL -> context.getString(
427- R .string.resize_mode_fill
428- )
429-
430- else -> context.getString(R .string.resize_mode_zoom)
429+ resizeModes.find { it.first == resizeMode }?.second?.let {
430+ context.getString(it)
431431 }
432432 }
433433 ) {
@@ -625,25 +625,24 @@ abstract class CustomExoPlayerView(
625625
626626 override fun onResizeModeClicked () {
627627 // switching between original aspect ratio (black bars) and zoomed to fill device screen
628- val aspectRatioModeNames = context.resources?.getStringArray(R .array.resizeMode)
629- ?.toList().orEmpty()
630-
631- val aspectRatioModes = listOf (
632- AspectRatioFrameLayout .RESIZE_MODE_FIT ,
633- AspectRatioFrameLayout .RESIZE_MODE_ZOOM ,
634- AspectRatioFrameLayout .RESIZE_MODE_FILL
635- )
636-
637628 BaseBottomSheet ()
638629 .setSimpleItems(
639- aspectRatioModeNames,
640- preselectedItem = aspectRatioModeNames[aspectRatioModes.indexOf(resizeMode)]
630+ resizeModes.map { context.getString(it.second) },
631+ preselectedItem = resizeModes.first { it.first == resizeMode }.second.let {
632+ context.getString(it)
633+ }
641634 ) { index ->
642- resizeMode = aspectRatioModes [index]
635+ resizeMode = resizeModes [index].first
643636 }
644637 .show(supportFragmentManager)
645638 }
646639
640+ override fun setResizeMode (resizeMode : Int ) {
641+ super .setResizeMode(resizeMode)
642+ // automatically remember the resize mode for the next session
643+ resizeModePref = resizeMode
644+ }
645+
647646 override fun onRepeatModeClicked () {
648647 // repeat mode options dialog
649648 BaseBottomSheet ()
@@ -805,6 +804,7 @@ abstract class CustomExoPlayerView(
805804 override fun onMinimize () {
806805 if (! PlayerHelper .pinchGestureEnabled) return
807806 resizeMode = AspectRatioFrameLayout .RESIZE_MODE_FIT
807+
808808 subtitleView?.setBottomPaddingFraction(SubtitleView .DEFAULT_BOTTOM_PADDING_FRACTION )
809809 }
810810
0 commit comments