-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from OneSignal/outcome_events_release
Outcome events release
- Loading branch information
Showing
24 changed files
with
451 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon Jul 16 17:30:59 PDT 2018 | ||
#Thu Oct 17 14:56:12 PDT 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip |
106 changes: 106 additions & 0 deletions
106
android/src/main/java/com/onesignal/flutter/OneSignalOutcomeEventsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.onesignal.flutter; | ||
|
||
import com.onesignal.OneSignal; | ||
import com.onesignal.OutcomeEvent; | ||
|
||
import java.util.HashMap; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | ||
import io.flutter.plugin.common.MethodChannel.Result; | ||
import io.flutter.plugin.common.PluginRegistry; | ||
import io.flutter.plugin.common.PluginRegistry.Registrar; | ||
|
||
class OSFlutterOutcomeEventsHandler extends FlutterRegistrarResponder implements OneSignal.OutcomeCallback { | ||
private Result result; | ||
|
||
// the outcome events callbacks can in some instances be called more than once | ||
// ie. cached vs. server response. | ||
// this property guarantees the callback will never be called more than once. | ||
private AtomicBoolean replySubmitted = new AtomicBoolean(false); | ||
|
||
OSFlutterOutcomeEventsHandler(PluginRegistry.Registrar flutterRegistrar, MethodChannel channel, Result result) { | ||
this.flutterRegistrar = flutterRegistrar; | ||
this.channel = channel; | ||
this.result = result; | ||
} | ||
|
||
@Override | ||
public void onSuccess(OutcomeEvent outcomeEvent) { | ||
if (this.replySubmitted.getAndSet(true)) | ||
return; | ||
|
||
if (outcomeEvent == null) | ||
replySuccess(result, new HashMap<>()); | ||
else | ||
replySuccess(result, OneSignalSerializer.convertOutcomeEventToMap(outcomeEvent)); | ||
} | ||
|
||
} | ||
|
||
public class OneSignalOutcomeEventsController extends FlutterRegistrarResponder implements MethodCallHandler { | ||
private MethodChannel channel; | ||
private Registrar registrar; | ||
|
||
static void registerWith(Registrar registrar) { | ||
OneSignalOutcomeEventsController controller = new OneSignalOutcomeEventsController(); | ||
controller.registrar = registrar; | ||
controller.channel = new MethodChannel(registrar.messenger(), "OneSignal#outcomes"); | ||
controller.channel.setMethodCallHandler(controller); | ||
controller.flutterRegistrar = registrar; | ||
} | ||
|
||
@Override | ||
public void onMethodCall(MethodCall call, Result result) { | ||
if (call.method.contentEquals("OneSignal#sendOutcome")) | ||
this.sendOutcome(call, result); | ||
else if (call.method.contentEquals("OneSignal#sendUniqueOutcome")) | ||
this.sendUniqueOutcome(call, result); | ||
else if (call.method.contentEquals("OneSignal#sendOutcomeWithValue")) | ||
this.sendOutcomeWithValue(call, result); | ||
else | ||
replyNotImplemented(result); | ||
} | ||
|
||
private void sendOutcome(MethodCall call, Result result) { | ||
String name = (String) call.arguments; | ||
|
||
if (name == null || name.isEmpty()) { | ||
replyError(result, "OneSignal", "sendOutcome() name must not be null or empty", null); | ||
return; | ||
} | ||
|
||
OneSignal.sendOutcome(name, new OSFlutterOutcomeEventsHandler(registrar, channel, result)); | ||
} | ||
|
||
private void sendUniqueOutcome(MethodCall call, Result result) { | ||
String name = (String) call.arguments; | ||
|
||
if (name == null || name.isEmpty()) { | ||
replyError(result, "OneSignal", "sendUniqueOutcome() name must not be null or empty", null); | ||
return; | ||
} | ||
|
||
OneSignal.sendUniqueOutcome(name, new OSFlutterOutcomeEventsHandler(registrar, channel, result)); | ||
} | ||
|
||
private void sendOutcomeWithValue(MethodCall call, Result result) { | ||
String name = call.argument("outcome_name"); | ||
Double value = call.argument("outcome_value"); | ||
|
||
if (name == null || name.isEmpty()) { | ||
replyError(result, "OneSignal", "sendOutcomeWithValue() name must not be null or empty", null); | ||
return; | ||
} | ||
|
||
if (value == null) { | ||
replyError(result, "OneSignal", "sendOutcomeWithValue() value must not be null", null); | ||
return; | ||
} | ||
|
||
OneSignal.sendOutcomeWithValue(name, value.floatValue(), new OSFlutterOutcomeEventsHandler(registrar, channel, result)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
|
||
android.enableR8=true | ||
android.enableD8=true | ||
|
||
android.useAndroidX=true | ||
android.enableJetifier=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Jun 23 08:50:38 CEST 2017 | ||
#Thu Oct 17 15:00:44 PDT 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.