Skip to content

Commit

Permalink
chore: various code clean (TheWidlarzGroup#3591)
Browse files Browse the repository at this point in the history
* chore: remove media3 dependancy from common

* chore: remove unused

* chore: fix linter change

---------

Co-authored-by: Olivier Bouillet <[email protected]>
  • Loading branch information
freeboub and Olivier Bouillet authored Mar 21, 2024
1 parent 21a19aa commit 408cfb2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
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;
Expand Down Expand Up @@ -449,14 +447,14 @@ public void receiveAdEvent(String event) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
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;
Expand Down Expand Up @@ -2124,6 +2125,7 @@ public void onAdEvent(AdEvent adEvent) {

@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()));
}
}

0 comments on commit 408cfb2

Please sign in to comment.