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