Skip to content

Commit 2f6e704

Browse files
committed
Merge branch 'master' of github.com:OneSignal/OneSignal-Flutter-SDK
2 parents 48d01b0 + 4afbe17 commit 2f6e704

15 files changed

+510
-226
lines changed

android/build.gradle

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

44
buildscript {
55
repositories {
@@ -34,7 +34,7 @@ android {
3434
}
3535

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

4040
// Adds required manifestPlaceholders keys to allow mainifest merge gradle step to complete

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import io.flutter.plugin.common.PluginRegistry;
99

1010
abstract class FlutterRegistrarResponder {
11-
protected MethodChannel channel;
12-
protected PluginRegistry.Registrar flutterRegistrar;
11+
MethodChannel channel;
12+
PluginRegistry.Registrar flutterRegistrar;
1313

1414
/**
1515
* MethodChannel class is home to success() method used by Result class
1616
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
1717
* This will communicate success back to Dart
1818
*/
19-
protected void replySuccess(final MethodChannel.Result reply, final Object response) {
19+
void replySuccess(final MethodChannel.Result reply, final Object response) {
2020
runOnMainThread(new Runnable() {
2121
@Override
2222
public void run() {
@@ -30,7 +30,7 @@ public void run() {
3030
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
3131
* This will communicate error back to Dart
3232
*/
33-
protected void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
33+
void replyError(final MethodChannel.Result reply, final String tag, final String message, final Object response) {
3434
runOnMainThread(new Runnable() {
3535
@Override
3636
public void run() {
@@ -44,7 +44,7 @@ public void run() {
4444
* It has the @UiThread annotation and must be run on UI thread, otherwise a RuntimeException will be thrown
4545
* This will communicate not implemented back to Dart
4646
*/
47-
protected void replyNotImplemented(final MethodChannel.Result reply) {
47+
void replyNotImplemented(final MethodChannel.Result reply) {
4848
runOnMainThread(new Runnable() {
4949
@Override
5050
public void run() {
@@ -53,11 +53,11 @@ public void run() {
5353
});
5454
}
5555

56-
protected void runOnMainThread(final Runnable runnable) {
57-
((Activity)flutterRegistrar.activeContext()).runOnUiThread(runnable);
56+
private void runOnMainThread(final Runnable runnable) {
57+
((Activity) flutterRegistrar.activeContext()).runOnUiThread(runnable);
5858
}
5959

60-
protected void invokeMethodOnUiThread(final String methodName, final HashMap map) {
60+
void invokeMethodOnUiThread(final String methodName, final HashMap map) {
6161
final MethodChannel channel = this.channel;
6262
runOnMainThread(new Runnable() {
6363
@Override
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.onesignal.flutter;
2+
3+
import com.onesignal.OneSignal;
4+
5+
import java.util.Collection;
6+
import java.util.Map;
7+
8+
import io.flutter.plugin.common.MethodCall;
9+
import io.flutter.plugin.common.MethodChannel;
10+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
11+
import io.flutter.plugin.common.MethodChannel.Result;
12+
import io.flutter.plugin.common.PluginRegistry.Registrar;
13+
14+
public class OneSignalInAppMessagingController extends FlutterRegistrarResponder implements MethodCallHandler {
15+
private MethodChannel channel;
16+
17+
static void registerWith(Registrar registrar) {
18+
OneSignalInAppMessagingController controller = new OneSignalInAppMessagingController();
19+
controller.channel = new MethodChannel(registrar.messenger(), "OneSignal#inAppMessages");
20+
controller.channel.setMethodCallHandler(controller);
21+
controller.flutterRegistrar = registrar;
22+
}
23+
24+
@Override
25+
public void onMethodCall(MethodCall call, Result result) {
26+
if (call.method.contentEquals("OneSignal#addTrigger"))
27+
this.addTriggers(call, result);
28+
else if (call.method.contentEquals("OneSignal#addTriggers"))
29+
this.addTriggers(call, result);
30+
else if (call.method.contentEquals("OneSignal#removeTriggerForKey"))
31+
this.removeTriggerForKey(call, result);
32+
else if (call.method.contentEquals("OneSignal#removeTriggersForKeys"))
33+
this.removeTriggersForKeys(call, result);
34+
else if (call.method.contentEquals("OneSignal#getTriggerValueForKey"))
35+
replySuccess(result, OneSignal.getTriggerValueForKey((String) call.arguments));
36+
else if (call.method.contentEquals("OneSignal#pauseInAppMessages"))
37+
this.pauseInAppMessages(call, result);
38+
else
39+
replyNotImplemented(result);
40+
}
41+
42+
private void addTriggers(MethodCall call, Result result) {
43+
// call.arguments is being casted to a Map<String, Object> so a try-catch with
44+
// a ClassCastException will be thrown
45+
try {
46+
OneSignal.addTriggers((Map<String, Object>) call.arguments);
47+
replySuccess(result, null);
48+
} catch (ClassCastException e) {
49+
replyError(result, "OneSignal", "Add triggers failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
50+
}
51+
}
52+
53+
private void removeTriggerForKey(MethodCall call, Result result) {
54+
OneSignal.removeTriggerForKey((String) call.arguments);
55+
replySuccess(result, null);
56+
}
57+
58+
private void removeTriggersForKeys(MethodCall call, Result result) {
59+
// call.arguments is being casted to a Collection<String> a try-catch with
60+
// a ClassCastException will be thrown
61+
try {
62+
OneSignal.removeTriggersForKeys((Collection<String>) call.arguments);
63+
replySuccess(result, null);
64+
} catch (ClassCastException e) {
65+
replyError(result, "OneSignal", "Remove triggers for keys failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
66+
}
67+
}
68+
69+
private void pauseInAppMessages(MethodCall call, Result result) {
70+
OneSignal.pauseInAppMessages((boolean) call.arguments);
71+
replySuccess(result, null);
72+
}
73+
}

0 commit comments

Comments
 (0)