diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ContentFeedView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ContentFeedView.kt index 17130779f964fa1d0b9c34d78c99d075b965026f..3c0e749676cacb1f53215d1b54308b09b1c683b3 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ContentFeedView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ContentFeedView.kt @@ -178,7 +178,7 @@ abstract class ContentFeedView<TFragment> : FeedView<TFragment, IPlatformContent ): StaggeredGridLayoutManager { val glmResults = StaggeredGridLayoutManager( - if (resources.configuration.screenWidthDp >= resources.getDimension(R.dimen.landscape_threshold)) 2 else 1, + (resources.configuration.screenWidthDp / resources.getDimension(R.dimen.landscape_threshold)).toInt() + 1, StaggeredGridLayoutManager.VERTICAL ); return glmResults diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt index 748b1d50eb86a3d60282634a40f033470549b312..16937e66586ec7f8f45ab34c4d395d8be951c259 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt @@ -180,14 +180,13 @@ abstract class FeedView<TFragment, TResult, TConverted, TPager, TViewHolder> : L if (firstVisibleItemPosition != RecyclerView.NO_POSITION) { val firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition) val itemHeight = firstVisibleView?.height ?: 0 - val occupiedSpace = recyclerData.results.size * itemHeight + val occupiedSpace = recyclerData.results.size / recyclerData.layoutManager.spanCount * itemHeight val recyclerViewHeight = _recyclerResults.height Logger.i(TAG, "ensureEnoughContentVisible loadNextPage occupiedSpace=$occupiedSpace recyclerViewHeight=$recyclerViewHeight") occupiedSpace >= recyclerViewHeight } else { false } - } Logger.i(TAG, "ensureEnoughContentVisible loadNextPage canScroll=$canScroll _automaticNextPageCounter=$_automaticNextPageCounter") if (!canScroll || filteredResults.isEmpty()) { @@ -228,11 +227,7 @@ abstract class FeedView<TFragment, TResult, TConverted, TPager, TViewHolder> : L } private fun updateSpanCount() { - if (resources.configuration.screenWidthDp >= resources.getDimension(R.dimen.landscape_threshold) && recyclerData.layoutManager.spanCount != 2) { - recyclerData.layoutManager.spanCount = 2 - } else if (resources.configuration.screenWidthDp < resources.getDimension(R.dimen.landscape_threshold) && recyclerData.layoutManager.spanCount != 1) { - recyclerData.layoutManager.spanCount = 1 - } + recyclerData.layoutManager.spanCount = (resources.configuration.screenWidthDp / resources.getDimension(R.dimen.landscape_threshold)).toInt() + 1 } override fun onConfigurationChanged(newConfig: Configuration?) { diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt index 089e9c83a390f236e28f303518f5c34d70d9872c..f394693d67b512c3c3ad98fece98f378a95bd8d6 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt @@ -4,6 +4,7 @@ import android.app.PictureInPictureParams import android.app.RemoteAction import android.content.Context import android.content.Intent +import android.content.res.Configuration import android.content.res.Resources import android.graphics.Bitmap import android.graphics.Rect @@ -164,6 +165,7 @@ import kotlinx.coroutines.withContext import userpackage.Protocol import java.time.OffsetDateTime import kotlin.math.abs +import kotlin.math.max import kotlin.math.roundToLong @UnstableApi @@ -2650,13 +2652,29 @@ class VideoDetailView : ConstraintLayout { if(_minimize_controls.isClickable != clickable) _minimize_controls.isClickable = clickable; } - fun setVideoMinimize(value : Float) { - val padRight = (resources.displayMetrics.widthPixels * 0.70 * value).toInt(); - _player.setPadding(0, _player.paddingTop, padRight, 0); - _cast.setPadding(0, _cast.paddingTop, padRight, 0); + + override fun onConfigurationChanged(newConfig: Configuration?) { + super.onConfigurationChanged(newConfig) + + setVideoMinimize(_minimizeProgress) + } + + fun setVideoMinimize(value: Float) { + val totalPaddingNeeded = value * max( + (resources.displayMetrics.widthPixels - resources.getDimension(R.dimen.minimized_player_max_width)).toInt(), + 0 + ) + val outerPadding = (totalPaddingNeeded / 2).toInt() + val padRight = + ((resources.displayMetrics.widthPixels - totalPaddingNeeded) * 0.70 * value).toInt() + + rootView.setPadding(outerPadding, 0, outerPadding, 0) + _player.setPadding(0, _player.paddingTop, padRight, 0) + _cast.setPadding(0, _cast.paddingTop, padRight, 0) } - fun setTopPadding(value : Float) { - _player.setPadding(0, value.toInt(), _player.paddingRight, 0); + + fun setTopPadding(value: Float) { + _player.setPadding(_player.paddingLeft, value.toInt(), _player.paddingRight, 0) } //Tasks diff --git a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt index 3f465269ac67c9439236bf000d8f26bbef182a16..a40d9906398f0496ac5bc51b70ac9abf387745e9 100644 --- a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt +++ b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt @@ -718,58 +718,72 @@ class FutoVideoPlayer : FutoVideoPlayerBase { //Sizing @OptIn(UnstableApi::class) - fun fitHeight(videoSize : VideoSize? = null){ + fun fitHeight(videoSize: VideoSize? = null) { Logger.i(TAG, "Video Fit Height"); - if(_originalBottomMargin != 0) { + if (_originalBottomMargin != 0) { val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams; layoutParams.setMargins(0, 0, 0, _originalBottomMargin); _videoView.layoutParams = layoutParams; } - var h = videoSize?.height ?: lastVideoSource?.height ?: exoPlayer?.player?.videoSize?.height ?: 0; - var w = videoSize?.width ?: lastVideoSource?.width ?: exoPlayer?.player?.videoSize?.width ?: 0; + var h = videoSize?.height ?: lastVideoSource?.height ?: exoPlayer?.player?.videoSize?.height + ?: 0; + var w = + videoSize?.width ?: lastVideoSource?.width ?: exoPlayer?.player?.videoSize?.width ?: 0; - if(h == 0 && w == 0) { - Logger.i(TAG, "UNKNOWN VIDEO FIT: (videoSize: ${videoSize != null}, player.videoSize: ${exoPlayer?.player?.videoSize != null})"); + if (h == 0 && w == 0) { + Logger.i( + TAG, + "UNKNOWN VIDEO FIT: (videoSize: ${videoSize != null}, player.videoSize: ${exoPlayer?.player?.videoSize != null})" + ); w = 1280; h = 720; } - - if(_lastSourceFit == null){ + if (_lastSourceFit == null) { val metrics = StateApp.instance.displayMetrics ?: resources.displayMetrics; - val viewWidth = Math.min(metrics.widthPixels, metrics.heightPixels); //TODO: Get parent width. was this.width + val viewWidth = Math.min( + metrics.widthPixels, + metrics.heightPixels + ); //TODO: Get parent width. was this.width val deviceHeight = Math.max(metrics.widthPixels, metrics.heightPixels); val maxHeight = deviceHeight * 0.4; - val determinedHeight = if(w > h) + val determinedHeight = if (w > h) ((h * (viewWidth.toDouble() / w)).toInt()) else ((h * (viewWidth.toDouble() / w)).toInt()); _lastSourceFit = determinedHeight; _lastSourceFit = Math.max(_lastSourceFit!!, 250); _lastSourceFit = Math.min(_lastSourceFit!!, maxHeight.toInt()); - if((_lastSourceFit ?: 0) < 300 || (_lastSourceFit ?: 0) > viewWidth) { - Log.d(TAG, "WEIRD HEIGHT DETECTED: ${_lastSourceFit}, Width: ${w}, Height: ${h}, VWidth: ${viewWidth}"); + if ((_lastSourceFit ?: 0) < 300 || (_lastSourceFit ?: 0) > viewWidth) { + Log.d( + TAG, + "WEIRD HEIGHT DETECTED: ${_lastSourceFit}, Width: ${w}, Height: ${h}, VWidth: ${viewWidth}" + ); } - if(_lastSourceFit != determinedHeight) - _desiredResizeModePortrait = AspectRatioFrameLayout.RESIZE_MODE_FIT; - else - _desiredResizeModePortrait = AspectRatioFrameLayout.RESIZE_MODE_ZOOM; + + _desiredResizeModePortrait = AspectRatioFrameLayout.RESIZE_MODE_FIT; _videoView.resizeMode = _desiredResizeModePortrait } + _videoView.resizeMode = _desiredResizeModePortrait - val marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7f, resources.displayMetrics).toInt(); + val marginBottom = + TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7f, resources.displayMetrics) + .toInt(); val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, _lastSourceFit!! + marginBottom) rootParams.bottomMargin = marginBottom; _root.layoutParams = rootParams isFitMode = true; } - fun fillHeight(){ + + @OptIn(UnstableApi::class) + fun fillHeight() { Logger.i(TAG, "Video Fill Height"); val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams; - _originalBottomMargin = if(layoutParams.bottomMargin > 0) layoutParams.bottomMargin else _originalBottomMargin; + _originalBottomMargin = + if (layoutParams.bottomMargin > 0) layoutParams.bottomMargin else _originalBottomMargin; layoutParams.setMargins(0); _videoView.layoutParams = layoutParams; _videoView.invalidate(); @@ -777,6 +791,8 @@ class FutoVideoPlayer : FutoVideoPlayerBase { val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); _root.layoutParams = rootParams; _root.invalidate(); + + _videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM isFitMode = false; } diff --git a/app/src/main/res/values/dimensions.xml b/app/src/main/res/values/dimensions.xml index 320998e23c476be2ff8018a3df8f76380e498459..5e75240b23926876f5d30922ef401cf45a30df69 100644 --- a/app/src/main/res/values/dimensions.xml +++ b/app/src/main/res/values/dimensions.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <dimen name="video_view_right_padding"></dimen> + <dimen name="minimized_player_max_width">500dp</dimen> <dimen name="app_bar_height">200dp</dimen> <dimen name="landscape_threshold">300dp</dimen> </resources>