From 57128faa1fb14820cd49697b165cd74b75b54267 Mon Sep 17 00:00:00 2001 From: Arthur Geron Date: Thu, 24 Aug 2023 16:37:42 -0300 Subject: [PATCH] fix: android warnings uncovered player states --- .../ivs/reactnative/player/AmazonIvsView.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/amazonaws/ivs/reactnative/player/AmazonIvsView.kt b/android/src/main/java/com/amazonaws/ivs/reactnative/player/AmazonIvsView.kt index f1030f8..91e134c 100644 --- a/android/src/main/java/com/amazonaws/ivs/reactnative/player/AmazonIvsView.kt +++ b/android/src/main/java/com/amazonaws/ivs/reactnative/player/AmazonIvsView.kt @@ -4,7 +4,7 @@ import android.content.pm.PackageManager import android.net.Uri import android.widget.FrameLayout import com.amazonaws.ivs.player.* -import android.os.Build +import com.amazonaws.ivs.player.Player.State.* import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.LifecycleEventListener import com.facebook.react.bridge.ReactContext @@ -305,7 +305,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte val reactContext = context as ReactContext when (state) { - Player.State.PLAYING -> { + PLAYING -> { if (!finishedLoading) { val onLoadData = Arguments.createMap() val parsedDuration = getDuration(player!!.duration); @@ -316,7 +316,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.LOAD.toString(), onLoadData) } } - Player.State.READY -> { + READY -> { val data = Arguments.createMap() val playerData = Arguments.createMap() playerData.putString("version", player?.version) @@ -337,8 +337,10 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte data.putMap("playerData", playerData) reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.DATA.toString(), data) - } - else -> {} + }; + BUFFERING -> {} // The following empty statements are intentional and avoid Kotlin’s "expression must be exhaustive" error. + IDLE -> {} + ENDED -> {} } val onStateChangeData = Arguments.createMap() @@ -409,7 +411,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte lastDuration = player?.duration } player?.position?.let { position -> - if (position > 0 && player?.state === Player.State.PLAYING) { + if (position > 0 && player?.state === PLAYING) { onProgress(position) } } @@ -421,11 +423,11 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte private fun mapPlayerState(state: Player.State): String { return when(state) { - Player.State.PLAYING -> "Playing" - Player.State.BUFFERING -> "Buffering" - Player.State.READY -> "Ready" - Player.State.IDLE -> "Idle" - Player.State.ENDED -> "Ended" + PLAYING -> "Playing" + BUFFERING -> "Buffering" + READY -> "Ready" + IDLE -> "Idle" + ENDED -> "Ended" } }