-
Notifications
You must be signed in to change notification settings - Fork 371
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 #1909 from OneSignal/AddUserStateChangeObserver
Add getter for onesignalId and UserStateObserver
- Loading branch information
Showing
12 changed files
with
157 additions
and
19 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
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
15 changes: 15 additions & 0 deletions
15
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/state/IUserStateObserver.kt
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,15 @@ | ||
package com.onesignal.user.state | ||
|
||
/** | ||
* A user state changed observer. Implement this interface and provide the implementation | ||
* to be notified when the user state has changed. | ||
*/ | ||
interface IUserStateObserver { | ||
/** | ||
* Called when the user state this change handler was added to, has changed. A | ||
* user state can change when user has logged in or out | ||
* | ||
* @param state The user changed state. | ||
*/ | ||
fun onUserStateChange(state: UserChangedState) | ||
} |
12 changes: 12 additions & 0 deletions
12
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/state/UserChangedState.kt
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,12 @@ | ||
package com.onesignal.user.state | ||
|
||
import org.json.JSONObject | ||
|
||
class UserChangedState( | ||
val current: UserState, | ||
) { | ||
fun toJSONObject(): JSONObject { | ||
return JSONObject() | ||
.put("current", current.toJSONObject()) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/state/UserState.kt
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,27 @@ | ||
package com.onesignal.user.state | ||
|
||
import org.json.JSONObject | ||
|
||
/** | ||
* A user state. | ||
*/ | ||
class UserState( | ||
/** | ||
* The unique identifier for your OneSignal account. This will be an empty string until the | ||
* user has been successfully logged in on the backend and assigned an ID. | ||
* Use [addObserver] to be notified when the [onesignalId] has been successfully assigned. | ||
*/ | ||
val onesignalId: String, | ||
/** | ||
* The external identifier that you use to identify users. Use [addObserver] to be notified | ||
* when the [externalId] has been successfully assigned. This will be an empty string if no | ||
* external identifier has been assigned to the associated [onesignalId]. | ||
*/ | ||
val externalId: String, | ||
) { | ||
fun toJSONObject(): JSONObject { | ||
return JSONObject() | ||
.put("onesignalId", onesignalId) | ||
.put("externalId", externalId) | ||
} | ||
} |
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