Skip to content

Commit c3b27b8

Browse files
author
john-gu
committed
Add Rex's setDelegate, remove currency race condition
1 parent 4462736 commit c3b27b8

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

src/android/com/mobileapptracking/MATPlugin.java

+34-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.apache.cordova.CallbackContext;
88
import org.apache.cordova.CordovaPlugin;
9+
import org.apache.cordova.PluginResult;
910
import org.json.JSONArray;
1011
import org.json.JSONException;
1112
import org.json.JSONObject;
@@ -17,6 +18,7 @@
1718
import android.telephony.TelephonyManager;
1819

1920
import com.mobileapptracker.MATEventItem;
21+
import com.mobileapptracker.MATResponse;
2022
import com.mobileapptracker.MobileAppTracker;
2123

2224
public class MATPlugin extends CordovaPlugin {
@@ -30,6 +32,7 @@ public class MATPlugin extends CordovaPlugin {
3032
public static final String SETAPPADTRACKING = "setAppAdTracking";
3133
public static final String SETALLOWDUP = "setAllowDuplicates";
3234
public static final String SETDEBUG = "setDebugMode";
35+
public static final String SETDELEGATE = "setDelegate";
3336
public static final String SETDEVICEID = "setDeviceId";
3437
public static final String SETEVENTATTRIBUTE1 = "setEventAttribute1";
3538
public static final String SETEVENTATTRIBUTE2 = "setEventAttribute2";
@@ -502,6 +505,32 @@ public void run() {
502505
boolean payingUser = tracker.getIsPayingUser();
503506
callbackContext.success(String.valueOf(payingUser));
504507
return true;
508+
} else if (SETDELEGATE.equals(action)) {
509+
// default to true
510+
boolean enabled = args.optBoolean(0, true);
511+
tracker.setMATResponse(new MATResponse() {
512+
@Override
513+
public void enqueuedActionWithRefId(String refId) {
514+
PluginResult result = new PluginResult(PluginResult.Status.OK, "MATPlugin.matDelegate.enqueued: " + refId);
515+
result.setKeepCallback(true);
516+
callbackContext.sendPluginResult(result);
517+
}
518+
519+
@Override
520+
public void didSucceedWithData(JSONObject data) {
521+
PluginResult result = new PluginResult(PluginResult.Status.OK, data.toString());
522+
result.setKeepCallback(true);
523+
callbackContext.sendPluginResult(result);
524+
}
525+
526+
@Override
527+
public void didFailWithError(JSONObject error) {
528+
PluginResult result = new PluginResult(PluginResult.Status.OK, error.toString());
529+
result.setKeepCallback(true);
530+
callbackContext.sendPluginResult(result);
531+
}
532+
});
533+
return true;
505534
} else {
506535
callbackContext.error("Unsupported action on Android");
507536
return false;
@@ -563,25 +592,21 @@ public MeasureActionThread(String eventName, double revenue, String currency, St
563592
@Override
564593
public void run() {
565594
if (tracker != null) {
566-
// Set currency code if exists
567-
if (currency != null && currency.length() > 0 && !currency.equals("null")) {
568-
tracker.setCurrencyCode(currency);
569-
}
570595
// If there are any event items, track with event item
571596
if (eventItemList != null && eventItemList.size() > 0) {
572597
if (receiptData != null && !receiptData.equals("null") && receiptSignature != null && !receiptSignature.equals("null")) {
573598
// Track with receipt data if not null
574-
tracker.measureAction(eventName, eventItemList, revenue, tracker.getCurrencyCode(), refId, receiptData, receiptSignature);
599+
tracker.measureAction(eventName, eventItemList, revenue, currency, refId, receiptData, receiptSignature);
575600
} else {
576601
// Track with just event item
577-
tracker.measureAction(eventName, eventItemList, revenue, tracker.getCurrencyCode(), refId);
602+
tracker.measureAction(eventName, eventItemList, revenue, currency, refId);
578603
}
579604
} else if (receiptData != null && receiptSignature != null) {
580-
tracker.measureAction(eventName, null, revenue, tracker.getCurrencyCode(), refId, receiptData, receiptSignature);
605+
tracker.measureAction(eventName, null, revenue, currency, refId, receiptData, receiptSignature);
581606
} else if (refId != null && refId.length() > 0) {
582-
tracker.measureAction(eventName, revenue, tracker.getCurrencyCode(), refId);
607+
tracker.measureAction(eventName, revenue, currency, refId);
583608
} else {
584-
tracker.measureAction(eventName, revenue, tracker.getCurrencyCode());
609+
tracker.measureAction(eventName, revenue, currency);
585610
}
586611
cbc.success();
587612
} else {

0 commit comments

Comments
 (0)