From 6707306ef611c8ec3a50b54003f97598532129a0 Mon Sep 17 00:00:00 2001 From: Emily Dixon Date: Thu, 30 May 2024 12:05:53 -0700 Subject: [PATCH] Releases/v1.2.2 (#64) ## Improvements * fix: Absurd screen resolution reported in some cases (#62) * Update MuxCore to v8.0.2 Co-authored-by: Emily Dixon Co-authored-by: Tomislav Kordic <32546640+tomkordic@users.noreply.github.com> Co-authored-by: GitHub --- build.gradle | 6 ++-- core-android/build.gradle | 4 +-- .../mux/stats/sdk/muxstats/MuxUiDelegate.kt | 35 +++++++++++++++---- mux-kt-utils/build.gradle | 4 +-- .../main/java/com/mux/android/util/Util.kt | 3 ++ 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 08f5aca..1f98e7e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.3.1' apply false - id 'com.android.library' version '8.3.1' apply false - id 'org.jetbrains.kotlin.android' version '1.9.22' apply false + id 'com.android.application' version '8.3.2' apply false + id 'com.android.library' version '8.3.2' apply false + id 'org.jetbrains.kotlin.android' version '1.9.24' apply false id 'com.mux.gradle.android.mux-android-distribution' version '1.1.2' apply false } diff --git a/core-android/build.gradle b/core-android/build.gradle index d12fa8e..da3504c 100644 --- a/core-android/build.gradle +++ b/core-android/build.gradle @@ -54,7 +54,7 @@ muxDistribution { dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3" - api "com.mux:stats.muxcore:8.0.1" + api "com.mux:stats.muxcore:8.0.2" debugImplementation project(':mux-kt-utils') afterEvaluate { // The version isn't computed until after this file is finalized thanks to agp 8 @@ -63,7 +63,7 @@ dependencies { testImplementation 'junit:junit:4.13.2' testImplementation 'androidx.test.ext:junit:1.1.5' - testImplementation "io.mockk:mockk:1.12.3" + testImplementation "io.mockk:mockk:1.13.9" // hm, seems like they got rid of API 16 at some point, so we'd have to handle that. // Robolectric doesn't need updated for anything in particular tho, test deps aren't exported //noinspection GradleDependency diff --git a/core-android/src/main/java/com/mux/stats/sdk/muxstats/MuxUiDelegate.kt b/core-android/src/main/java/com/mux/stats/sdk/muxstats/MuxUiDelegate.kt index 4a54bb8..31f6dc6 100644 --- a/core-android/src/main/java/com/mux/stats/sdk/muxstats/MuxUiDelegate.kt +++ b/core-android/src/main/java/com/mux/stats/sdk/muxstats/MuxUiDelegate.kt @@ -12,9 +12,10 @@ import com.mux.stats.sdk.core.util.MuxLogger /** * Allows implementers to supply data about the view and screen being used for playback + * @param PV An object that can be used to access view and screen metrics, like a [View] */ -abstract class MuxUiDelegate(view: PlayerView?) { - var view by weak(view) +abstract class MuxUiDelegate(view: PV?) { + open var view by weak(view) /** * Gets the size of the player view in px as a pair of (width, height) @@ -47,9 +48,20 @@ abstract class MuxUiDelegate(view: PlayerView?) { private class AndroidUiDelegate(context: Context?, view: PlayerView?) : MuxUiDelegate(view) { - private val _screenSize: Point = - context?.let { it as? Activity }?.let { screenSize(it) } ?: Point() - private val displayDensity = context?.resources?.displayMetrics?.density ?: 0F + private var _screenSize: Point = screenSizeFromContext(context) + + private var displayDensity = displayDensityFromContext(context) + + override var view: PlayerView? + get() { + return super.view + } + set(value) { + val ctx = value?.context + _screenSize = screenSizeFromContext(ctx) + displayDensity = displayDensityFromContext(ctx) + super.view = value + } override fun getPlayerViewSize(): Point = view?.let { view -> Point().apply { @@ -60,6 +72,14 @@ private class AndroidUiDelegate(context: Context?, view: Play override fun getScreenSize(): Point = _screenSize + private fun displayDensityFromContext(context: Context?): Float { + return context?.resources?.displayMetrics?.density ?: 0F + } + + private fun screenSizeFromContext(context: Context?): Point { + return context?.let { it as? Activity }?.let { screenSize(it) } ?: Point() + } + private fun screenSize(activity: Activity): Point { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { screenSizeApiR(activity) @@ -110,7 +130,7 @@ private class AndroidUiDelegate(context: Context?, view: Play @Suppress("unused") @JvmSynthetic internal fun V.muxUiDelegate(context: Context) - : MuxUiDelegate = AndroidUiDelegate(context as? Activity, this) + : MuxUiDelegate = AndroidUiDelegate(context as? Activity, this) /** * Create a MuxUiDelegate for a view-less playback experience. Returns 0 for all sizes, as we are @@ -118,4 +138,5 @@ internal fun V.muxUiDelegate(context: Context) */ @Suppress("unused") @JvmSynthetic -internal fun noUiDelegate(context: Context): MuxUiDelegate = AndroidUiDelegate(context, null) +internal fun noUiDelegate(context: Context): MuxUiDelegate = + AndroidUiDelegate(context, null) diff --git a/mux-kt-utils/build.gradle b/mux-kt-utils/build.gradle index f1647c3..8dd2385 100644 --- a/mux-kt-utils/build.gradle +++ b/mux-kt-utils/build.gradle @@ -55,8 +55,8 @@ dependencies { testImplementation 'junit:junit:4.13.2' testImplementation 'androidx.test.ext:junit:1.1.5' - testImplementation "io.mockk:mockk:1.12.3" - testImplementation 'org.robolectric:robolectric:4.11' + testImplementation "io.mockk:mockk:1.13.9" + testImplementation 'org.robolectric:robolectric:4.11.1' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' diff --git a/mux-kt-utils/src/main/java/com/mux/android/util/Util.kt b/mux-kt-utils/src/main/java/com/mux/android/util/Util.kt index 16c7210..8056552 100644 --- a/mux-kt-utils/src/main/java/com/mux/android/util/Util.kt +++ b/mux-kt-utils/src/main/java/com/mux/android/util/Util.kt @@ -46,6 +46,9 @@ fun Int.clamp(min: Int, max: Int): Int { * Convert from a raw pixel dimension to a density-independent (dip) dimension */ fun convertPxToDp(px: Int, displayDensity: Float): Int { + if (displayDensity < 0.75F) { + return ceil((px / 0.75F).toDouble()).toInt() + } return ceil((px / displayDensity).toDouble()).toInt() }