Skip to content

Commit c8f7ecc

Browse files
authored
Merge pull request #161 from OneSignal/outcome_events_release
Outcome events release
2 parents 2f6e704 + e7a4301 commit c8f7ecc

24 files changed

+451
-39
lines changed

android/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.onesignal.flutter'
2-
version '2.1.0'
2+
version '2.2.0'
33

44
buildscript {
55
repositories {
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.0.1'
11+
classpath 'com.android.tools.build:gradle:3.5.0'
1212
}
1313
}
1414

@@ -34,16 +34,16 @@ android {
3434
}
3535

3636
dependencies {
37-
compile('com.onesignal:OneSignal:3.11.4')
37+
api 'com.onesignal:OneSignal:3.12.2'
3838
}
3939

4040
// Adds required manifestPlaceholders keys to allow mainifest merge gradle step to complete
4141
// The OneSignal app id should be set in your JS code.
4242
// Google project number / FCM Sender ID will be pulled in from the OneSignal dashbaord
4343
class DefaultManifestPlaceHolders {
4444
static final MANIFEST_PLACEHOLDERS_DEFAULTS = [
45-
onesignal_app_id: '',
46-
onesignal_google_project_number: 'REMOTE'
45+
onesignal_app_id: '${onesignal_app_id}',
46+
onesignal_google_project_number: '${onesignal_google_project_number}'
4747
]
4848

4949
static void addManifestToAppProject(Project proj) {
@@ -62,7 +62,7 @@ class DefaultManifestPlaceHolders {
6262
}
6363

6464
rootProject.childProjects.each { projName, proj ->
65-
if (projName != 'app')
65+
if (projName != 'app' && projName != 'onesignal_flutter')
6666
return
6767

6868
if (proj.hasProperty('android')) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Jul 16 17:30:59 PDT 2018
1+
#Thu Oct 17 14:56:12 PDT 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.onesignal.flutter;
2+
3+
import com.onesignal.OneSignal;
4+
import com.onesignal.OutcomeEvent;
5+
6+
import java.util.HashMap;
7+
import java.util.concurrent.atomic.AtomicBoolean;
8+
9+
import io.flutter.plugin.common.MethodCall;
10+
import io.flutter.plugin.common.MethodChannel;
11+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
12+
import io.flutter.plugin.common.MethodChannel.Result;
13+
import io.flutter.plugin.common.PluginRegistry;
14+
import io.flutter.plugin.common.PluginRegistry.Registrar;
15+
16+
class OSFlutterOutcomeEventsHandler extends FlutterRegistrarResponder implements OneSignal.OutcomeCallback {
17+
private Result result;
18+
19+
// the outcome events callbacks can in some instances be called more than once
20+
// ie. cached vs. server response.
21+
// this property guarantees the callback will never be called more than once.
22+
private AtomicBoolean replySubmitted = new AtomicBoolean(false);
23+
24+
OSFlutterOutcomeEventsHandler(PluginRegistry.Registrar flutterRegistrar, MethodChannel channel, Result result) {
25+
this.flutterRegistrar = flutterRegistrar;
26+
this.channel = channel;
27+
this.result = result;
28+
}
29+
30+
@Override
31+
public void onSuccess(OutcomeEvent outcomeEvent) {
32+
if (this.replySubmitted.getAndSet(true))
33+
return;
34+
35+
if (outcomeEvent == null)
36+
replySuccess(result, new HashMap<>());
37+
else
38+
replySuccess(result, OneSignalSerializer.convertOutcomeEventToMap(outcomeEvent));
39+
}
40+
41+
}
42+
43+
public class OneSignalOutcomeEventsController extends FlutterRegistrarResponder implements MethodCallHandler {
44+
private MethodChannel channel;
45+
private Registrar registrar;
46+
47+
static void registerWith(Registrar registrar) {
48+
OneSignalOutcomeEventsController controller = new OneSignalOutcomeEventsController();
49+
controller.registrar = registrar;
50+
controller.channel = new MethodChannel(registrar.messenger(), "OneSignal#outcomes");
51+
controller.channel.setMethodCallHandler(controller);
52+
controller.flutterRegistrar = registrar;
53+
}
54+
55+
@Override
56+
public void onMethodCall(MethodCall call, Result result) {
57+
if (call.method.contentEquals("OneSignal#sendOutcome"))
58+
this.sendOutcome(call, result);
59+
else if (call.method.contentEquals("OneSignal#sendUniqueOutcome"))
60+
this.sendUniqueOutcome(call, result);
61+
else if (call.method.contentEquals("OneSignal#sendOutcomeWithValue"))
62+
this.sendOutcomeWithValue(call, result);
63+
else
64+
replyNotImplemented(result);
65+
}
66+
67+
private void sendOutcome(MethodCall call, Result result) {
68+
String name = (String) call.arguments;
69+
70+
if (name == null || name.isEmpty()) {
71+
replyError(result, "OneSignal", "sendOutcome() name must not be null or empty", null);
72+
return;
73+
}
74+
75+
OneSignal.sendOutcome(name, new OSFlutterOutcomeEventsHandler(registrar, channel, result));
76+
}
77+
78+
private void sendUniqueOutcome(MethodCall call, Result result) {
79+
String name = (String) call.arguments;
80+
81+
if (name == null || name.isEmpty()) {
82+
replyError(result, "OneSignal", "sendUniqueOutcome() name must not be null or empty", null);
83+
return;
84+
}
85+
86+
OneSignal.sendUniqueOutcome(name, new OSFlutterOutcomeEventsHandler(registrar, channel, result));
87+
}
88+
89+
private void sendOutcomeWithValue(MethodCall call, Result result) {
90+
String name = call.argument("outcome_name");
91+
Double value = call.argument("outcome_value");
92+
93+
if (name == null || name.isEmpty()) {
94+
replyError(result, "OneSignal", "sendOutcomeWithValue() name must not be null or empty", null);
95+
return;
96+
}
97+
98+
if (value == null) {
99+
replyError(result, "OneSignal", "sendOutcomeWithValue() value must not be null", null);
100+
return;
101+
}
102+
103+
OneSignal.sendOutcomeWithValue(name, value.floatValue(), new OSFlutterOutcomeEventsHandler(registrar, channel, result));
104+
}
105+
106+
}

android/src/main/java/com/onesignal/flutter/OneSignalPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
7777

7878
OneSignalTagsController.registerWith(registrar);
7979
OneSignalInAppMessagingController.registerWith(registrar);
80+
OneSignalOutcomeEventsController.registerWith(registrar);
8081
}
8182

8283
@Override

android/src/main/java/com/onesignal/flutter/OneSignalSerializer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ static HashMap<String, Object> convertInAppMessageClickedActionToMap(OSInAppMess
197197
return hash;
198198
}
199199

200+
static HashMap<String, Object> convertOutcomeEventToMap(OutcomeEvent outcomeEvent) {
201+
HashMap<String, Object> hash = new HashMap<>();
202+
203+
hash.put("session", outcomeEvent.getSession().toString());
204+
205+
if (outcomeEvent.getNotificationIds() == null)
206+
hash.put("notification_ids", new JSONArray().toString());
207+
else
208+
hash.put("notification_ids", outcomeEvent.getNotificationIds().toString());
209+
210+
hash.put("id", outcomeEvent.getName());
211+
hash.put("timestamp", outcomeEvent.getTimestamp());
212+
hash.put("weight", String.valueOf(outcomeEvent.getWeight()));
213+
214+
return hash;
215+
}
216+
200217
private static HashMap<String, Object> convertAndroidBackgroundImageLayoutToMap(BackgroundImageLayout layout) {
201218
HashMap<String, Object> hash = new HashMap<>();
202219

android/src/main/java/com/onesignal/flutter/OneSignalTagsController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static void registerWith(Registrar registrar) {
7979
controller.registrar = registrar;
8080
controller.channel = new MethodChannel(registrar.messenger(), "OneSignal#tags");
8181
controller.channel.setMethodCallHandler(controller);
82+
controller.flutterRegistrar = registrar;
8283
}
8384

8485
@Override

example/android/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ apply plugin: 'com.android.application'
2929
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
3030

3131
android {
32-
compileSdkVersion 27
32+
compileSdkVersion 28
3333

3434
lintOptions {
3535
disable 'InvalidPackage'
@@ -39,7 +39,7 @@ android {
3939
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
4040
applicationId "com.onesignal.onesignalexample"
4141
minSdkVersion 16
42-
targetSdkVersion 27
42+
targetSdkVersion 28
4343
versionCode 1
4444
versionName "1.0"
4545
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -60,6 +60,6 @@ flutter {
6060

6161
dependencies {
6262
testImplementation 'junit:junit:4.12'
63-
androidTestImplementation 'com.android.support.test:runner:1.0.1'
64-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
63+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
64+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
6565
}

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.1.3'
8+
classpath 'com.android.tools.build:gradle:3.5.0'
99
}
1010
}
1111

example/android/gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
org.gradle.jvmargs=-Xmx1536M
2+
3+
android.enableR8=true
4+
android.enableD8=true
5+
6+
android.useAndroidX=true
7+
android.enableJetifier=true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jun 23 08:50:38 CEST 2017
1+
#Thu Oct 17 15:00:44 PDT 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

0 commit comments

Comments
 (0)