mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 11:35:46 +00:00
minimized player fixes
This commit is contained in:
parent
68eb0cc8f2
commit
13516087f2
5 changed files with 63 additions and 34 deletions
|
@ -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
|
||||
|
|
|
@ -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?) {
|
||||
|
|
|
@ -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 setTopPadding(value : Float) {
|
||||
_player.setPadding(0, value.toInt(), _player.paddingRight, 0);
|
||||
|
||||
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(_player.paddingLeft, value.toInt(), _player.paddingRight, 0)
|
||||
}
|
||||
|
||||
//Tasks
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Reference in a new issue