Skip to content

Commit

Permalink
Releases/v1.2.2 (#64)
Browse files Browse the repository at this point in the history
## Improvements

* fix: Absurd screen resolution reported in some cases (#62)
* Update MuxCore to v8.0.2


Co-authored-by: Emily Dixon <edixon@mux.com>
Co-authored-by: Tomislav Kordic <32546640+tomkordic@users.noreply.github.com>
Co-authored-by: GitHub <noreply@github.com>
  • Loading branch information
3 people authored May 30, 2024
1 parent 79fa4aa commit 6707306
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions core-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayerView>(view: PlayerView?) {
var view by weak(view)
abstract class MuxUiDelegate<PV>(view: PV?) {
open var view by weak(view)

/**
* Gets the size of the player view in px as a pair of (width, height)
Expand Down Expand Up @@ -47,9 +48,20 @@ abstract class MuxUiDelegate<PlayerView>(view: PlayerView?) {
private class AndroidUiDelegate<PlayerView : View>(context: Context?, view: PlayerView?) :
MuxUiDelegate<PlayerView>(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 {
Expand All @@ -60,6 +72,14 @@ private class AndroidUiDelegate<PlayerView : View>(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)
Expand Down Expand Up @@ -110,12 +130,13 @@ private class AndroidUiDelegate<PlayerView : View>(context: Context?, view: Play
@Suppress("unused")
@JvmSynthetic
internal fun <V : View> V.muxUiDelegate(context: Context)
: MuxUiDelegate<V> = AndroidUiDelegate(context as? Activity, this)
: MuxUiDelegate<V> = AndroidUiDelegate(context as? Activity, this)

/**
* Create a MuxUiDelegate for a view-less playback experience. Returns 0 for all sizes, as we are
* not able to get a Display from a non-activity context
*/
@Suppress("unused")
@JvmSynthetic
internal fun <V : View> noUiDelegate(context: Context): MuxUiDelegate<V> = AndroidUiDelegate(context, null)
internal fun <V : View> noUiDelegate(context: Context): MuxUiDelegate<V> =
AndroidUiDelegate(context, null)
4 changes: 2 additions & 2 deletions mux-kt-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions mux-kt-utils/src/main/java/com/mux/android/util/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 6707306

Please sign in to comment.