Skip to content

Commit 1fe7043

Browse files
author
Adam Schlesinger
committed
Add wrapper for IAM lifecycle on Android
1 parent ac3d35f commit 1fe7043

File tree

5 files changed

+122
-2
lines changed

5 files changed

+122
-2
lines changed

com.onesignal.unity.android/Runtime/OneSignalAndroid.Callbacks.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public sealed partial class OneSignalAndroid : OneSignal {
4343
private const string SDKClassName = "OneSignal";
4444
private const string QualifiedSDKClass = SDKPackage + "." + SDKClassName;
4545

46+
private const string IAMLifecycleClassName = "UnityIAMLifecycleHandler";
47+
private const string QualifiedIAMLifecycleClass = SDKPackage + "." + IAMLifecycleClassName;
48+
4649
private readonly AndroidJavaClass _sdkClass = new AndroidJavaClass(QualifiedSDKClass);
4750

4851
private abstract class OneSignalAndroidJavaProxy : AndroidJavaProxy {
@@ -82,8 +85,10 @@ public OneSignalAndroid() {
8285
_sdkClass.CallStatic("setNotificationOpenedHandler", new OSNotificationOpenedHandler());
8386

8487
// iams
85-
_sdkClass.CallStatic("setInAppMessageLifecycleHandler", new OSInAppMessageLifecycleHandler());
8688
_sdkClass.CallStatic("setInAppMessageClickHandler", new OSInAppMessageClickHandler());
89+
90+
var wrapperHandler = new AndroidJavaObject(QualifiedIAMLifecycleClass, new OSInAppMessageLifecycleHandler());
91+
_sdkClass.CallStatic("setInAppMessageLifecycleHandler", wrapperHandler);
8792

8893
_instance = this;
8994
}
@@ -156,7 +161,7 @@ public void notificationOpened(AndroidJavaObject result)
156161
}
157162

158163
private sealed class OSInAppMessageLifecycleHandler : OneSignalAndroidJavaProxy {
159-
public OSInAppMessageLifecycleHandler() : base("OSInAppMessageLifecycleHandler") { }
164+
public OSInAppMessageLifecycleHandler() : base(IAMLifecycleClassName + "$WrapperLifecycleHandler") { }
160165

161166
/// <param name="message">OSInAppMessage</param>
162167
public void onWillDisplayInAppMessage(AndroidJavaObject message)

com.onesignal.unity.android/Runtime/Plugins.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.onesignal.unity.android/Runtime/Plugins/Android.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Modified MIT License
3+
*
4+
* Copyright 2021 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
package com.onesignal;
29+
30+
public final class UnityIAMLifecycleHandler extends OSInAppMessageLifecycleHandler {
31+
private final WrapperLifecycleHandler wrapperLifeCycleHandler;
32+
33+
public UnityIAMLifecycleHandler(WrapperLifecycleHandler handler) {
34+
wrapperLifeCycleHandler = handler;
35+
}
36+
37+
public interface WrapperLifecycleHandler {
38+
void onWillDisplayInAppMessage(OSInAppMessage message);
39+
void onDidDisplayInAppMessage(OSInAppMessage message);
40+
void onWillDismissInAppMessage(OSInAppMessage message);
41+
void onDidDismissInAppMessage(OSInAppMessage message);
42+
}
43+
44+
@Override
45+
public void onWillDisplayInAppMessage(OSInAppMessage message) {
46+
if (wrapperLifeCycleHandler != null)
47+
wrapperLifeCycleHandler.onWillDisplayInAppMessage(message);
48+
}
49+
50+
@Override
51+
public void onDidDisplayInAppMessage(OSInAppMessage message) {
52+
if (wrapperLifeCycleHandler != null)
53+
wrapperLifeCycleHandler.onDidDisplayInAppMessage(message);
54+
}
55+
56+
@Override
57+
public void onWillDismissInAppMessage(OSInAppMessage message) {
58+
if (wrapperLifeCycleHandler != null)
59+
wrapperLifeCycleHandler.onWillDismissInAppMessage(message);
60+
}
61+
62+
@Override
63+
public void onDidDismissInAppMessage(OSInAppMessage message) {
64+
if (wrapperLifeCycleHandler != null)
65+
wrapperLifeCycleHandler.onDidDismissInAppMessage(message);
66+
}
67+
}

com.onesignal.unity.android/Runtime/Plugins/Android/UnityIAMLifecycleHandler.java.meta

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)