chore: various code clean (#3591)

* chore: remove media3 dependancy from common

* chore: remove unused

* chore: fix linter change

---------

Co-authored-by: Olivier Bouillet <olivier@OrdinateOlivier.lan>
This commit is contained in:
Olivier Bouillet 2024-03-21 14:07:53 +01:00 committed by GitHub
parent 21a19aabc5
commit 408cfb2c1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 48 deletions

View File

@ -11,8 +11,6 @@ import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.source.ads.AdsLoader;
import androidx.media3.exoplayer.source.ads.AdsMediaSource;
import com.facebook.react.uimanager.ThemedReactContext;
import java.io.IOException;
public class ImaAdsLoader implements AdsLoader {

View File

@ -14,8 +14,6 @@ import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.google.ads.interactivemedia.v3.api.AdError;
import java.io.PrintWriter;
import java.io.StringWriter;
@ -449,14 +447,14 @@ public class VideoEventEmitter {
receiveEvent(EVENT_ON_RECEIVE_AD_EVENT, map);
}
public void receiveAdErrorEvent(AdError error) {
public void receiveAdErrorEvent(String message, String code, String type) {
WritableMap map = Arguments.createMap();
map.putString("event", "ERROR");
WritableMap dataMap = Arguments.createMap();
dataMap.putString("message", error.getMessage());
dataMap.putString("code", String.valueOf(error.getErrorCode()));
dataMap.putString("type", String.valueOf(error.getErrorType()));
dataMap.putString("message", message);
dataMap.putString("code", code);
dataMap.putString("type", type);
map.putMap("data", dataMap);
receiveEvent(EVENT_ON_RECEIVE_AD_EVENT, map);

View File

@ -12,67 +12,47 @@ import java.util.HashMap
object ReactBridgeUtils {
@JvmStatic
fun safeGetString(map: ReadableMap?, key: String?, fallback: String?): String? {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getString(key) else fallback
}
fun safeGetString(map: ReadableMap?, key: String?, fallback: String?): String? =
if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getString(key) else fallback
@JvmStatic
fun safeGetString(map: ReadableMap?, key: String?): String? {
return safeGetString(map, key, null)
}
fun safeGetString(map: ReadableMap?, key: String?): String? = safeGetString(map, key, null)
@JvmStatic
fun safeGetDynamic(map: ReadableMap?, key: String?, fallback: Dynamic?): Dynamic? {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDynamic(key) else fallback
}
fun safeGetDynamic(map: ReadableMap?, key: String?, fallback: Dynamic?): Dynamic? =
if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDynamic(key) else fallback
@JvmStatic
fun safeGetDynamic(map: ReadableMap?, key: String?): Dynamic? {
return safeGetDynamic(map, key, null)
}
fun safeGetDynamic(map: ReadableMap?, key: String?): Dynamic? = safeGetDynamic(map, key, null)
@JvmStatic
fun safeGetBool(map: ReadableMap?, key: String?, fallback: Boolean): Boolean {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getBoolean(key) else fallback
}
fun safeGetBool(map: ReadableMap?, key: String?, fallback: Boolean): Boolean =
if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getBoolean(key) else fallback
@JvmStatic
fun safeGetMap(map: ReadableMap?, key: String?): ReadableMap? {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getMap(key) else null
}
fun safeGetMap(map: ReadableMap?, key: String?): ReadableMap? = if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getMap(key) else null
@JvmStatic
fun safeGetArray(map: ReadableMap?, key: String?): ReadableArray? {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getArray(key) else null
}
fun safeGetArray(map: ReadableMap?, key: String?): ReadableArray? = if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getArray(key) else null
@JvmStatic
fun safeGetInt(map: ReadableMap?, key: String?, fallback: Int): Int {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getInt(key) else fallback
}
fun safeGetInt(map: ReadableMap?, key: String?, fallback: Int): Int =
if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getInt(key) else fallback
@JvmStatic
fun safeGetInt(map: ReadableMap?, key: String?): Int {
return safeGetInt(map, key, 0)
}
fun safeGetInt(map: ReadableMap?, key: String?): Int = safeGetInt(map, key, 0)
@JvmStatic
fun safeGetDouble(map: ReadableMap?, key: String?, fallback: Double): Double {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDouble(key) else fallback
}
fun safeGetDouble(map: ReadableMap?, key: String?, fallback: Double): Double =
if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDouble(key) else fallback
@JvmStatic
fun safeGetDouble(map: ReadableMap?, key: String?): Double {
return safeGetDouble(map, key, 0.0)
}
fun safeGetDouble(map: ReadableMap?, key: String?): Double = safeGetDouble(map, key, 0.0)
@JvmStatic fun safeGetFloat(map: ReadableMap?, key: String?, fallback: Float): Float {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDouble(key).toFloat() else fallback
}
@JvmStatic fun safeGetFloat(map: ReadableMap?, key: String?, fallback: Float): Float =
if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDouble(key).toFloat() else fallback
@JvmStatic fun safeGetFloat(map: ReadableMap?, key: String?): Float {
return safeGetFloat(map, key, 0.0f)
}
@JvmStatic fun safeGetFloat(map: ReadableMap?, key: String?): Float = safeGetFloat(map, key, 0.0f)
/**
* toStringMap converts a [ReadableMap] into a HashMap.

View File

@ -108,6 +108,7 @@ import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.uimanager.ThemedReactContext;
import com.google.ads.interactivemedia.v3.api.AdError;
import com.google.ads.interactivemedia.v3.api.AdEvent;
import com.google.ads.interactivemedia.v3.api.AdErrorEvent;
import com.google.common.collect.ImmutableList;
@ -2124,6 +2125,7 @@ public class ReactExoplayerView extends FrameLayout implements
@Override
public void onAdError(AdErrorEvent adErrorEvent) {
eventEmitter.receiveAdErrorEvent(adErrorEvent.getError());
AdError error = adErrorEvent.getError();
eventEmitter.receiveAdErrorEvent(error.getMessage(), String.valueOf(error.getErrorCode()), String.valueOf(error.getErrorType()));
}
}