react-native-notify-kit 9.1.21 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +6 -2
  2. package/RNNotifee.podspec +1 -0
  3. package/android/build.gradle +67 -35
  4. package/android/proguard-rules.pro +14 -1
  5. package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/1.json +44 -0
  6. package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/2.json +51 -0
  7. package/android/src/androidTest/java/app/notifee/core/ExampleInstrumentedTest.java +25 -0
  8. package/android/src/androidTest/java/app/notifee/core/database/NotifeeCoreDatabaseTest.java +55 -0
  9. package/android/src/main/AndroidManifest.xml +71 -4
  10. package/android/src/main/java/app/notifee/core/AlarmPermissionBroadcastReceiver.java +25 -0
  11. package/android/src/main/java/app/notifee/core/BlockStateBroadcastReceiver.java +164 -0
  12. package/android/src/main/java/app/notifee/core/ChannelManager.java +350 -0
  13. package/android/src/main/java/app/notifee/core/ContextHolder.java +33 -0
  14. package/android/src/main/java/app/notifee/core/EventBus.java +63 -0
  15. package/android/src/main/java/app/notifee/core/EventSubscriber.java +82 -0
  16. package/android/src/main/java/app/notifee/core/ForegroundService.java +347 -0
  17. package/android/src/main/java/app/notifee/core/InitProvider.java +93 -0
  18. package/android/src/main/java/app/notifee/core/KeepForSdk.java +26 -0
  19. package/android/src/main/java/app/notifee/core/Logger.java +68 -0
  20. package/android/src/main/java/app/notifee/core/Notifee.java +570 -0
  21. package/android/src/main/java/app/notifee/core/NotifeeAlarmManager.java +352 -0
  22. package/android/src/main/java/app/notifee/core/NotificationAlarmReceiver.java +42 -0
  23. package/android/src/main/java/app/notifee/core/NotificationManager.java +939 -0
  24. package/android/src/main/java/app/notifee/core/NotificationPendingIntent.java +191 -0
  25. package/android/src/main/java/app/notifee/core/NotificationReceiverActivity.java +39 -0
  26. package/android/src/main/java/app/notifee/core/NotificationReceiverHandler.java +144 -0
  27. package/android/src/main/java/app/notifee/core/Preferences.java +79 -0
  28. package/android/src/main/java/app/notifee/core/RebootBroadcastReceiver.java +39 -0
  29. package/android/src/main/java/app/notifee/core/ReceiverService.java +281 -0
  30. package/android/src/main/java/app/notifee/core/Worker.java +87 -0
  31. package/android/src/main/java/app/notifee/core/database/NotifeeCoreDatabase.java +77 -0
  32. package/android/src/main/java/app/notifee/core/database/WorkDataDao.java +52 -0
  33. package/android/src/main/java/app/notifee/core/database/WorkDataEntity.java +68 -0
  34. package/android/src/main/java/app/notifee/core/database/WorkDataRepository.java +107 -0
  35. package/android/src/main/java/app/notifee/core/event/BlockStateEvent.java +102 -0
  36. package/android/src/main/java/app/notifee/core/event/ForegroundServiceEvent.java +48 -0
  37. package/android/src/main/java/app/notifee/core/event/InitialNotificationEvent.java +50 -0
  38. package/android/src/main/java/app/notifee/core/event/LogEvent.java +74 -0
  39. package/android/src/main/java/app/notifee/core/event/MainComponentEvent.java +33 -0
  40. package/android/src/main/java/app/notifee/core/event/NotificationEvent.java +107 -0
  41. package/android/src/main/java/app/notifee/core/interfaces/EventListener.java +39 -0
  42. package/android/src/main/java/app/notifee/core/interfaces/MethodCallResult.java +27 -0
  43. package/android/src/main/java/app/notifee/core/model/ChannelGroupModel.java +48 -0
  44. package/android/src/main/java/app/notifee/core/model/ChannelModel.java +126 -0
  45. package/android/src/main/java/app/notifee/core/model/IntervalTriggerModel.java +63 -0
  46. package/android/src/main/java/app/notifee/core/model/NotificationAndroidActionModel.java +125 -0
  47. package/android/src/main/java/app/notifee/core/model/NotificationAndroidModel.java +688 -0
  48. package/android/src/main/java/app/notifee/core/model/NotificationAndroidPressActionModel.java +150 -0
  49. package/android/src/main/java/app/notifee/core/model/NotificationAndroidStyleModel.java +336 -0
  50. package/android/src/main/java/app/notifee/core/model/NotificationModel.java +72 -0
  51. package/android/src/main/java/app/notifee/core/model/TimestampTriggerModel.java +206 -0
  52. package/android/src/main/java/app/notifee/core/model/package-info.java +4 -0
  53. package/android/src/main/java/app/notifee/core/utility/AlarmUtils.java +52 -0
  54. package/android/src/main/java/app/notifee/core/utility/Callbackable.java +12 -0
  55. package/android/src/main/java/app/notifee/core/utility/ColorUtils.java +62 -0
  56. package/android/src/main/java/app/notifee/core/utility/ExtendedListenableFuture.java +84 -0
  57. package/android/src/main/java/app/notifee/core/utility/IntentUtils.java +146 -0
  58. package/android/src/main/java/app/notifee/core/utility/ObjectUtils.java +191 -0
  59. package/android/src/main/java/app/notifee/core/utility/PowerManagerUtils.java +338 -0
  60. package/android/src/main/java/app/notifee/core/utility/ResourceUtils.java +308 -0
  61. package/android/src/main/java/app/notifee/core/utility/TextUtils.java +28 -0
  62. package/android/src/main/java/app/notifee/core/utility/package-info.java +4 -0
  63. package/android/src/test/java/app/notifee/core/model/NotificationAndroidPressActionModelTest.java +56 -0
  64. package/android/src/test/java/app/notifee/core/model/TimestampTriggerModelTest.java +44 -0
  65. package/dist/version.d.ts +1 -1
  66. package/dist/version.js +1 -1
  67. package/dist/version.js.map +1 -1
  68. package/package.json +2 -2
  69. package/src/version.ts +1 -1
  70. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar +0 -0
  71. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.md5 +0 -1
  72. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha1 +0 -1
  73. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha256 +0 -1
  74. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha512 +0 -1
  75. package/android/libs/app/notifee/core/202108261754/core-202108261754.module +0 -146
  76. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.md5 +0 -1
  77. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha1 +0 -1
  78. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha256 +0 -1
  79. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha512 +0 -1
  80. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom +0 -64
  81. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.md5 +0 -1
  82. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha1 +0 -1
  83. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha256 +0 -1
  84. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha512 +0 -1
  85. package/android/libs/app/notifee/core/maven-metadata.xml +0 -13
  86. package/android/libs/app/notifee/core/maven-metadata.xml.md5 +0 -1
  87. package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +0 -1
  88. package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +0 -1
  89. package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +0 -1
