[Android] Fix the video resolution text generation
Nicolas Pomepuy
git at videolan.org
Wed Oct 5 07:46:11 UTC 2022
vlc-android | branch: 3.5.x | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Sep 30 08:42:41 2022 +0200| [a77af19a6a5a43603068aa080a9a892bcba852a9] | committer: Duncan McNamara
Fix the video resolution text generation
Fixes #2699
> https://code.videolan.org/videolan/vlc-android/commit/a77af19a6a5a43603068aa080a9a892bcba852a9
---
.../src/org/videolan/vlc/util/Kextensions.kt | 26 ++++++++++++++++------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 605150f8d..df6252e38 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -59,6 +59,7 @@ import java.net.URISyntaxException
import java.security.SecureRandom
import java.util.*
import kotlin.math.max
+import kotlin.math.min
import kotlin.math.roundToInt
fun String.validateLocation(): Boolean {
@@ -361,14 +362,25 @@ fun RecyclerView.Adapter<*>.onAnyChange(listener: ()->Unit): RecyclerView.Adapte
return dataObserver
}
-fun generateResolutionClass(width: Int, height: Int) : String? = if (width <= 0 || height <= 0) {
+/**
+ * Generate a string containing the commercial denomination of the video resolution
+ *
+ * @param width the video width
+ * @param height the video height
+ * @return the commercial resolution (SD, HD, 4K, ...)
+ */
+fun generateResolutionClass(width: Int, height: Int): String? = if (width <= 0 || height <= 0) {
null
-} else when {
- width >= 7680 -> "8K"
- width >= 3840 -> "4K"
- width >= 1920 -> "1080p"
- width >= 1280 -> "720p"
- else -> "SD"
+} else {
+ val realHeight = min(height, width)
+ when {
+ realHeight >= 4320 -> "8K"
+ realHeight >= 2160 -> "4K"
+ realHeight >= 1440 -> "qHD"
+ realHeight >= 1080 -> "FHD"
+ realHeight >= 720 -> "HD"
+ else -> "SD"
+ }
}
val View.scope : CoroutineScope
More information about the Android
mailing list