File tree Expand file tree Collapse file tree 6 files changed +83
-0
lines changed
core/src/main/java/com/onesignal/user Expand file tree Collapse file tree 6 files changed +83
-0
lines changed Original file line number Diff line number Diff line change @@ -138,4 +138,15 @@ interface IUserManager {
138
138
* Return a copy of all local tags from the current user.
139
139
*/
140
140
fun getTags () : Map <String , String >
141
+
142
+ /* *
143
+ * Add an observer to the user state, allowing the provider to be
144
+ * notified whenever the user state has changed.
145
+ */
146
+ fun addObserver (observer : IUserStateObserver )
147
+
148
+ /* *
149
+ * Remove an observer from the user state.
150
+ */
151
+ fun removeObserver (observer : IUserStateObserver )
141
152
}
Original file line number Diff line number Diff line change
1
+ package com.onesignal.user
2
+
3
+ /* *
4
+ * A user state changed handler. Implement this interface and provide the implementation
5
+ * to be notified when the user has changed.
6
+ */
7
+ interface IUserStateObserver {
8
+ /* *
9
+ * Called when the user state this change handler was added to, has changed. A
10
+ * user state can change when user has logged in or out
11
+ *
12
+ * @param state The user changed state.
13
+ */
14
+ fun onUserStateChange (state : UserChangedState )
15
+ }
Original file line number Diff line number Diff line change
1
+ package com.onesignal.user
2
+
3
+ import org.json.JSONObject
4
+
5
+ class UserChangedState (
6
+ val previous : UserState ,
7
+ val current : UserState ,
8
+ val switchedUsers : Boolean ,
9
+ ) {
10
+ fun toJSONObject (): JSONObject {
11
+ return JSONObject ()
12
+ .put(" previous" , previous.toJSONObject())
13
+ .put(" current" , current.toJSONObject())
14
+ .put(" switchedUsers" , switchedUsers)
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ package com.onesignal.user
2
+
3
+ import org.json.JSONObject
4
+
5
+ /* *
6
+ * A user state.
7
+ */
8
+ class UserState (
9
+ /* *
10
+ * The unique identifier for OneSignal account. This will be a null string until
11
+ * the user has been successfully logged in on the backend and assigned an ID.
12
+ * Use [addObserver] to be notified when the [onesignalId] has been successfully
13
+ * assigned.
14
+ */
15
+ val onesignalId : String? ,
16
+
17
+ /* *
18
+ * The unique external identifier. This will be a null string until the id has
19
+ * been successfully assigned and retrieved from the server.
20
+ * Use [addObserver] to be notified when the [externalId] has been successfully
21
+ * assigned.
22
+ */
23
+ val externalId : String? ,
24
+ ) {
25
+ fun toJSONObject (): JSONObject {
26
+ return JSONObject ()
27
+ .put(" onesignalId" , onesignalId)
28
+ .put(" externalId" , externalId)
29
+ }
30
+ }
Original file line number Diff line number Diff line change 1
1
package com.onesignal.user.internal
2
2
3
3
import com.onesignal.common.OneSignalUtils
4
+ import com.onesignal.common.events.EventProducer
4
5
import com.onesignal.core.internal.language.ILanguageContext
5
6
import com.onesignal.debug.LogLevel
6
7
import com.onesignal.debug.internal.logging.Logging
7
8
import com.onesignal.user.IUserManager
9
+ import com.onesignal.user.IUserStateObserver
8
10
import com.onesignal.user.internal.backend.IdentityConstants
9
11
import com.onesignal.user.internal.identity.IdentityModel
10
12
import com.onesignal.user.internal.identity.IdentityModelStore
@@ -29,6 +31,8 @@ internal open class UserManager(
29
31
val subscriptions: SubscriptionList
30
32
get() = _subscriptionManager .subscriptions
31
33
34
+ val changeHandlersNotifier = EventProducer <IUserStateObserver >()
35
+
32
36
override val pushSubscription: IPushSubscription
33
37
get() = _subscriptionManager .subscriptions.push
34
38
@@ -219,4 +223,8 @@ internal open class UserManager(
219
223
override fun getTags (): Map <String , String > {
220
224
return _propertiesModel .tags.toMap()
221
225
}
226
+
227
+ override fun addObserver (observer : IUserStateObserver ) = changeHandlersNotifier.subscribe(observer)
228
+
229
+ override fun removeObserver (observer : IUserStateObserver ) = changeHandlersNotifier.unsubscribe(observer)
222
230
}
Original file line number Diff line number Diff line change 20
20
void onPushSubscriptionChange(com.onesignal.user.subscriptions.PushSubscriptionChangedState);
21
21
}
22
22
23
+ -keep class ** implements com.onesignal.user.IUserStateObserver {
24
+ void onUserChange(com.onesignal.user.UserChangedState);
25
+ }
23
26
-keep class ** implements com.onesignal.notifications.INotificationServiceExtension{
24
27
void onNotificationReceived(com.onesignal.notifications.INotificationReceivedEvent);
25
28
}
You can’t perform that action at this time.
0 commit comments