mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #4386 from Bnyro/master
feat: preference to force landscape as orientation
This commit is contained in:
commit
70f9583956
@ -17,7 +17,7 @@ object PreferenceKeys {
|
|||||||
*/
|
*/
|
||||||
const val LANGUAGE = "language"
|
const val LANGUAGE = "language"
|
||||||
const val REGION = "region"
|
const val REGION = "region"
|
||||||
const val AUTO_ROTATION = "auto_rotation"
|
const val ORIENTATION = "orientation"
|
||||||
const val SLEEP_TIMER = "sleep_timer_toggle"
|
const val SLEEP_TIMER = "sleep_timer_toggle"
|
||||||
const val SLEEP_TIMER_DELAY = "sleep_timer_delay"
|
const val SLEEP_TIMER_DELAY = "sleep_timer_delay"
|
||||||
const val SAVE_FEED = "save_feed"
|
const val SAVE_FEED = "save_feed"
|
||||||
|
@ -114,7 +114,7 @@ object PlayerHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val autoRotationEnabled: Boolean
|
val autoFullscreenEnabled: Boolean
|
||||||
get() = PreferenceHelper.getBoolean(
|
get() = PreferenceHelper.getBoolean(
|
||||||
PreferenceKeys.AUTO_FULLSCREEN,
|
PreferenceKeys.AUTO_FULLSCREEN,
|
||||||
false
|
false
|
||||||
|
@ -60,13 +60,6 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
private var savedSearchQuery: String? = null
|
private var savedSearchQuery: String? = null
|
||||||
|
|
||||||
val autoRotationEnabled by lazy {
|
|
||||||
PreferenceHelper.getBoolean(
|
|
||||||
PreferenceKeys.AUTO_ROTATION,
|
|
||||||
resources.getBoolean(R.bool.config_default_auto_rotation_pref)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@ -230,17 +223,6 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotate according to the preference
|
|
||||||
*/
|
|
||||||
fun requestOrientationChange() {
|
|
||||||
requestedOrientation = if (autoRotationEnabled) {
|
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER
|
|
||||||
} else {
|
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the notification badge showing the amount of new videos
|
* Initialize the notification badge showing the amount of new videos
|
||||||
*/
|
*/
|
||||||
@ -501,11 +483,7 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playerViewModel.isFullscreen.value = false
|
playerViewModel.isFullscreen.value = false
|
||||||
requestedOrientation = if (autoRotationEnabled) {
|
requestOrientationChange()
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER
|
|
||||||
} else {
|
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SwitchIntDef")
|
@SuppressLint("SwitchIntDef")
|
||||||
|
@ -1,14 +1,31 @@
|
|||||||
package com.github.libretube.ui.base
|
package com.github.libretube.ui.base
|
||||||
|
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import com.github.libretube.R
|
||||||
|
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.ThemeHelper
|
import com.github.libretube.helpers.ThemeHelper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity that applies the LibreTube theme and the in-app language
|
* Activity that applies the LibreTube theme and the in-app language
|
||||||
*/
|
*/
|
||||||
open class BaseActivity : AppCompatActivity() {
|
open class BaseActivity : AppCompatActivity() {
|
||||||
|
private val screenOrientationPref by lazy {
|
||||||
|
val orientationPref = PreferenceHelper.getString(
|
||||||
|
PreferenceKeys.ORIENTATION,
|
||||||
|
resources.getString(R.string.config_default_orientation_pref)
|
||||||
|
)
|
||||||
|
when (orientationPref) {
|
||||||
|
"portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
|
"landscape" -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||||
|
"auto" -> ActivityInfo.SCREEN_ORIENTATION_USER
|
||||||
|
else -> throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
@ -16,6 +33,15 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
// set the apps language
|
// set the apps language
|
||||||
LocaleHelper.updateLanguage(this)
|
LocaleHelper.updateLanguage(this)
|
||||||
|
|
||||||
|
requestOrientationChange()
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate according to the preference
|
||||||
|
*/
|
||||||
|
fun requestOrientationChange() {
|
||||||
|
requestedOrientation = screenOrientationPref
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
// FullScreen button trigger
|
// FullScreen button trigger
|
||||||
// hide fullscreen button if autorotation enabled
|
// hide fullscreen button if autorotation enabled
|
||||||
playerBinding.fullscreen.isInvisible = PlayerHelper.autoRotationEnabled
|
playerBinding.fullscreen.isInvisible = PlayerHelper.autoFullscreenEnabled
|
||||||
playerBinding.fullscreen.setOnClickListener {
|
playerBinding.fullscreen.setOnClickListener {
|
||||||
// hide player controller
|
// hide player controller
|
||||||
binding.player.hideController()
|
binding.player.hideController()
|
||||||
@ -513,7 +513,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
* Expected behavior: Portrait for shorts, Landscape for normal videos
|
* Expected behavior: Portrait for shorts, Landscape for normal videos
|
||||||
*/
|
*/
|
||||||
private fun updateFullscreenOrientation() {
|
private fun updateFullscreenOrientation() {
|
||||||
if (!PlayerHelper.autoRotationEnabled) {
|
if (!PlayerHelper.autoFullscreenEnabled) {
|
||||||
val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height
|
val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height
|
||||||
val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width
|
val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width
|
||||||
|
|
||||||
@ -563,7 +563,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
|
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
|
||||||
playerBinding.exoTitle.isInvisible = true
|
playerBinding.exoTitle.isInvisible = true
|
||||||
|
|
||||||
if (!PlayerHelper.autoRotationEnabled) {
|
if (!PlayerHelper.autoFullscreenEnabled) {
|
||||||
// switch back to portrait mode if autorotation disabled
|
// switch back to portrait mode if autorotation disabled
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
}
|
}
|
||||||
@ -641,12 +641,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
nowPlayingNotification.destroySelfAndPlayer()
|
nowPlayingNotification.destroySelfAndPlayer()
|
||||||
|
|
||||||
activity?.requestedOrientation =
|
(context as MainActivity).requestOrientationChange()
|
||||||
if ((activity as MainActivity).autoRotationEnabled) {
|
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER
|
|
||||||
} else {
|
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
@ -1400,7 +1395,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
*/
|
*/
|
||||||
@SuppressLint("SourceLockedOrientationActivity")
|
@SuppressLint("SourceLockedOrientationActivity")
|
||||||
private fun changeOrientationMode() {
|
private fun changeOrientationMode() {
|
||||||
if (PlayerHelper.autoRotationEnabled) {
|
if (PlayerHelper.autoFullscreenEnabled) {
|
||||||
// enable auto rotation
|
// enable auto rotation
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
|
||||||
onConfigurationChanged(resources.configuration)
|
onConfigurationChanged(resources.configuration)
|
||||||
@ -1612,7 +1607,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
|
|
||||||
if (!PlayerHelper.autoRotationEnabled || _binding == null ||
|
if (!PlayerHelper.autoFullscreenEnabled || _binding == null ||
|
||||||
// If in PiP mode, orientation is given as landscape.
|
// If in PiP mode, orientation is given as landscape.
|
||||||
PictureInPictureCompat.isInPictureInPictureMode(requireActivity())
|
PictureInPictureCompat.isInPictureInPictureMode(requireActivity())
|
||||||
) {
|
) {
|
||||||
|
@ -27,7 +27,7 @@ class GeneralSettings : BasePreferenceFragment() {
|
|||||||
val region = findPreference<ListPreference>("region")
|
val region = findPreference<ListPreference>("region")
|
||||||
region?.let { setupRegionPref(it) }
|
region?.let { setupRegionPref(it) }
|
||||||
|
|
||||||
val autoRotation = findPreference<SwitchPreferenceCompat>(PreferenceKeys.AUTO_ROTATION)
|
val autoRotation = findPreference<ListPreference>(PreferenceKeys.ORIENTATION)
|
||||||
autoRotation?.setOnPreferenceChangeListener { _, _ ->
|
autoRotation?.setOnPreferenceChangeListener { _, _ ->
|
||||||
RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name)
|
RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name)
|
||||||
true
|
true
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<bool name="config_default_auto_rotation_pref">true</bool>
|
<string name="config_default_orientation_pref" translatable="false">landscape</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -455,4 +455,16 @@
|
|||||||
<item>automatic</item>
|
<item>automatic</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="orientation">
|
||||||
|
<item>@string/portrait</item>
|
||||||
|
<item>@string/landscape</item>
|
||||||
|
<item>@string/auto_rotation</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="orientation_values">
|
||||||
|
<item>portrait</item>
|
||||||
|
<item>landscape</item>
|
||||||
|
<item>auto</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<bool name="config_default_auto_rotation_pref">false</bool>
|
<string name="config_default_orientation_pref" translatable="false">portrait</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -461,6 +461,7 @@
|
|||||||
<string name="unknown_or_no_audio">unknown or no audio</string>
|
<string name="unknown_or_no_audio">unknown or no audio</string>
|
||||||
<string name="continue_watching">Continue watching</string>
|
<string name="continue_watching">Continue watching</string>
|
||||||
<string name="no_chapter">No chapter</string>
|
<string name="no_chapter">No chapter</string>
|
||||||
|
<string name="screen_orientation">Screen orientation</string>
|
||||||
|
|
||||||
<!-- Notification channel strings -->
|
<!-- Notification channel strings -->
|
||||||
<string name="download_channel_name">Download Service</string>
|
<string name="download_channel_name">Download Service</string>
|
||||||
|
@ -30,11 +30,14 @@
|
|||||||
android:title="@string/audio_only_mode"
|
android:title="@string/audio_only_mode"
|
||||||
app:key="audio_only_mode" />
|
app:key="audio_only_mode" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<ListPreference
|
||||||
android:defaultValue="@bool/config_default_auto_rotation_pref"
|
android:defaultValue="@string/config_default_orientation_pref"
|
||||||
|
android:entries="@array/orientation"
|
||||||
|
android:entryValues="@array/orientation_values"
|
||||||
android:icon="@drawable/ic_screen_rotation"
|
android:icon="@drawable/ic_screen_rotation"
|
||||||
app:key="auto_rotation"
|
app:key="orientation"
|
||||||
app:title="@string/auto_rotation" />
|
app:title="@string/screen_orientation"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
|
Loading…
Reference in New Issue
Block a user