@@ -0,0 +1,688 @@
1
+ package app.notifee.core.model;
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.app.Notification;
21
+ import android.content.pm.ServiceInfo;
22
+ import android.graphics.Color;
23
+ import android.os.Build;
24
+ import android.os.Bundle;
25
+ import androidx.annotation.Keep;
26
+ import androidx.annotation.NonNull;
27
+ import androidx.annotation.Nullable;
28
+ import androidx.annotation.RequiresApi;
29
+ import androidx.core.app.NotificationCompat;
30
+ import androidx.core.app.NotificationManagerCompat;
31
+ import app.notifee.core.Logger;
32
+ import app.notifee.core.utility.ObjectUtils;
33
+ import app.notifee.core.utility.ResourceUtils;
34
+ import java.util.ArrayList;
35
+ import java.util.Objects;
36
+
37
+ @Keep
38
+ public class NotificationAndroidModel {
39
+ private static final String TAG = "NotificationAndroidModel";
40
+ private Bundle mNotificationAndroidBundle;
41
+
42
+ private NotificationAndroidModel(Bundle bundle) {
43
+ mNotificationAndroidBundle = bundle;
44
+ }
45
+
46
+ public static NotificationAndroidModel fromBundle(Bundle bundle) {
47
+ return new NotificationAndroidModel(bundle);
48
+ }
49
+
50
+ public @Nullable ArrayList<NotificationAndroidActionModel> getActions() {
51
+ if (mNotificationAndroidBundle.containsKey("actions")) {
52
+ ArrayList<Bundle> actionBundles =
53
+ Objects.requireNonNull(mNotificationAndroidBundle.getParcelableArrayList("actions"));
54
+ ArrayList<NotificationAndroidActionModel> actions = new ArrayList<>(actionBundles.size());
55
+
56
+ for (Bundle actionBundle : actionBundles) {
57
+ actions.add(NotificationAndroidActionModel.fromBundle(actionBundle));
58
+ }
59
+
60
+ return actions;
61
+ }
62
+
63
+ return null;
64
+ }
65
+
66
+ @RequiresApi(api = Build.VERSION_CODES.Q)
67
+ public int getForegroundServiceType() {
68
+ if (!mNotificationAndroidBundle.containsKey("foregroundServiceTypes")) {
69
+ // no foreground service types provided, so we default to manifest
70
+ return ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST;
71
+ }
72
+
73
+ ArrayList<?> foregroundServiceTypesArrayList =
74
+ Objects.requireNonNull(
75
+ mNotificationAndroidBundle.getParcelableArrayList("foregroundServiceTypes"));
76
+
77
+ int foregroundServiceType = 0;
78
+ for (int i = 0; i < foregroundServiceTypesArrayList.size(); i++) {
79
+ foregroundServiceType |= ObjectUtils.getInt(foregroundServiceTypesArrayList.get(i));
80
+ }
81
+
82
+ // from Android 14, it is disallowed to use NONE type, so we default to manifest
83
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE
84
+ && foregroundServiceType == ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE) {
85
+ return ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST;
86
+ }
87
+
88
+ return foregroundServiceType;
89
+ }
90
+
91
+ /**
92
+ * Gets whether the notification is for a foreground service
93
+ *
94
+ * @return Boolean
95
+ */
96
+ public Boolean getAsForegroundService() {
97
+ return mNotificationAndroidBundle.getBoolean("asForegroundService", false);
98
+ }
99
+
100
+ /**
101
+ * Gets if the notification should light up the screen when displayed
102
+ *
103
+ * @return Boolean
104
+ */
105
+ public Boolean getLightUpScreen() {
106
+ return mNotificationAndroidBundle.getBoolean("lightUpScreen", false);
107
+ }
108
+
109
+ /**
110
+ * Gets whether the notification can be auto cancelled
111
+ *
112
+ * @return Boolean
113
+ */
114
+ public Boolean getAutoCancel() {
115
+ return mNotificationAndroidBundle.getBoolean("autoCancel", false);
116
+ }
117
+
118
+ /**
119
+ * Gets the badge icon type for the notification
120
+ *
121
+ * @return Integer
122
+ */
123
+ public @Nullable Integer getBadgeIconType() {
124
+ if (mNotificationAndroidBundle.containsKey("badgeIconType")) {
125
+
126
+ return ObjectUtils.getInt(mNotificationAndroidBundle.get("badgeIconType"));
127
+ }
128
+
129
+ return NotificationCompat.BADGE_ICON_LARGE;
130
+ }
131
+
132
+ /**
133
+ * Gets the channel ID for the notification, returns an empty string if none is available
134
+ *
135
+ * @return String
136
+ */
137
+ public @NonNull String getChannelId() {
138
+ if (mNotificationAndroidBundle.containsKey("channelId")) {
139
+ return Objects.requireNonNull(mNotificationAndroidBundle.getString("channelId"));
140
+ }
141
+
142
+ return "";
143
+ }
144
+
145
+ /**
146
+ * Gets the notification category
147
+ *
148
+ * @return String
149
+ */
150
+ public @Nullable String getCategory() {
151
+ return mNotificationAndroidBundle.getString("category");
152
+ }
153
+
154
+ /**
155
+ * Gets the parsed notification color
156
+ *
157
+ * @return Integer
158
+ */
159
+ public @Nullable Integer getColor() {
160
+ if (mNotificationAndroidBundle.containsKey("color")) {
161
+ return Color.parseColor(mNotificationAndroidBundle.getString("color"));
162
+ }
163
+
164
+ return null;
165
+ }
166
+
167
+ /**
168
+ * Gets whether the notification is colorized
169
+ *
170
+ * @return Boolean
171
+ */
172
+ public Boolean getColorized() {
173
+ return mNotificationAndroidBundle.getBoolean("colorized", false);
174
+ }
175
+
176
+ /**
177
+ * Gets whether the notification chronometer should count down
178
+ *
179
+ * @return Boolean
180
+ */
181
+ public Boolean getChronometerCountDown() {
182
+ if (mNotificationAndroidBundle.containsKey("chronometerDirection")) {
183
+ String direction = mNotificationAndroidBundle.getString("chronometerDirection");
184
+ return direction != null && direction.equals("down");
185
+ }
186
+
187
+ return false;
188
+ }
189
+
190
+ /**
191
+ * Gets the notification defaults (for API < 26)
192
+ *
193
+ * @param hasCustomSound A flag to indicate if notificaiton has a custom sound and has successfuly
194
+ * resolved
195
+ * @return Integer
196
+ */
197
+ // Notification.DEFAULT_* constants are deprecated since API 26 in favor of NotificationChannel,
198
+ // but are still needed for pre-channel backward compatibility (minSdk 24).
199
+ @SuppressWarnings("deprecation")
200
+ public Integer getDefaults(Boolean hasCustomSound) {
201
+ String TAG = "NotificationManager";
202
+ Integer defaults = 0;
203
+
204
+ if (mNotificationAndroidBundle.containsKey("defaults")) {
205
+ ArrayList<Integer> defaultsArray = mNotificationAndroidBundle.getIntegerArrayList("defaults");
206
+
207
+ for (Integer integer : Objects.requireNonNull(defaultsArray)) {
208
+ defaults |= integer;
209
+ }
210
+ } else {
211
+ defaults = Notification.DEFAULT_ALL;
212
+ }
213
+
214
+ if (hasCustomSound) {
215
+ defaults &= ~Notification.DEFAULT_SOUND;
216
+ }
217
+
218
+ if (!mNotificationAndroidBundle.containsKey("vibrationPattern")) {
219
+ defaults &= ~Notification.DEFAULT_VIBRATE;
220
+ }
221
+
222
+ if (mNotificationAndroidBundle.containsKey("lights")) {
223
+ defaults &= ~Notification.DEFAULT_LIGHTS;
224
+ }
225
+
226
+ return defaults;
227
+ }
228
+
229
+ /**
230
+ * Gets the notification tag
231
+ *
232
+ * @return String
233
+ */
234
+ public @Nullable String getTag() {
235
+ return mNotificationAndroidBundle.getString("tag");
236
+ }
237
+
238
+ /**
239
+ * Gets the notification group key
240
+ *
241
+ * @return String
242
+ */
243
+ public @Nullable String getGroup() {
244
+ return mNotificationAndroidBundle.getString("groupId");
245
+ }
246
+
247
+ /**
248
+ * Gets the group alert behaviour for a notification
249
+ *
250
+ * @return int
251
+ */
252
+ public int getGroupAlertBehaviour() {
253
+ if (mNotificationAndroidBundle.containsKey("groupAlertBehavior")) {
254
+ return ObjectUtils.getInt(mNotificationAndroidBundle.get("groupAlertBehavior"));
255
+ }
256
+
257
+ return NotificationCompat.GROUP_ALERT_ALL;
258
+ }
259
+
260
+ /**
261
+ * Gets whether the notification is the group summary
262
+ *
263
+ * @return Boolean
264
+ */
265
+ public Boolean getGroupSummary() {
266
+ return mNotificationAndroidBundle.getBoolean("groupSummary", false);
267
+ }
268
+
269
+ /**
270
+ * Gets the input history of the notification
271
+ *
272
+ * @return CharSequence[]
273
+ */
274
+ public @Nullable CharSequence[] getInputHistory() {
275
+ if (mNotificationAndroidBundle.containsKey("inputHistory")) {
276
+ ArrayList<String> inputHistoryArray =
277
+ mNotificationAndroidBundle.getStringArrayList("inputHistory");
278
+ return Objects.requireNonNull(inputHistoryArray)
279
+ .toArray(new CharSequence[inputHistoryArray.size()]);
280
+ }
281
+
282
+ return null;
283
+ }
284
+
285
+ /**
286
+ * Returns true if the notification has a large icon field
287
+ *
288
+ * @return Boolean
289
+ */
290
+ public Boolean hasLargeIcon() {
291
+ return mNotificationAndroidBundle.containsKey("largeIcon");
292
+ }
293
+
294
+ /** Returns the large icon string */
295
+ public String getLargeIcon() {
296
+ if (hasLargeIcon()) {
297
+ return Objects.requireNonNull(mNotificationAndroidBundle.getString("largeIcon"));
298
+ }
299
+
300
+ return null;
301
+ }
302
+
303
+ /** Returns the large icon string */
304
+ public Boolean getCircularLargeIcon() {
305
+ return Objects.requireNonNull(
306
+ mNotificationAndroidBundle.getBoolean("circularLargeIcon", false));
307
+ }
308
+
309
+ /**
310
+ * Gets the light output for the notification
311
+ *
312
+ * @return ArrayList<Integer>
313
+ */
314
+ // Bundle.getParcelableArrayList returns ArrayList<?>, so element casts to String/Integer
315
+ // are inherently unchecked but correct for our serialization format.
316
+ @SuppressWarnings("unchecked")
317
+ public @Nullable ArrayList<Integer> getLights() {
318
+ if (mNotificationAndroidBundle.containsKey("lights")) {
319
+ try {
320
+ ArrayList<?> lightList =
321
+ Objects.requireNonNull(mNotificationAndroidBundle.getParcelableArrayList("lights"));
322
+ String rawColor = (String) lightList.get(0);
323
+
324
+ ArrayList<Integer> lights = new ArrayList<>(3);
325
+ lights.add(Color.parseColor(rawColor));
326
+ lights.add((Integer) lightList.get(1));
327
+ lights.add((Integer) lightList.get(2));
328
+
329
+ return lights;
330
+ } catch (Exception e) {
331
+ Logger.e(TAG, "getLights -> Failed to parse lights");
332
+ return null;
333
+ }
334
+ }
335
+
336
+ return null;
337
+ }
338
+
339
+ /**
340
+ * Gets whether the notification is for local devices only
341
+ *
342
+ * @return Boolean
343
+ */
344
+ public Boolean getLocalOnly() {
345
+ return mNotificationAndroidBundle.getBoolean("localOnly", false);
346
+ }
347
+
348
+ /**
349
+ * Gets a custom set number for the device notification count
350
+ *
351
+ * @return Integer
352
+ */
353
+ public Integer getNumber() {
354
+ if (mNotificationAndroidBundle.containsKey("badgeCount")) {
355
+ return ObjectUtils.getInt(mNotificationAndroidBundle.get("badgeCount"));
356
+ }
357
+
358
+ return null;
359
+ }
360
+
361
+ /**
362
+ * Gets whether this notification is ongoing
363
+ *
364
+ * @return Boolean
365
+ */
366
+ public Boolean getOngoing() {
367
+ return mNotificationAndroidBundle.getBoolean("ongoing", false);
368
+ }
369
+
370
+ /**
371
+ * Gets whether this notification should loop the sound
372
+ *
373
+ * @return Boolean
374
+ */
375
+ public Boolean getLoopSound() {
376
+ return mNotificationAndroidBundle.getBoolean("loopSound", false);
377
+ }
378
+
379
+ /**
380
+ * Gets an array of flags
381
+ *
382
+ * @return int[]
383
+ */
384
+ public int[] getFlags() {
385
+ if (!mNotificationAndroidBundle.containsKey("flags")) {
386
+ return null;
387
+ }
388
+
389
+ ArrayList<?> flagsArrayList =
390
+ Objects.requireNonNull(mNotificationAndroidBundle.getParcelableArrayList("flags"));
391
+
392
+ int[] flagsArray = new int[flagsArrayList.size()];
393
+
394
+ for (int i = 0; i < flagsArrayList.size(); i++) {
395
+ flagsArray[i] = ObjectUtils.getInt(flagsArrayList.get(i));
396
+ }
397
+
398
+ return flagsArray;
399
+ }
400
+
401
+ /**
402
+ * Gets whether this notification should only alert once if updated
403
+ *
404
+ * @return Boolean
405
+ */
406
+ public Boolean getOnlyAlertOnce() {
407
+ return mNotificationAndroidBundle.getBoolean("onlyAlertOnce", false);
408
+ }
409
+
410
+ /**
411
+ * Returns true if the notification has a fullScreenAction
412
+ *
413
+ * @return Boolean
414
+ */
415
+ public Boolean hasFullScreenAction() {
416
+ return mNotificationAndroidBundle.containsKey("fullScreenAction");
417
+ }
418
+
419
+ /**
420
+ * Gets an pressAction bundle for the notification
421
+ *
422
+ * @return Bundle or null
423
+ */
424
+ public @Nullable Bundle getPressAction() {
425
+ return mNotificationAndroidBundle.getBundle("pressAction");
426
+ }
427
+
428
+ /**
429
+ * Returns a notification full screen action
430
+ *
431
+ * @return NotificationAndroidFullScreenActionModel
432
+ */
433
+ public @Nullable NotificationAndroidPressActionModel getFullScreenAction() {
434
+ if (!hasFullScreenAction()) {
435
+ return null;
436
+ }
437
+
438
+ return NotificationAndroidPressActionModel.fromBundle(
439
+ mNotificationAndroidBundle.getBundle("fullScreenAction"));
440
+ }
441
+
442
+ /**
443
+ * JS uses the same API as importance for priority so we dont confuse users. This maps importance
444
+ * to a priority flag.
445
+ *
446
+ * @return int
447
+ */
448
+ // NotificationCompat.PRIORITY_* constants are deprecated since API 26 in favor of
449
+ // NotificationChannel importance, but are still needed for pre-channel backward compatibility.
450
+ @SuppressWarnings("deprecation")
451
+ public int getPriority() {
452
+ if (!mNotificationAndroidBundle.containsKey("importance")) {
453
+ return NotificationCompat.PRIORITY_DEFAULT;
454
+ }
455
+
456
+ int importance = ObjectUtils.getInt(mNotificationAndroidBundle.get("importance"));
457
+ switch (importance) {
458
+ case NotificationManagerCompat.IMPORTANCE_HIGH:
459
+ return NotificationCompat.PRIORITY_HIGH;
460
+ case NotificationManagerCompat.IMPORTANCE_MIN:
461
+ return NotificationCompat.PRIORITY_LOW;
462
+ case NotificationManagerCompat.IMPORTANCE_NONE:
463
+ return NotificationCompat.PRIORITY_MIN;
464
+ case NotificationManagerCompat.IMPORTANCE_DEFAULT:
465
+ default:
466
+ return NotificationCompat.PRIORITY_DEFAULT;
467
+ }
468
+ }
469
+
470
+ /**
471
+ * Gets a AndroidProgress class for the current notification
472
+ *
473
+ * @return AndroidProgress
474
+ */
475
+ public @Nullable AndroidProgress getProgress() {
476
+ if (mNotificationAndroidBundle.containsKey("progress")) {
477
+ Bundle progressBundle =
478
+ Objects.requireNonNull(mNotificationAndroidBundle.getBundle("progress"));
479
+
480
+ return new AndroidProgress(
481
+ ObjectUtils.getInt(progressBundle.get("max")),
482
+ ObjectUtils.getInt(progressBundle.get("current")),
483
+ progressBundle.getBoolean("indeterminate", false));
484
+ }
485
+
486
+ return null;
487
+ }
488
+
489
+ /**
490
+ * Gets the shortcut ID for the notification
491
+ *
492
+ * @return String
493
+ */
494
+ public @Nullable String getShortcutId() {
495
+ return mNotificationAndroidBundle.getString("shortcutId");
496
+ }
497
+
498
+ /**
499
+ * Gets whether this notification should show the timestamp
500
+ *
501
+ * @return Boolean
502
+ */
503
+ public Boolean getShowTimestamp() {
504
+ return mNotificationAndroidBundle.getBoolean("showTimestamp", false);
505
+ }
506
+
507
+ /**
508
+ * Gets the small icon resource id from its string name, or null if the icon is missing from the
509
+ * device.
510
+ */
511
+ public @Nullable Integer getSmallIcon() {
512
+ if (!mNotificationAndroidBundle.containsKey("smallIcon")) {
513
+ return null;
514
+ }
515
+
516
+ String rawIcon = mNotificationAndroidBundle.getString("smallIcon");
517
+ int smallIconId = ResourceUtils.getImageResourceId(rawIcon);
518
+
519
+ if (smallIconId == 0) {
520
+ Logger.d(
521
+ "NotificationAndroidModel",
522
+ String.format("Notification small icon '%s' could not be found", rawIcon));
523
+ return null;
524
+ }
525
+
526
+ return smallIconId;
527
+ }
528
+
529
+ /**
530
+ * Gets the small icon & it's level, or null if the icon is missing from the device.
531
+ *
532
+ * @return ArrayList<Integer>
533
+ */
534
+ public @Nullable Integer getSmallIconLevel() {
535
+ if (!mNotificationAndroidBundle.containsKey("smallIconLevel")) {
536
+ return null;
537
+ }
538
+
539
+ return mNotificationAndroidBundle.getInt("smallIconLevel");
540
+ }
541
+
542
+ /**
543
+ * Gets the sort key
544
+ *
545
+ * @return String
546
+ */
547
+ public @Nullable String getSortKey() {
548
+ return mNotificationAndroidBundle.getString("sortKey");
549
+ }
550
+
551
+ /**
552
+ * Returns whether the notification has any styles
553
+ *
554
+ * @return Boolean
555
+ */
556
+ public Boolean hasStyle() {
557
+ return mNotificationAndroidBundle.containsKey("style");
558
+ }
559
+
560
+ /**
561
+ * Returns a task containing a notification style
562
+ *
563
+ * @return ListenableFuture<NotificationCompat.Style>
564
+ */
565
+ public @Nullable NotificationAndroidStyleModel getStyle() {
566
+ if (!hasStyle()) {
567
+ return null;
568
+ }
569
+
570
+ return NotificationAndroidStyleModel.fromBundle(mNotificationAndroidBundle.getBundle("style"));
571
+ }
572
+
573
+ /**
574
+ * Gets the ticker text
575
+ *
576
+ * @return String
577
+ */
578
+ public @Nullable String getTicker() {
579
+ return mNotificationAndroidBundle.getString("ticker");
580
+ }
581
+
582
+ /**
583
+ * Gets the timeout after ms, -1 if none exists
584
+ *
585
+ * @return long
586
+ */
587
+ public @Nullable Long getTimeoutAfter() {
588
+ if (mNotificationAndroidBundle.containsKey("timeoutAfter")) {
589
+ return ObjectUtils.getLong(mNotificationAndroidBundle.get("timeoutAfter"));
590
+ }
591
+
592
+ return null;
593
+ }
594
+
595
+ /**
596
+ * Gets whether the chronometer should be shown
597
+ *
598
+ * @return Boolean
599
+ */
600
+ public Boolean getShowChronometer() {
601
+ return mNotificationAndroidBundle.getBoolean("showChronometer", false);
602
+ }
603
+
604
+ public @Nullable String getSound() {
605
+ if (!mNotificationAndroidBundle.containsKey("sound")) {
606
+ return null;
607
+ }
608
+
609
+ return mNotificationAndroidBundle.getString("sound");
610
+ }
611
+
612
+ /**
613
+ * Gets an array vibration pattern for the notification, or empty if not provided
614
+ *
615
+ * @return long[]
616
+ */
617
+ // Bundle.getParcelableArrayList returns ArrayList<?>, so the (Integer) cast is inherently
618
+ // unchecked but correct for our serialization format.
619
+ @SuppressWarnings("unchecked")
620
+ public long[] getVibrationPattern() {
621
+ if (!mNotificationAndroidBundle.containsKey("vibrationPattern")) {
622
+ return new long[0];
623
+ }
624
+
625
+ ArrayList<?> vibrationPattern =
626
+ Objects.requireNonNull(
627
+ mNotificationAndroidBundle.getParcelableArrayList("vibrationPattern"));
628
+
629
+ long[] vibrateArray = new long[vibrationPattern.size()];
630
+
631
+ for (int i = 0; i < vibrationPattern.size(); i++) {
632
+ Integer value = (Integer) vibrationPattern.get(i);
633
+ vibrateArray[i] = value.longValue();
634
+ }
635
+
636
+ return vibrateArray;
637
+ }
638
+
639
+ /**
640
+ * Gets the notification visibility
641
+ *
642
+ * @return int
643
+ */
644
+ public int getVisibility() {
645
+ if (mNotificationAndroidBundle.containsKey("visibility")) {
646
+ return ObjectUtils.getInt(mNotificationAndroidBundle.get("visibility"));
647
+ }
648
+
649
+ return NotificationCompat.VISIBILITY_PRIVATE;
650
+ }
651
+
652
+ /**
653
+ * Gets the notification timestamp, or -1 if not provided
654
+ *
655
+ * @return long
656
+ */
657
+ public long getTimestamp() {
658
+ if (mNotificationAndroidBundle.containsKey("timestamp")) {
659
+ return ObjectUtils.getLong(mNotificationAndroidBundle.get("timestamp"));
660
+ }
661
+
662
+ return -1;
663
+ }
664
+
665
+ public static class AndroidProgress {
666
+ int max;
667
+ int current;
668
+ boolean indeterminate;
669
+
670
+ AndroidProgress(int max, int current, boolean indeterminate) {
671
+ this.max = max;
672
+ this.current = current;
673
+ this.indeterminate = indeterminate;
674
+ }
675
+
676
+ public int getMax() {
677
+ return max;
678
+ }
679
+
680
+ public int getCurrent() {
681
+ return current;
682
+ }
683
+
684
+ public boolean getIndeterminate() {
685
+ return indeterminate;
686
+ }
687
+ }
688
+ }