mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
feat(session): split the display resolution into landscape and portrait
Landscape and Portrait resolution rows with the same options, each with a Follow option so one can mirror the other. Existing choices stay as the landscape resolution and portrait follows landscape by default, so nothing changes until portrait is set.
This commit is contained in:
41 files changed
+305
-64
No files matched your search
@@ -12,6 +12,9 @@ object SessionDisplay {
|
||||
const val FOLLOW_SCALE_MAX = 8f
|
||||
private const val FOLLOW_SCALED_PREFIX = "follow/"
|
||||
|
||||
const val LINK_LANDSCAPE = "link/landscape"
|
||||
const val LINK_PORTRAIT = "link/portrait"
|
||||
|
||||
const val DEFAULT_RESOLUTION = "720p"
|
||||
private val PRESET_HEIGHTS = listOf(720, 900, 1080)
|
||||
|
||||
@@ -35,6 +38,23 @@ object SessionDisplay {
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun isLink(choice: String): Boolean = choice == LINK_LANDSCAPE || choice == LINK_PORTRAIT
|
||||
|
||||
fun orientCustom(choice: String, portrait: Boolean): String {
|
||||
val parts = choice.split('x').map { it.toIntOrNull() }
|
||||
if (parts.size != 2 || parts.any { it == null || it <= 0 }) return choice
|
||||
val width = parts[0]!!
|
||||
val height = parts[1]!!
|
||||
return if ((portrait && width > height) || (!portrait && height > width)) "${height}x$width" else choice
|
||||
}
|
||||
|
||||
fun effectiveChoice(landscape: String, portrait: String, forPortrait: Boolean): String {
|
||||
val own = if (forPortrait) portrait else landscape
|
||||
if (!isLink(own)) return own
|
||||
val other = if (forPortrait) landscape else portrait
|
||||
return if (isLink(other)) DEFAULT_RESOLUTION else orientCustom(other, forPortrait)
|
||||
}
|
||||
|
||||
fun screenSize(panel: Pair<Int, Int>): Pair<Int, Int> =
|
||||
(maxOf(panel.first, panel.second) and 1.inv()) to (minOf(panel.first, panel.second) and 1.inv())
|
||||
|
||||
|
||||
@@ -1296,14 +1296,27 @@ object SessionPrefs {
|
||||
|
||||
private fun resolutionCap(context: Context, mode: String): Int = prefs(context).getInt("resolutionCap.$mode", 720)
|
||||
|
||||
fun resolutionChosen(context: Context, mode: String): Boolean =
|
||||
fun resolutionChosen(context: Context, mode: String, portrait: Boolean = false): Boolean =
|
||||
prefs(context).contains("displayResolution.$mode") ||
|
||||
prefs(context).contains("resolutionCap.$mode") || customResolution(context, mode) != null
|
||||
prefs(context).contains("resolutionCap.$mode") || customResolution(context, mode) != null ||
|
||||
(portrait && prefs(context).contains("displayResolution.portrait.$mode"))
|
||||
|
||||
fun resolutionChoice(context: Context, mode: String, panel: Pair<Int, Int>): String {
|
||||
fun resolutionChoice(context: Context, mode: String, panel: Pair<Int, Int>, portrait: Boolean = false): String =
|
||||
SessionDisplay.effectiveChoice(
|
||||
resolutionStored(context, mode, panel, false), resolutionStored(context, mode, panel, true), portrait)
|
||||
|
||||
fun resolutionStored(context: Context, mode: String, panel: Pair<Int, Int>, portrait: Boolean): String {
|
||||
if (!portrait) return landscapeResolutionStored(context, mode, panel)
|
||||
val value = prefs(context).getString("displayResolution.portrait.$mode", null) ?: return SessionDisplay.LINK_LANDSCAPE
|
||||
if (value == SessionDisplay.LINK_LANDSCAPE || value == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(value) ||
|
||||
SessionDisplay.presetHeight(value) != null) return value
|
||||
return parseResolution(value)?.let { "${it.first}x${it.second}" } ?: SessionDisplay.LINK_LANDSCAPE
|
||||
}
|
||||
|
||||
private fun landscapeResolutionStored(context: Context, mode: String, panel: Pair<Int, Int>): String {
|
||||
val saved = prefs(context)
|
||||
saved.getString("displayResolution.$mode", null)?.let { value ->
|
||||
if (value == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(value) ||
|
||||
if (value == SessionDisplay.MATCH_SCREEN || value == SessionDisplay.LINK_PORTRAIT || SessionDisplay.isFollow(value) ||
|
||||
SessionDisplay.presetHeight(value) != null) return value
|
||||
parseResolution(value)?.let { return "${it.first}x${it.second}" }
|
||||
}
|
||||
@@ -1315,13 +1328,22 @@ object SessionPrefs {
|
||||
else "${legacy.first}x${legacy.second}"
|
||||
}
|
||||
|
||||
fun setResolutionChoice(context: Context, mode: String, choice: String) {
|
||||
val value = if (choice == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(choice) ||
|
||||
fun setResolutionChoice(context: Context, mode: String, choice: String, portrait: Boolean = false) {
|
||||
val link = if (portrait) SessionDisplay.LINK_LANDSCAPE else SessionDisplay.LINK_PORTRAIT
|
||||
val value = if (choice == link || choice == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(choice) ||
|
||||
SessionDisplay.presetHeight(choice) != null) choice else {
|
||||
val size = requireNotNull(parseResolution(choice)) { "Invalid resolution" }
|
||||
"${size.first}x${size.second}"
|
||||
}
|
||||
prefs(context).edit().putString("displayResolution.$mode", value).apply()
|
||||
val panel = SessionDisplay.panelSize(context)
|
||||
val landscapeStored = resolutionStored(context, mode, panel, false)
|
||||
val portraitStored = resolutionStored(context, mode, panel, true)
|
||||
val edit = prefs(context).edit()
|
||||
if (value == link && SessionDisplay.isLink(if (portrait) landscapeStored else portraitStored)) {
|
||||
val concrete = SessionDisplay.effectiveChoice(landscapeStored, portraitStored, !portrait)
|
||||
edit.putString(if (portrait) "displayResolution.$mode" else "displayResolution.portrait.$mode", concrete)
|
||||
}
|
||||
edit.putString(if (portrait) "displayResolution.portrait.$mode" else "displayResolution.$mode", value).apply()
|
||||
}
|
||||
|
||||
fun fexPreset(context: Context): String = prefs(context).getString("fexPreset", DEFAULT_FEX_PRESET) ?: DEFAULT_FEX_PRESET
|
||||
|
||||
Reference in new issue
Block a user