1
1
package cn .jpush .api .push .model .live_activity ;
2
2
3
3
import cn .jpush .api .push .model .PushModel ;
4
- import com .google .gson .JsonArray ;
5
- import com .google .gson .JsonElement ;
6
- import com .google .gson .JsonObject ;
7
- import com .google .gson .JsonPrimitive ;
4
+ import com .google .gson .*;
8
5
9
6
public class LiveActivity implements PushModel {
10
7
@@ -15,13 +12,15 @@ public class LiveActivity implements PushModel {
15
12
private final String iOSEvent ;
16
13
private final JsonObject iOSContentState ;
17
14
private final Long iOSDismissalDate ;
15
+ private final JsonObject iOSAlert ;
18
16
19
- public LiveActivity (Boolean apnsProduction , String liveActivityId , String iOSEvent , JsonObject iOSContentState , Long iOSDismissalDate ) {
17
+ public LiveActivity (Boolean apnsProduction , String liveActivityId , String iOSEvent , JsonObject iOSContentState , Long iOSDismissalDate , JsonObject iOSAlert ) {
20
18
this .apnsProduction = apnsProduction ;
21
19
this .liveActivityId = liveActivityId ;
22
20
this .iOSEvent = iOSEvent ;
23
21
this .iOSContentState = iOSContentState ;
24
22
this .iOSDismissalDate = iOSDismissalDate ;
23
+ this .iOSAlert = iOSAlert ;
25
24
}
26
25
27
26
public static Builder newBuilder () {
@@ -34,6 +33,7 @@ public static class Builder {
34
33
private String iOSEvent ;
35
34
private JsonObject iOSContentState ;
36
35
private Long iOSDismissalDate ;
36
+ private JsonObject iOSAlert ;
37
37
38
38
public Builder apnsProduction (Boolean apnsProduction ) {
39
39
this .apnsProduction = apnsProduction ;
@@ -81,15 +81,55 @@ public Builder iOSDismissalDate(Long iOSDismissalDate) {
81
81
return this ;
82
82
}
83
83
84
+ public Builder iOSAlertTitle (String iosAlertTitle ) {
85
+ if (this .iOSAlert == null ) {
86
+ this .iOSAlert = new JsonObject ();
87
+ }
88
+ this .iOSAlert .addProperty ("title" , iosAlertTitle );
89
+ return this ;
90
+ }
91
+
92
+ public Builder iOSAlertAlternateTitle (String iosAlertAlternateTitle ) {
93
+ if (this .iOSAlert == null ) {
94
+ this .iOSAlert = new JsonObject ();
95
+ }
96
+ this .iOSAlert .addProperty ("alternate_title" , iosAlertAlternateTitle );
97
+ return this ;
98
+ }
99
+
100
+ public Builder iOSAlertBody (String iosAlertBody ) {
101
+ if (this .iOSAlert == null ) {
102
+ this .iOSAlert = new JsonObject ();
103
+ }
104
+ this .iOSAlert .addProperty ("body" , iosAlertBody );
105
+ return this ;
106
+ }
107
+
108
+ public Builder iOSAlertAlternateBody (String iosAlertAlternateBody ) {
109
+ if (this .iOSAlert == null ) {
110
+ this .iOSAlert = new JsonObject ();
111
+ }
112
+ this .iOSAlert .addProperty ("alternate_body" , iosAlertAlternateBody );
113
+ return this ;
114
+ }
115
+
116
+ public Builder iOSAlertSound (String iosAlertSound ) {
117
+ if (this .iOSAlert == null ) {
118
+ this .iOSAlert = new JsonObject ();
119
+ }
120
+ this .iOSAlert .addProperty ("sound" , iosAlertSound );
121
+ return this ;
122
+ }
123
+
84
124
public LiveActivity build () {
85
- return new LiveActivity (apnsProduction , liveActivityId , iOSEvent , iOSContentState , iOSDismissalDate );
125
+ return new LiveActivity (apnsProduction , liveActivityId , iOSEvent , iOSContentState , iOSDismissalDate , iOSAlert );
86
126
}
87
127
88
128
}
89
129
90
130
@ Override
91
131
public JsonElement toJSON () {
92
- JsonObject jsonObject = new JsonObject ();
132
+ JsonObject pushJsonObject = new JsonObject ();
93
133
94
134
JsonArray platformJsonArray = new JsonArray ();
95
135
platformJsonArray .add (new JsonPrimitive ("ios" ));
@@ -99,37 +139,42 @@ public JsonElement toJSON() {
99
139
audienceJsonObject .addProperty ("live_activity_id" , liveActivityId );
100
140
}
101
141
102
- JsonObject optionsJsonObject = new JsonObject ();
103
- if (apnsProduction != null ) {
104
- optionsJsonObject .addProperty ("apns_production" , apnsProduction );
105
- }
106
-
107
142
JsonObject liveActivityJsonObject = new JsonObject ();
108
143
JsonObject iOSJsonObject = new JsonObject ();
109
- JsonObject alertJsonObject = new JsonObject ();
110
144
111
145
if (iOSEvent != null ) {
112
146
iOSJsonObject .addProperty ("event" , iOSEvent );
113
147
}
148
+
114
149
if (iOSContentState != null ) {
115
150
iOSJsonObject .add ("content-state" , iOSContentState );
116
151
}
117
- if (!alertJsonObject .entrySet ().isEmpty ()) {
118
- iOSJsonObject .add ("alert" , alertJsonObject );
119
- }
120
- if (!alertJsonObject .entrySet ().isEmpty ()) {
152
+
153
+ if (iOSDismissalDate != null ) {
121
154
iOSJsonObject .addProperty ("dismissal-date" , iOSDismissalDate );
122
155
}
123
156
157
+ if (iOSAlert != null ) {
158
+ iOSJsonObject .add ("alert" , iOSAlert );
159
+ }
160
+
124
161
if (!iOSJsonObject .entrySet ().isEmpty ()) {
125
162
liveActivityJsonObject .add ("ios" , iOSJsonObject );
126
163
}
127
164
128
- jsonObject .add ("platform" , platformJsonArray );
129
- jsonObject .add ("audience" , audienceJsonObject );
130
- jsonObject .add ("live_activity" , liveActivityJsonObject );
131
- jsonObject .add ("options" , optionsJsonObject );
132
- return jsonObject ;
165
+ JsonObject optionsJsonObject = new JsonObject ();
166
+ if (apnsProduction != null ) {
167
+ optionsJsonObject .addProperty ("apns_production" , apnsProduction );
168
+ }
169
+ if (iOSAlert != null ) {
170
+ optionsJsonObject .addProperty ("alternate_set" , true );
171
+ }
172
+
173
+ pushJsonObject .add ("platform" , platformJsonArray );
174
+ pushJsonObject .add ("audience" , audienceJsonObject );
175
+ pushJsonObject .add ("live_activity" , liveActivityJsonObject );
176
+ pushJsonObject .add ("options" , optionsJsonObject );
177
+ return pushJsonObject ;
133
178
}
134
179
135
180
}
0 commit comments