mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #777 from Bnyro/master
Fullscreen Upon Landscape Option
This commit is contained in:
commit
d6b7971617
@ -37,7 +37,7 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:screenOrientation="userPortrait"
|
android:screenOrientation="user"
|
||||||
android:supportsPictureInPicture="true">
|
android:supportsPictureInPicture="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@ -3,7 +3,6 @@ package com.github.libretube.activities
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@ -84,8 +83,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
|
|
||||||
navController = findNavController(R.id.fragment)
|
navController = findNavController(R.id.fragment)
|
||||||
binding.bottomNav.setupWithNavController(navController)
|
binding.bottomNav.setupWithNavController(navController)
|
||||||
|
|
||||||
@ -290,7 +287,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// set the animation duration
|
// set the animation duration
|
||||||
motionLayout.setTransitionDuration(250)
|
motionLayout.setTransitionDuration(250)
|
||||||
motionLayout.transitionToEnd()
|
motionLayout.transitionToEnd()
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
with(motionLayout) {
|
with(motionLayout) {
|
||||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
||||||
enableTransition(R.id.yt_transition, true)
|
enableTransition(R.id.yt_transition, true)
|
||||||
|
@ -6,6 +6,7 @@ import android.app.PictureInPictureParams
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -140,6 +141,8 @@ class PlayerFragment : Fragment() {
|
|||||||
private lateinit var chapters: List<ChapterSegment>
|
private lateinit var chapters: List<ChapterSegment>
|
||||||
private val sponsorBlockPrefs = SponsorBlockPrefs()
|
private val sponsorBlockPrefs = SponsorBlockPrefs()
|
||||||
|
|
||||||
|
private var autoRotationEnabled = true
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
@ -163,6 +166,34 @@ class PlayerFragment : Fragment() {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
|
|
||||||
|
// save whether auto rotation is enabled
|
||||||
|
autoRotationEnabled = PreferenceHelper.getBoolean(
|
||||||
|
requireContext(),
|
||||||
|
"auto_fullscreen",
|
||||||
|
true
|
||||||
|
)
|
||||||
|
val mainActivity = activity as MainActivity
|
||||||
|
if (autoRotationEnabled) {
|
||||||
|
// enable auto rotation
|
||||||
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER
|
||||||
|
onConfigurationChanged(resources.configuration)
|
||||||
|
} else {
|
||||||
|
// go to portrait mode
|
||||||
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
|
}
|
||||||
|
|
||||||
|
// save whether related streams and autoplay are enabled
|
||||||
|
autoplay = PreferenceHelper.getBoolean(
|
||||||
|
requireContext(),
|
||||||
|
"autoplay",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
relatedStreamsEnabled = PreferenceHelper.getBoolean(
|
||||||
|
requireContext(),
|
||||||
|
"related_streams_toggle",
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
setSponsorBlockPrefs()
|
setSponsorBlockPrefs()
|
||||||
createExoPlayer(view)
|
createExoPlayer(view)
|
||||||
initializeTransitionLayout(view)
|
initializeTransitionLayout(view)
|
||||||
@ -232,7 +263,6 @@ class PlayerFragment : Fragment() {
|
|||||||
Globals.isMiniPlayerVisible = false
|
Globals.isMiniPlayerVisible = false
|
||||||
binding.playerMotionLayout.transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
mainActivity.supportFragmentManager.beginTransaction()
|
mainActivity.supportFragmentManager.beginTransaction()
|
||||||
.remove(this)
|
.remove(this)
|
||||||
.commit()
|
.commit()
|
||||||
@ -241,7 +271,6 @@ class PlayerFragment : Fragment() {
|
|||||||
Globals.isMiniPlayerVisible = false
|
Globals.isMiniPlayerVisible = false
|
||||||
binding.playerMotionLayout.transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
mainActivity.supportFragmentManager.beginTransaction()
|
mainActivity.supportFragmentManager.beginTransaction()
|
||||||
.remove(this)
|
.remove(this)
|
||||||
.commit()
|
.commit()
|
||||||
@ -268,6 +297,8 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FullScreen button trigger
|
// FullScreen button trigger
|
||||||
|
// hide fullscreen button if auto rotation enabled
|
||||||
|
playerBinding.fullscreen.visibility = if (autoRotationEnabled) View.GONE else View.VISIBLE
|
||||||
playerBinding.fullscreen.setOnClickListener {
|
playerBinding.fullscreen.setOnClickListener {
|
||||||
// hide player controller
|
// hide player controller
|
||||||
exoPlayerView.hideController()
|
exoPlayerView.hideController()
|
||||||
@ -341,20 +372,23 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
scaleControls(1.3F)
|
scaleControls(1.3F)
|
||||||
|
|
||||||
val orientation = when (fullscreenOrientationPref) {
|
if (!autoRotationEnabled) {
|
||||||
"ratio" -> {
|
// different orientations of the video are only available when auto rotation is disabled
|
||||||
val videoSize = exoPlayer.videoSize
|
val orientation = when (fullscreenOrientationPref) {
|
||||||
// probably a youtube shorts video
|
"ratio" -> {
|
||||||
if (videoSize.height > videoSize.width) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
val videoSize = exoPlayer.videoSize
|
||||||
// a video with normal aspect ratio
|
// probably a youtube shorts video
|
||||||
else ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
if (videoSize.height > videoSize.width) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
|
// a video with normal aspect ratio
|
||||||
|
else ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||||
|
}
|
||||||
|
"auto" -> ActivityInfo.SCREEN_ORIENTATION_USER
|
||||||
|
"landscape" -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||||
|
"portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
|
else -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||||
}
|
}
|
||||||
"auto" -> ActivityInfo.SCREEN_ORIENTATION_USER
|
mainActivity.requestedOrientation = orientation
|
||||||
"landscape" -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
|
||||||
"portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
else -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
|
||||||
}
|
}
|
||||||
mainActivity.requestedOrientation = orientation
|
|
||||||
|
|
||||||
Globals.isFullScreen = true
|
Globals.isFullScreen = true
|
||||||
}
|
}
|
||||||
@ -373,8 +407,11 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
scaleControls(1F)
|
scaleControls(1F)
|
||||||
|
|
||||||
val mainActivity = activity as MainActivity
|
if (!autoRotationEnabled) {
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
// switch back to portrait mode if auto rotation disabled
|
||||||
|
val mainActivity = activity as MainActivity
|
||||||
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
|
}
|
||||||
|
|
||||||
Globals.isFullScreen = false
|
Globals.isFullScreen = false
|
||||||
}
|
}
|
||||||
@ -497,10 +534,6 @@ class PlayerFragment : Fragment() {
|
|||||||
uploader = response.uploader!!
|
uploader = response.uploader!!
|
||||||
thumbnailUrl = response.thumbnailUrl!!
|
thumbnailUrl = response.thumbnailUrl!!
|
||||||
|
|
||||||
// save whether related streams and autoplay are enabled
|
|
||||||
autoplay = PreferenceHelper.getBoolean(requireContext(), "autoplay", false)
|
|
||||||
relatedStreamsEnabled =
|
|
||||||
PreferenceHelper.getBoolean(requireContext(), "related_streams_toggle", true)
|
|
||||||
// save related streams for autoplay
|
// save related streams for autoplay
|
||||||
relatedStreams = response.relatedStreams
|
relatedStreams = response.relatedStreams
|
||||||
|
|
||||||
@ -1426,17 +1459,7 @@ class PlayerFragment : Fragment() {
|
|||||||
exoPlayerView.hideController()
|
exoPlayerView.hideController()
|
||||||
exoPlayerView.useController = false
|
exoPlayerView.useController = false
|
||||||
|
|
||||||
// hide anything but the player
|
unsetFullscreen()
|
||||||
binding.linLayout.visibility = View.GONE
|
|
||||||
binding.mainContainer.isClickable = true
|
|
||||||
|
|
||||||
with(binding.playerMotionLayout) {
|
|
||||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
|
|
||||||
enableTransition(R.id.yt_transition, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
|
|
||||||
Globals.isFullScreen = false
|
Globals.isFullScreen = false
|
||||||
} else {
|
} else {
|
||||||
@ -1462,4 +1485,19 @@ class PlayerFragment : Fragment() {
|
|||||||
private fun updatePipParams() = PictureInPictureParams.Builder()
|
private fun updatePipParams() = PictureInPictureParams.Builder()
|
||||||
.setActions(emptyList())
|
.setActions(emptyList())
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
|
||||||
|
if (autoRotationEnabled) {
|
||||||
|
val orientation = newConfig.orientation
|
||||||
|
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
|
// go to fullscreen mode
|
||||||
|
setFullscreen()
|
||||||
|
} else {
|
||||||
|
// exit fullscreen if not landscape
|
||||||
|
unsetFullscreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.github.libretube.preferences
|
package com.github.libretube.preferences
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.activities.SettingsActivity
|
import com.github.libretube.activities.SettingsActivity
|
||||||
|
|
||||||
@ -13,5 +15,20 @@ class PlayerSettings : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
val settingsActivity = activity as SettingsActivity
|
val settingsActivity = activity as SettingsActivity
|
||||||
settingsActivity.changeTopBarText(getString(R.string.audio_video))
|
settingsActivity.changeTopBarText(getString(R.string.audio_video))
|
||||||
|
|
||||||
|
val playerOrientation = findPreference<ListPreference>("fullscreen_orientation")
|
||||||
|
val autoRotateToFullscreen = findPreference<SwitchPreferenceCompat>("auto_fullscreen")
|
||||||
|
|
||||||
|
// only show the player orientation option if auto fullscreen is disabled
|
||||||
|
playerOrientation?.isEnabled != PreferenceHelper.getBoolean(
|
||||||
|
requireContext(),
|
||||||
|
"auto_fullscreen",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
autoRotateToFullscreen?.setOnPreferenceChangeListener { _, newValue ->
|
||||||
|
playerOrientation?.isEnabled = newValue != true
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
app/src/main/res/drawable/ic_rotating_circle.xml
Normal file
4
app/src/main/res/drawable/ic_rotating_circle.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<vector android:height="24dp" android:viewportHeight="48"
|
||||||
|
android:viewportWidth="48" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FF000000" android:pathData="m24.1,38 l5.7,-5.65 -5.7,-5.65 -2.1,2.1 2.15,2.15q-1.4,0.05 -2.725,-0.45 -1.325,-0.5 -2.375,-1.55 -1,-1 -1.525,-2.3 -0.525,-1.3 -0.525,-2.6 0,-0.85 0.225,-1.7t0.625,-1.65l-2.2,-2.2q-0.85,1.25 -1.25,2.65T14,24q0,1.9 0.75,3.75t2.2,3.3q1.45,1.45 3.25,2.175 1.8,0.725 3.7,0.775L22,35.9ZM32.35,29.5q0.85,-1.25 1.25,-2.65T34,24q0,-1.9 -0.725,-3.775T31.1,16.9q-1.45,-1.45 -3.275,-2.15t-3.725,-0.7L26,12.1 23.9,10l-5.7,5.65 5.7,5.65 2.1,-2.1 -2.2,-2.2q1.35,0 2.75,0.525t2.4,1.525q1,1 1.525,2.3 0.525,1.3 0.525,2.6 0,0.85 -0.225,1.7t-0.625,1.65ZM24,44q-4.1,0 -7.75,-1.575 -3.65,-1.575 -6.375,-4.3 -2.725,-2.725 -4.3,-6.375Q4,28.1 4,24q0,-4.15 1.575,-7.8 1.575,-3.65 4.3,-6.35 2.725,-2.7 6.375,-4.275Q19.9,4 24,4q4.15,0 7.8,1.575 3.65,1.575 6.35,4.275 2.7,2.7 4.275,6.35Q44,19.85 44,24q0,4.1 -1.575,7.75 -1.575,3.65 -4.275,6.375t-6.35,4.3Q28.15,44 24,44Z"/>
|
||||||
|
</vector>
|
@ -237,4 +237,6 @@
|
|||||||
<string name="always">Always</string>
|
<string name="always">Always</string>
|
||||||
<string name="selected">Selected</string>
|
<string name="selected">Selected</string>
|
||||||
<string name="never">Never</string>
|
<string name="never">Never</string>
|
||||||
|
<string name="autoRotatePlayer">Auto fullscreen</string>
|
||||||
|
<string name="autoRotatePlayer_summary">Automatically switch to player fullscreen when the device gets turned.</string>
|
||||||
</resources>
|
</resources>
|
@ -60,15 +60,24 @@
|
|||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:icon="@drawable/ic_play_filled"
|
android:icon="@drawable/ic_play_filled"
|
||||||
android:summary="@string/autoplay_summary"
|
android:summary="@string/autoplay_summary"
|
||||||
|
app:defaultValue="true"
|
||||||
app:key="autoplay"
|
app:key="autoplay"
|
||||||
app:title="@string/player_autoplay" />
|
app:title="@string/player_autoplay" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:icon="@drawable/ic_pause_filled"
|
android:icon="@drawable/ic_pause_filled"
|
||||||
android:summary="@string/pauseOnScreenOff_summary"
|
android:summary="@string/pauseOnScreenOff_summary"
|
||||||
|
app:defaultValue="false"
|
||||||
app:key="pause_screen_off"
|
app:key="pause_screen_off"
|
||||||
app:title="@string/pauseOnScreenOff" />
|
app:title="@string/pauseOnScreenOff" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:icon="@drawable/ic_rotating_circle"
|
||||||
|
android:summary="@string/autoRotatePlayer_summary"
|
||||||
|
app:defaultValue="false"
|
||||||
|
app:key="auto_fullscreen"
|
||||||
|
app:title="@string/autoRotatePlayer" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:icon="@drawable/ic_flip"
|
android:icon="@drawable/ic_flip"
|
||||||
app:defaultValue="ratio"
|
app:defaultValue="ratio"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user