30
30
import org .json .JSONArray ;
31
31
import org .json .JSONObject ;
32
32
33
+ import java .util .ArrayList ;
33
34
import java .util .List ;
34
35
35
36
// Notification properties received from OneSignal.
@@ -54,11 +55,52 @@ public class OSNotificationPayload {
54
55
public int priority ;
55
56
public String rawPayload ;
56
57
58
+ public OSNotificationPayload () {
59
+ }
60
+
61
+ public OSNotificationPayload (JSONObject jsonObject ) {
62
+ notificationID = jsonObject .optString ("notificationID" );
63
+ title = jsonObject .optString ("title" );
64
+
65
+ body = jsonObject .optString ("body" );
66
+ additionalData = jsonObject .optJSONObject ("additionalData" );
67
+ smallIcon = jsonObject .optString ("smallIcon" );
68
+ largeIcon = jsonObject .optString ("largeIcon" );
69
+ bigPicture = jsonObject .optString ("bigPicture" );
70
+ smallIconAccentColor = jsonObject .optString ("smallIconAccentColor" );
71
+ launchURL = jsonObject .optString ("launchURL" );
72
+ sound = jsonObject .optString ("sound" );
73
+ ledColor = jsonObject .optString ("ledColor" );
74
+ lockScreenVisibility = jsonObject .optInt ("lockScreenVisibility" );
75
+ groupKey = jsonObject .optString ("groupKey" );
76
+ groupMessage = jsonObject .optString ("groupMessage" );
77
+
78
+ if (jsonObject .has ("actionButtons" )) {
79
+ actionButtons = new ArrayList <>();
80
+ JSONArray jsonArray = jsonObject .optJSONArray ("actionButtons" );
81
+ for (int i = 0 ; i < jsonArray .length (); i ++)
82
+ actionButtons .add (new ActionButton (jsonArray .optJSONObject (i )));
83
+ }
84
+
85
+ fromProjectNumber = jsonObject .optString ("fromProjectNumber" );
86
+ collapseId = jsonObject .optString ("collapseId" );
87
+ priority = jsonObject .optInt ("priority" );
88
+ rawPayload = jsonObject .optString ("rawPayload" );
89
+ }
90
+
57
91
public static class ActionButton {
58
92
public String id ;
59
93
public String text ;
60
94
public String icon ;
61
-
95
+
96
+ public ActionButton () {}
97
+
98
+ public ActionButton (JSONObject jsonObject ) {
99
+ id = jsonObject .optString ("id" );
100
+ text = jsonObject .optString ("text" );
101
+ icon = jsonObject .optString ("icon" );
102
+ }
103
+
62
104
public JSONObject toJSONObject () {
63
105
JSONObject json = new JSONObject ();
64
106
try {
0 commit comments