From 3bfd90c29e8235805dedef1aad252b8d806ad359 Mon Sep 17 00:00:00 2001 From: Amit Levy Date: Wed, 6 Nov 2024 16:12:04 +0200 Subject: [PATCH] update imports and onResponse --- .../reactnative/PCAppsFlyerModule.java | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/android/src/main/includeConnector/com/appsflyer/reactnative/PCAppsFlyerModule.java b/android/src/main/includeConnector/com/appsflyer/reactnative/PCAppsFlyerModule.java index f53e6977..f4dce1e0 100644 --- a/android/src/main/includeConnector/com/appsflyer/reactnative/PCAppsFlyerModule.java +++ b/android/src/main/includeConnector/com/appsflyer/reactnative/PCAppsFlyerModule.java @@ -2,6 +2,7 @@ import android.util.Log; +import com.appsflyer.api.PurchaseClient; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; @@ -9,10 +10,10 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.WritableMap; -import com.facebook.react.bridge.WritableArray; import org.json.JSONObject; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; import java.util.Arrays; @@ -96,16 +97,8 @@ public void onFailure(String result, Throwable error) { @Override public void onResponse(Map response) { if (response != null) { - WritableArray writableArray = Arguments.createArray(); - for (Map.Entry entry : response.entrySet()) { - if (entry.getValue() instanceof Map) { - Map productData = (Map) entry.getValue(); - WritableMap writableMap = RNUtil.toWritableMap(productData); - writableArray.pushMap(writableMap); - } - } - - handleSuccess(EVENT_SUBSCRIPTION_VALIDATION_SUCCESS, writableArray); + WritableMap writableMap = RNUtil.toWritableMap(response); + handleSuccess(EVENT_SUBSCRIPTION_VALIDATION_SUCCESS, writableMap); } } }; @@ -137,16 +130,16 @@ private void handleError(String eventName, String result, Throwable error) { } private void sendEvent(String eventName, Object params) { - ReactApplicationContext context = reactContext.get(); // Retrieve the context from WeakReference - - if (context != null && context.hasActiveReactInstance()) { // Ensure context is not null and active - Log.d("ReactNativeJS", "Event: " + eventName + ", params: " + params.toString()); - context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) - .emit(eventName, params); - } else { - Log.d("ReactNativeJS", "Skipping event: " + eventName + " (ReactContext is null or inactive)"); + ReactApplicationContext context = reactContext.get(); // Retrieve the context from WeakReference + if (context != null && context.hasActiveReactInstance()) { // Ensure context is not null and active + Log.d("ReactNativeJS", "Event: " + eventName + ", params: " + params.toString()); + context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit(eventName, params); + } else { + Log.d("ReactNativeJS", "Skipping event: " + eventName + " (ReactContext is null or inactive)"); + } } -} + private WritableMap errorToMap(Throwable error) { JSONObject errorJson = new JSONObject(this.throwableToMap(error)); WritableMap errorMap = RNUtil.jsonToWritableMap(errorJson);