mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
fix: horizontal margin of fullscreen player not updated
This commit is contained in:
parent
5245e62f97
commit
c8749888e9
@ -8,6 +8,7 @@ import com.github.libretube.constants.PreferenceKeys
|
|||||||
import com.github.libretube.helpers.LocaleHelper
|
import com.github.libretube.helpers.LocaleHelper
|
||||||
import com.github.libretube.helpers.PreferenceHelper
|
import com.github.libretube.helpers.PreferenceHelper
|
||||||
import com.github.libretube.helpers.ThemeHelper
|
import com.github.libretube.helpers.ThemeHelper
|
||||||
|
import com.github.libretube.helpers.WindowHelper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity that applies the LibreTube theme and the in-app language
|
* Activity that applies the LibreTube theme and the in-app language
|
||||||
@ -26,6 +27,11 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the phone of the user has a cutout like a notch or not
|
||||||
|
*/
|
||||||
|
var hasCutout = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
// set the app theme (e.g. Material You)
|
// set the app theme (e.g. Material You)
|
||||||
ThemeHelper.updateTheme(this)
|
ThemeHelper.updateTheme(this)
|
||||||
@ -35,6 +41,8 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
requestOrientationChange()
|
requestOrientationChange()
|
||||||
|
|
||||||
|
hasCutout = WindowHelper.hasCutout(window.decorView)
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,6 +690,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
updateResolutionOnFullscreenChange(true)
|
updateResolutionOnFullscreenChange(true)
|
||||||
|
|
||||||
openOrCloseFullscreenDialog(true)
|
openOrCloseFullscreenDialog(true)
|
||||||
|
|
||||||
|
binding.player.updateMarginsByFullscreenMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SourceLockedOrientationActivity")
|
@SuppressLint("SourceLockedOrientationActivity")
|
||||||
@ -716,6 +718,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
openOrCloseFullscreenDialog(false)
|
openOrCloseFullscreenDialog(false)
|
||||||
|
|
||||||
checkForNecessaryOrientationRestart()
|
checkForNecessaryOrientationRestart()
|
||||||
|
|
||||||
|
binding.player.updateMarginsByFullscreenMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openOrCloseFullscreenDialog(open: Boolean) {
|
private fun openOrCloseFullscreenDialog(open: Boolean) {
|
||||||
|
@ -3,6 +3,7 @@ package com.github.libretube.ui.views
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
@ -98,10 +99,6 @@ open class CustomExoPlayerView(
|
|||||||
private val supportFragmentManager
|
private val supportFragmentManager
|
||||||
get() = activity.supportFragmentManager
|
get() = activity.supportFragmentManager
|
||||||
|
|
||||||
private val hasCutout by lazy {
|
|
||||||
WindowHelper.hasCutout(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun toggleController() {
|
private fun toggleController() {
|
||||||
if (isControllerFullyVisible) hideController() else showController()
|
if (isControllerFullyVisible) hideController() else showController()
|
||||||
}
|
}
|
||||||
@ -553,9 +550,16 @@ open class CustomExoPlayerView(
|
|||||||
open fun isFullscreen() =
|
open fun isFullscreen() =
|
||||||
resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
|
|
||||||
|
updateMarginsByFullscreenMode()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the margins according to the current orientation and fullscreen mode
|
||||||
|
*/
|
||||||
|
fun updateMarginsByFullscreenMode() {
|
||||||
// add a larger bottom margin to the time bar in landscape mode
|
// add a larger bottom margin to the time bar in landscape mode
|
||||||
binding.progressBar.updateLayoutParams<MarginLayoutParams> {
|
binding.progressBar.updateLayoutParams<MarginLayoutParams> {
|
||||||
bottomMargin = (if (isFullscreen()) 20f else 10f).dpToPx()
|
bottomMargin = (if (isFullscreen()) 20f else 10f).dpToPx()
|
||||||
@ -563,19 +567,17 @@ open class CustomExoPlayerView(
|
|||||||
|
|
||||||
updateTopBarMargin()
|
updateTopBarMargin()
|
||||||
|
|
||||||
// don't add extra padding if there's no cutout
|
// don't add extra padding if there's no cutout and no margin set that would need to be undone
|
||||||
if (!hasCutout && binding.topBar.marginStart == 0) return
|
if (!(context as BaseActivity).hasCutout && binding.topBar.marginStart == LANDSCAPE_MARGIN_HORIZONTAL_NONE) return
|
||||||
|
|
||||||
// add a margin to the top and the bottom bar in landscape mode for notches
|
// add a margin to the top and the bottom bar in landscape mode for notches
|
||||||
val newMargin = when (newConfig.orientation) {
|
val isForcedPortrait = activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
Configuration.ORIENTATION_LANDSCAPE -> LANDSCAPE_MARGIN_HORIZONTAL
|
val horizontalMargin = if (isFullscreen() && !isForcedPortrait) LANDSCAPE_MARGIN_HORIZONTAL else LANDSCAPE_MARGIN_HORIZONTAL_NONE
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
|
|
||||||
listOf(binding.topBar, binding.bottomBar).forEach {
|
listOf(binding.topBar, binding.bottomBar).forEach {
|
||||||
it.updateLayoutParams<MarginLayoutParams> {
|
it.updateLayoutParams<MarginLayoutParams> {
|
||||||
marginStart = newMargin
|
marginStart = horizontalMargin
|
||||||
marginEnd = newMargin
|
marginEnd = horizontalMargin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -599,7 +601,7 @@ open class CustomExoPlayerView(
|
|||||||
*/
|
*/
|
||||||
fun updateTopBarMargin() {
|
fun updateTopBarMargin() {
|
||||||
binding.topBar.updateLayoutParams<MarginLayoutParams> {
|
binding.topBar.updateLayoutParams<MarginLayoutParams> {
|
||||||
topMargin = getTopBarMarginDp().toFloat().dpToPx()
|
topMargin = (if (isFullscreen()) 18f else 0f).dpToPx()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,10 +618,6 @@ open class CustomExoPlayerView(
|
|||||||
runnableHandler.postDelayed(100, UPDATE_POSITION_TOKEN, this::updateCurrentPosition)
|
runnableHandler.postDelayed(100, UPDATE_POSITION_TOKEN, this::updateCurrentPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getTopBarMarginDp(): Int {
|
|
||||||
return if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) 10 else 0
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onSingleTap() {
|
override fun onSingleTap() {
|
||||||
toggleController()
|
toggleController()
|
||||||
}
|
}
|
||||||
@ -728,5 +726,6 @@ open class CustomExoPlayerView(
|
|||||||
private const val ANIMATION_DURATION = 100L
|
private const val ANIMATION_DURATION = 100L
|
||||||
private const val AUTO_HIDE_CONTROLLER_DELAY = 2000L
|
private const val AUTO_HIDE_CONTROLLER_DELAY = 2000L
|
||||||
private val LANDSCAPE_MARGIN_HORIZONTAL = 20f.dpToPx()
|
private val LANDSCAPE_MARGIN_HORIZONTAL = 20f.dpToPx()
|
||||||
|
private val LANDSCAPE_MARGIN_HORIZONTAL_NONE = 0f.dpToPx()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,6 @@ class OfflinePlayerView(
|
|||||||
toggleSystemBars(true)
|
toggleSystemBars(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTopBarMarginDp(): Int {
|
|
||||||
// the offline player requires a bigger top bar margin
|
|
||||||
return if (isFullscreen()) 18 else super.getTopBarMarginDp()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun minimizeOrExitPlayer() {
|
override fun minimizeOrExitPlayer() {
|
||||||
(context as AppCompatActivity).onBackPressedDispatcher.onBackPressed()
|
(context as AppCompatActivity).onBackPressedDispatcher.onBackPressed()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.ui.views
|
package com.github.libretube.ui.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
@ -194,14 +193,6 @@ class OnlinePlayerView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTopBarMarginDp(): Int {
|
|
||||||
return when {
|
|
||||||
resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE -> 15
|
|
||||||
playerViewModel?.isFullscreen?.value == true -> 20
|
|
||||||
else -> super.getTopBarMarginDp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isFullscreen(): Boolean {
|
override fun isFullscreen(): Boolean {
|
||||||
return playerViewModel?.isFullscreen?.value ?: super.isFullscreen()
|
return playerViewModel?.isFullscreen?.value ?: super.isFullscreen()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user