@ammarahmed/notifee-react-native 7.3.1 → 7.4.2
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.
- package/android/build.gradle +36 -18
- package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/1.json +46 -0
- package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/2.json +53 -0
- package/android/src/main/java/app/notifee/core/AlarmPermissionBroadcastReceiver.java +19 -0
- package/android/src/main/java/app/notifee/core/BlockStateBroadcastReceiver.java +164 -0
- package/android/src/main/java/app/notifee/core/ChannelManager.java +351 -0
- package/android/src/main/java/app/notifee/core/ContextHolder.java +33 -0
- package/android/src/main/java/app/notifee/core/EventBus.java +63 -0
- package/android/src/main/java/app/notifee/core/EventSubscriber.java +82 -0
- package/android/src/main/java/app/notifee/core/ForegroundService.java +125 -0
- package/android/src/main/java/app/notifee/core/InitProvider.java +92 -0
- package/android/src/main/java/app/notifee/core/KeepForSdk.java +26 -0
- package/android/src/main/java/app/notifee/core/Logger.java +68 -0
- package/android/src/main/java/app/notifee/core/Notifee.java +533 -0
- package/android/src/main/java/app/notifee/core/NotifeeAlarmManager.java +256 -0
- package/android/src/main/java/app/notifee/core/NotificationAlarmReceiver.java +32 -0
- package/android/src/main/java/app/notifee/core/NotificationManager.java +903 -0
- package/android/src/main/java/app/notifee/core/NotificationPendingIntent.java +189 -0
- package/android/src/main/java/app/notifee/core/NotificationReceiverActivity.java +38 -0
- package/android/src/main/java/app/notifee/core/NotificationReceiverHandler.java +140 -0
- package/android/src/main/java/app/notifee/core/Preferences.java +79 -0
- package/android/src/main/java/app/notifee/core/RebootBroadcastReceiver.java +38 -0
- package/android/src/main/java/app/notifee/core/ReceiverService.java +268 -0
- package/android/src/main/java/app/notifee/core/Worker.java +87 -0
- package/android/src/main/java/app/notifee/core/database/NotifeeCoreDatabase.java +76 -0
- package/android/src/main/java/app/notifee/core/database/WorkDataDao.java +52 -0
- package/android/src/main/java/app/notifee/core/database/WorkDataEntity.java +68 -0
- package/android/src/main/java/app/notifee/core/database/WorkDataRepository.java +107 -0
- package/android/src/main/java/app/notifee/core/event/BlockStateEvent.java +102 -0
- package/android/src/main/java/app/notifee/core/event/ForegroundServiceEvent.java +48 -0
- package/android/src/main/java/app/notifee/core/event/InitialNotificationEvent.java +50 -0
- package/android/src/main/java/app/notifee/core/event/LogEvent.java +74 -0
- package/android/src/main/java/app/notifee/core/event/MainComponentEvent.java +33 -0
- package/android/src/main/java/app/notifee/core/event/NotificationEvent.java +97 -0
- package/android/src/main/java/app/notifee/core/interfaces/EventListener.java +39 -0
- package/android/src/main/java/app/notifee/core/interfaces/MethodCallResult.java +27 -0
- package/android/src/main/java/app/notifee/core/model/ChannelGroupModel.java +48 -0
- package/android/src/main/java/app/notifee/core/model/ChannelModel.java +123 -0
- package/android/src/main/java/app/notifee/core/model/IntervalTriggerModel.java +63 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidActionModel.java +125 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidModel.java +654 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidPressActionModel.java +146 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidStyleModel.java +341 -0
- package/android/src/main/java/app/notifee/core/model/NotificationModel.java +72 -0
- package/android/src/main/java/app/notifee/core/model/TimestampTriggerModel.java +163 -0
- package/android/src/main/java/app/notifee/core/model/package-info.java +4 -0
- package/android/src/main/java/app/notifee/core/utility/AlarmUtils.java +52 -0
- package/android/src/main/java/app/notifee/core/utility/Callbackable.java +12 -0
- package/android/src/main/java/app/notifee/core/utility/ColorUtils.java +62 -0
- package/android/src/main/java/app/notifee/core/utility/ExtendedListenableFuture.java +84 -0
- package/android/src/main/java/app/notifee/core/utility/IntentUtils.java +136 -0
- package/android/src/main/java/app/notifee/core/utility/ObjectUtils.java +187 -0
- package/android/src/main/java/app/notifee/core/utility/PowerManagerUtils.java +334 -0
- package/android/src/main/java/app/notifee/core/utility/ResourceUtils.java +309 -0
- package/android/src/main/java/app/notifee/core/utility/TextUtils.java +28 -0
- package/android/src/main/java/app/notifee/core/utility/package-info.java +4 -0
- package/dist/types/Notification.d.ts +8 -1
- package/dist/types/Notification.js +6 -0
- package/dist/types/Notification.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/jest-mock.js +7 -4
- package/package.json +1 -3
- package/src/types/Notification.ts +8 -0
- package/src/version.ts +1 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +0 -9
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml +0 -13
- package/android/libs/app/notifee/core/maven-metadata.xml.md5 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
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.content.Intent;
|
|
21
|
+
import android.os.Build;
|
|
22
|
+
import android.os.Bundle;
|
|
23
|
+
import androidx.annotation.Keep;
|
|
24
|
+
import androidx.annotation.NonNull;
|
|
25
|
+
import androidx.annotation.Nullable;
|
|
26
|
+
import java.util.ArrayList;
|
|
27
|
+
import java.util.Objects;
|
|
28
|
+
|
|
29
|
+
@Keep
|
|
30
|
+
public class NotificationAndroidPressActionModel {
|
|
31
|
+
|
|
32
|
+
private Bundle mNotificationAndroidPressActionBundle;
|
|
33
|
+
|
|
34
|
+
private NotificationAndroidPressActionModel(Bundle pressActionBundle) {
|
|
35
|
+
mNotificationAndroidPressActionBundle = pressActionBundle;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public static NotificationAndroidPressActionModel fromBundle(Bundle pressActionBundle) {
|
|
39
|
+
return new NotificationAndroidPressActionModel(pressActionBundle);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public Bundle toBundle() {
|
|
43
|
+
return (Bundle) mNotificationAndroidPressActionBundle.clone();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public @NonNull String getId() {
|
|
47
|
+
return Objects.requireNonNull(mNotificationAndroidPressActionBundle.getString("id"));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public @Nullable String getLaunchActivity() {
|
|
51
|
+
return mNotificationAndroidPressActionBundle.getString("launchActivity");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public int getLaunchActivityFlags() {
|
|
55
|
+
if (!mNotificationAndroidPressActionBundle.containsKey("launchActivityFlags")) {
|
|
56
|
+
return -1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
int baseFlags = 0;
|
|
60
|
+
ArrayList<Integer> launchActivityFlags =
|
|
61
|
+
Objects.requireNonNull(
|
|
62
|
+
mNotificationAndroidPressActionBundle.getIntegerArrayList("launchActivityFlags"));
|
|
63
|
+
|
|
64
|
+
for (int i = 0; i < launchActivityFlags.size(); i++) {
|
|
65
|
+
Integer flag = launchActivityFlags.get(i);
|
|
66
|
+
switch (flag) {
|
|
67
|
+
case 0:
|
|
68
|
+
baseFlags |= Intent.FLAG_ACTIVITY_NO_HISTORY;
|
|
69
|
+
break;
|
|
70
|
+
case 1:
|
|
71
|
+
baseFlags |= Intent.FLAG_ACTIVITY_SINGLE_TOP;
|
|
72
|
+
break;
|
|
73
|
+
case 2:
|
|
74
|
+
baseFlags |= Intent.FLAG_ACTIVITY_NEW_TASK;
|
|
75
|
+
break;
|
|
76
|
+
case 3:
|
|
77
|
+
baseFlags |= Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
|
|
78
|
+
break;
|
|
79
|
+
case 4:
|
|
80
|
+
baseFlags |= Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
|
81
|
+
break;
|
|
82
|
+
case 5:
|
|
83
|
+
baseFlags |= Intent.FLAG_ACTIVITY_FORWARD_RESULT;
|
|
84
|
+
break;
|
|
85
|
+
case 6:
|
|
86
|
+
baseFlags |= Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP;
|
|
87
|
+
break;
|
|
88
|
+
case 7:
|
|
89
|
+
baseFlags |= Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
|
|
90
|
+
break;
|
|
91
|
+
case 8:
|
|
92
|
+
baseFlags |= Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT;
|
|
93
|
+
break;
|
|
94
|
+
case 9:
|
|
95
|
+
baseFlags |= Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED;
|
|
96
|
+
break;
|
|
97
|
+
case 10:
|
|
98
|
+
baseFlags |= Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY;
|
|
99
|
+
break;
|
|
100
|
+
case 11:
|
|
101
|
+
baseFlags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
|
|
102
|
+
break;
|
|
103
|
+
case 12:
|
|
104
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
105
|
+
baseFlags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case 13:
|
|
109
|
+
baseFlags |= Intent.FLAG_ACTIVITY_NO_USER_ACTION;
|
|
110
|
+
break;
|
|
111
|
+
case 14:
|
|
112
|
+
baseFlags |= Intent.FLAG_ACTIVITY_REORDER_TO_FRONT;
|
|
113
|
+
break;
|
|
114
|
+
case 15:
|
|
115
|
+
baseFlags |= Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
|
116
|
+
break;
|
|
117
|
+
case 16:
|
|
118
|
+
baseFlags |= Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
|
119
|
+
break;
|
|
120
|
+
case 17:
|
|
121
|
+
baseFlags |= Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
|
122
|
+
break;
|
|
123
|
+
case 18:
|
|
124
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
125
|
+
baseFlags |= Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case 19:
|
|
129
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
130
|
+
baseFlags |= Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT;
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case 20:
|
|
134
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
135
|
+
baseFlags |= Intent.FLAG_ACTIVITY_MATCH_EXTERNAL;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return baseFlags;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public @Nullable String getMainComponent() {
|
|
144
|
+
return mNotificationAndroidPressActionBundle.getString("mainComponent");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
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.graphics.Bitmap;
|
|
21
|
+
import android.os.Bundle;
|
|
22
|
+
import androidx.annotation.Keep;
|
|
23
|
+
import androidx.annotation.Nullable;
|
|
24
|
+
import androidx.core.app.NotificationCompat;
|
|
25
|
+
import androidx.core.app.Person;
|
|
26
|
+
import androidx.core.graphics.drawable.IconCompat;
|
|
27
|
+
import app.notifee.core.Logger;
|
|
28
|
+
import app.notifee.core.utility.ObjectUtils;
|
|
29
|
+
import app.notifee.core.utility.ResourceUtils;
|
|
30
|
+
import app.notifee.core.utility.TextUtils;
|
|
31
|
+
import com.google.common.util.concurrent.Futures;
|
|
32
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
33
|
+
import com.google.common.util.concurrent.ListeningExecutorService;
|
|
34
|
+
import com.google.common.util.concurrent.SettableFuture;
|
|
35
|
+
import java.util.ArrayList;
|
|
36
|
+
import java.util.Objects;
|
|
37
|
+
import java.util.concurrent.TimeUnit;
|
|
38
|
+
import java.util.concurrent.TimeoutException;
|
|
39
|
+
|
|
40
|
+
@Keep
|
|
41
|
+
public class NotificationAndroidStyleModel {
|
|
42
|
+
private static final String TAG = "NotificationAndroidStyle";
|
|
43
|
+
private Bundle mNotificationAndroidStyleBundle;
|
|
44
|
+
|
|
45
|
+
private NotificationAndroidStyleModel(Bundle styleBundle) {
|
|
46
|
+
mNotificationAndroidStyleBundle = styleBundle;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public static NotificationAndroidStyleModel fromBundle(Bundle styleBundle) {
|
|
50
|
+
return new NotificationAndroidStyleModel(styleBundle);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Converts a person bundle from JS into a Person
|
|
55
|
+
*
|
|
56
|
+
* @param personBundle
|
|
57
|
+
* @return
|
|
58
|
+
*/
|
|
59
|
+
private static ListenableFuture<Person> getPerson(
|
|
60
|
+
ListeningExecutorService lExecutor, Bundle personBundle) {
|
|
61
|
+
return lExecutor.submit(
|
|
62
|
+
() -> {
|
|
63
|
+
Person.Builder personBuilder = new Person.Builder();
|
|
64
|
+
|
|
65
|
+
personBuilder.setName(personBundle.getString("name"));
|
|
66
|
+
|
|
67
|
+
if (personBundle.containsKey("id")) {
|
|
68
|
+
personBuilder.setKey(personBundle.getString("id"));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (personBundle.containsKey("bot")) {
|
|
72
|
+
personBuilder.setBot(personBundle.getBoolean("bot"));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (personBundle.containsKey("important")) {
|
|
76
|
+
personBuilder.setImportant(personBundle.getBoolean("important"));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (personBundle.containsKey("icon")) {
|
|
80
|
+
String personIcon = Objects.requireNonNull(personBundle.getString("icon"));
|
|
81
|
+
Bitmap personIconBitmap = null;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
personIconBitmap =
|
|
85
|
+
ResourceUtils.getImageBitmapFromUrl(personIcon)
|
|
86
|
+
.get(10, TimeUnit.SECONDS);
|
|
87
|
+
} catch (TimeoutException e) {
|
|
88
|
+
Logger.e(
|
|
89
|
+
TAG,
|
|
90
|
+
"Timeout occurred whilst trying to retrieve a person icon: " + personIcon,
|
|
91
|
+
e);
|
|
92
|
+
} catch (Exception e) {
|
|
93
|
+
Logger.e(
|
|
94
|
+
TAG,
|
|
95
|
+
"An error occurred whilst trying to retrieve a person icon: " + personIcon,
|
|
96
|
+
e);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (personIconBitmap != null) {
|
|
100
|
+
personBuilder.setIcon(IconCompat.createWithAdaptiveBitmap(personIconBitmap));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (personBundle.containsKey("uri")) {
|
|
105
|
+
personBuilder.setUri(personBundle.getString("uri"));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return personBuilder.build();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public Bundle toBundle() {
|
|
113
|
+
return (Bundle) mNotificationAndroidStyleBundle.clone();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Nullable
|
|
117
|
+
public ListenableFuture<NotificationCompat.Style> getStyleTask(
|
|
118
|
+
ListeningExecutorService lExecutor) {
|
|
119
|
+
int type = ObjectUtils.getInt(mNotificationAndroidStyleBundle.get("type"));
|
|
120
|
+
ListenableFuture<NotificationCompat.Style> styleTask = null;
|
|
121
|
+
|
|
122
|
+
switch (type) {
|
|
123
|
+
case 0:
|
|
124
|
+
styleTask = getBigPictureStyleTask(lExecutor);
|
|
125
|
+
break;
|
|
126
|
+
case 1:
|
|
127
|
+
styleTask = Futures.immediateFuture(getBigTextStyle());
|
|
128
|
+
break;
|
|
129
|
+
case 2:
|
|
130
|
+
styleTask = Futures.immediateFuture(getInboxStyle());
|
|
131
|
+
break;
|
|
132
|
+
case 3:
|
|
133
|
+
styleTask = getMessagingStyleTask(lExecutor);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return styleTask;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Gets a BigPictureStyle for a notification
|
|
142
|
+
*
|
|
143
|
+
* @return
|
|
144
|
+
*/
|
|
145
|
+
private ListenableFuture<NotificationCompat.Style> getBigPictureStyleTask(
|
|
146
|
+
ListeningExecutorService lExecutor) {
|
|
147
|
+
return lExecutor.submit(
|
|
148
|
+
() -> {
|
|
149
|
+
NotificationCompat.BigPictureStyle bigPictureStyle =
|
|
150
|
+
new NotificationCompat.BigPictureStyle();
|
|
151
|
+
|
|
152
|
+
if (mNotificationAndroidStyleBundle.containsKey("picture")) {
|
|
153
|
+
String picture =
|
|
154
|
+
Objects.requireNonNull(mNotificationAndroidStyleBundle.getString("picture"));
|
|
155
|
+
Bitmap pictureBitmap = null;
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
pictureBitmap =
|
|
159
|
+
ResourceUtils.getImageBitmapFromUrl(picture)
|
|
160
|
+
.get(10, TimeUnit.SECONDS);
|
|
161
|
+
} catch (TimeoutException e) {
|
|
162
|
+
Logger.e(
|
|
163
|
+
TAG,
|
|
164
|
+
"Timeout occurred whilst trying to retrieve a big picture style image: "
|
|
165
|
+
+ picture,
|
|
166
|
+
e);
|
|
167
|
+
} catch (Exception e) {
|
|
168
|
+
Logger.e(
|
|
169
|
+
TAG,
|
|
170
|
+
"An error occurred whilst trying to retrieve a big picture style image: "
|
|
171
|
+
+ picture,
|
|
172
|
+
e);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (pictureBitmap != null) {
|
|
176
|
+
bigPictureStyle.bigPicture(pictureBitmap);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
String largeIcon = null;
|
|
181
|
+
|
|
182
|
+
if (mNotificationAndroidStyleBundle.containsKey("largeIcon")) {
|
|
183
|
+
largeIcon = mNotificationAndroidStyleBundle.getString("largeIcon");
|
|
184
|
+
|
|
185
|
+
// largeIcon has been specified to be null for BigPicture
|
|
186
|
+
if (largeIcon == null) {
|
|
187
|
+
bigPictureStyle.bigLargeIcon(null);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (largeIcon != null) {
|
|
192
|
+
Bitmap largeIconBitmap = null;
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
largeIconBitmap =
|
|
196
|
+
ResourceUtils.getImageBitmapFromUrl(largeIcon)
|
|
197
|
+
.get(10, TimeUnit.SECONDS);
|
|
198
|
+
} catch (TimeoutException e) {
|
|
199
|
+
Logger.e(
|
|
200
|
+
TAG,
|
|
201
|
+
"Timeout occurred whilst trying to retrieve a big picture style large icon: "
|
|
202
|
+
+ largeIcon,
|
|
203
|
+
e);
|
|
204
|
+
} catch (Exception e) {
|
|
205
|
+
Logger.e(
|
|
206
|
+
TAG,
|
|
207
|
+
"An error occurred whilst trying to retrieve a big picture style large icon: "
|
|
208
|
+
+ largeIcon,
|
|
209
|
+
e);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (largeIconBitmap != null) {
|
|
213
|
+
bigPictureStyle.bigLargeIcon(largeIconBitmap);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (mNotificationAndroidStyleBundle.containsKey("title")) {
|
|
218
|
+
bigPictureStyle =
|
|
219
|
+
bigPictureStyle.setBigContentTitle(
|
|
220
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("title")));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (mNotificationAndroidStyleBundle.containsKey("summary")) {
|
|
224
|
+
bigPictureStyle =
|
|
225
|
+
bigPictureStyle.setSummaryText(
|
|
226
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("summary")));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return bigPictureStyle;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Gets a BigTextStyle for a notification
|
|
235
|
+
*
|
|
236
|
+
* @return NotificationCompat.BigTextStyle
|
|
237
|
+
*/
|
|
238
|
+
private NotificationCompat.BigTextStyle getBigTextStyle() {
|
|
239
|
+
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
|
|
240
|
+
|
|
241
|
+
if (mNotificationAndroidStyleBundle.containsKey("text")) {
|
|
242
|
+
bigTextStyle =
|
|
243
|
+
bigTextStyle.bigText(
|
|
244
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("text")));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (mNotificationAndroidStyleBundle.containsKey("title")) {
|
|
248
|
+
bigTextStyle =
|
|
249
|
+
bigTextStyle.setBigContentTitle(
|
|
250
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("title")));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (mNotificationAndroidStyleBundle.containsKey("summary")) {
|
|
254
|
+
bigTextStyle =
|
|
255
|
+
bigTextStyle.setSummaryText(
|
|
256
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("summary")));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return bigTextStyle;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Gets an InboxStyle for a notification
|
|
264
|
+
*
|
|
265
|
+
* @return NotificationCompat.InboxStyle
|
|
266
|
+
*/
|
|
267
|
+
private NotificationCompat.InboxStyle getInboxStyle() {
|
|
268
|
+
NotificationCompat.InboxStyle inputStyle = new NotificationCompat.InboxStyle();
|
|
269
|
+
|
|
270
|
+
if (mNotificationAndroidStyleBundle.containsKey("title")) {
|
|
271
|
+
inputStyle =
|
|
272
|
+
inputStyle.setBigContentTitle(
|
|
273
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("title")));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (mNotificationAndroidStyleBundle.containsKey("summary")) {
|
|
277
|
+
inputStyle =
|
|
278
|
+
inputStyle.setSummaryText(
|
|
279
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("summary")));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
ArrayList<String> lines = mNotificationAndroidStyleBundle.getStringArrayList("lines");
|
|
283
|
+
|
|
284
|
+
for (int i = 0; i < Objects.requireNonNull(lines).size(); i++) {
|
|
285
|
+
String line = lines.get(i);
|
|
286
|
+
inputStyle = inputStyle.addLine(TextUtils.fromHtml(line));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return inputStyle;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Gets a MessagingStyle for a notification */
|
|
293
|
+
private ListenableFuture<NotificationCompat.Style> getMessagingStyleTask(
|
|
294
|
+
ListeningExecutorService lExecutor) {
|
|
295
|
+
return lExecutor.submit(
|
|
296
|
+
() -> {
|
|
297
|
+
Person person =
|
|
298
|
+
getPerson(lExecutor,
|
|
299
|
+
Objects.requireNonNull(
|
|
300
|
+
mNotificationAndroidStyleBundle.getBundle("person"))
|
|
301
|
+
).get(20, TimeUnit.SECONDS);
|
|
302
|
+
|
|
303
|
+
NotificationCompat.MessagingStyle messagingStyle =
|
|
304
|
+
new NotificationCompat.MessagingStyle(person);
|
|
305
|
+
|
|
306
|
+
if (mNotificationAndroidStyleBundle.containsKey("title")) {
|
|
307
|
+
messagingStyle =
|
|
308
|
+
messagingStyle.setConversationTitle(
|
|
309
|
+
TextUtils.fromHtml(mNotificationAndroidStyleBundle.getString("title")));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (mNotificationAndroidStyleBundle.containsKey("group")) {
|
|
313
|
+
messagingStyle =
|
|
314
|
+
messagingStyle.setGroupConversation(
|
|
315
|
+
mNotificationAndroidStyleBundle.getBoolean("group"));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
ArrayList<Bundle> messages =
|
|
319
|
+
mNotificationAndroidStyleBundle.getParcelableArrayList("messages");
|
|
320
|
+
|
|
321
|
+
for (int i = 0; i < Objects.requireNonNull(messages).size(); i++) {
|
|
322
|
+
Bundle message = messages.get(i);
|
|
323
|
+
Person messagePerson = null;
|
|
324
|
+
long timestamp = ObjectUtils.getLong(message.get("timestamp"));
|
|
325
|
+
|
|
326
|
+
if (message.containsKey("person")) {
|
|
327
|
+
messagePerson =
|
|
328
|
+
getPerson(lExecutor,
|
|
329
|
+
Objects.requireNonNull(message.getBundle("person"))
|
|
330
|
+
).get(20, TimeUnit.SECONDS);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
messagingStyle =
|
|
334
|
+
messagingStyle.addMessage(
|
|
335
|
+
TextUtils.fromHtml(message.getString("text")), timestamp, messagePerson);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return messagingStyle;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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.os.Bundle;
|
|
21
|
+
import androidx.annotation.NonNull;
|
|
22
|
+
import androidx.annotation.Nullable;
|
|
23
|
+
import app.notifee.core.KeepForSdk;
|
|
24
|
+
import java.util.Objects;
|
|
25
|
+
|
|
26
|
+
@KeepForSdk
|
|
27
|
+
public class NotificationModel {
|
|
28
|
+
private Bundle mNotificationBundle;
|
|
29
|
+
|
|
30
|
+
public NotificationModel(Bundle bundle) {
|
|
31
|
+
mNotificationBundle = bundle;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static NotificationModel fromBundle(@NonNull Bundle bundle) {
|
|
35
|
+
return new NotificationModel(bundle);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public @NonNull Integer getHashCode() {
|
|
39
|
+
return getId().hashCode();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public @NonNull String getId() {
|
|
43
|
+
return Objects.requireNonNull(mNotificationBundle.getString("id"));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public @Nullable String getTitle() {
|
|
47
|
+
return mNotificationBundle.getString("title");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public @Nullable String getSubTitle() {
|
|
51
|
+
return mNotificationBundle.getString("subtitle");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public @Nullable String getBody() {
|
|
55
|
+
return mNotificationBundle.getString("body");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public @NonNull NotificationAndroidModel getAndroid() {
|
|
59
|
+
return NotificationAndroidModel.fromBundle(mNotificationBundle.getBundle("android"));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public @NonNull Bundle getData() {
|
|
63
|
+
Bundle data = mNotificationBundle.getBundle("data");
|
|
64
|
+
if (data != null) return (Bundle) data.clone();
|
|
65
|
+
return new Bundle();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@KeepForSdk
|
|
69
|
+
public Bundle toBundle() {
|
|
70
|
+
return (Bundle) mNotificationBundle.clone();
|
|
71
|
+
}
|
|
72
|
+
}
|