@ammarahmed/notifee-react-native 7.3.1 → 7.4.1
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,189 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
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.PendingIntent;
|
|
21
|
+
import android.content.Context;
|
|
22
|
+
import android.content.Intent;
|
|
23
|
+
import android.os.Bundle;
|
|
24
|
+
import app.notifee.core.event.MainComponentEvent;
|
|
25
|
+
import app.notifee.core.model.NotificationAndroidPressActionModel;
|
|
26
|
+
import app.notifee.core.utility.IntentUtils;
|
|
27
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
|
28
|
+
|
|
29
|
+
public class NotificationPendingIntent {
|
|
30
|
+
public static final String EVENT_TYPE_INTENT_KEY = "notifee_event_type";
|
|
31
|
+
public static final String NOTIFICATION_ID_INTENT_KEY = "notification_id";
|
|
32
|
+
private static final AtomicInteger uniqueIds = new AtomicInteger(0);
|
|
33
|
+
private static final String TAG = "NotificationPendingIntent";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates a PendingIntent, which when sent triggers this class.
|
|
37
|
+
*
|
|
38
|
+
* @param notificationId int
|
|
39
|
+
* @param pressActionModelBundle NotificationAndroidPressActionModel.
|
|
40
|
+
* @param extraKeys Array of strings
|
|
41
|
+
* @param extraBundles One or more bundles
|
|
42
|
+
*/
|
|
43
|
+
static PendingIntent createIntent(
|
|
44
|
+
int notificationId,
|
|
45
|
+
Bundle pressActionModelBundle,
|
|
46
|
+
int eventType,
|
|
47
|
+
String[] extraKeys,
|
|
48
|
+
Bundle... extraBundles) {
|
|
49
|
+
Context context = ContextHolder.getApplicationContext();
|
|
50
|
+
|
|
51
|
+
// Get launch activity intent
|
|
52
|
+
Intent launchActivityIntent = null;
|
|
53
|
+
if (pressActionModelBundle != null) {
|
|
54
|
+
launchActivityIntent =
|
|
55
|
+
createLaunchActivityIntent(
|
|
56
|
+
context,
|
|
57
|
+
notificationId,
|
|
58
|
+
NotificationAndroidPressActionModel.fromBundle(pressActionModelBundle));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Create an activity to receive notification events
|
|
62
|
+
Intent receiverIntent = new Intent(context, NotificationReceiverActivity.class);
|
|
63
|
+
|
|
64
|
+
// Set extras for each intent
|
|
65
|
+
setIntentExtras(launchActivityIntent, eventType, notificationId, extraKeys, extraBundles);
|
|
66
|
+
setIntentExtras(receiverIntent, eventType, notificationId, extraKeys, extraBundles);
|
|
67
|
+
|
|
68
|
+
// Create pending intent with activities
|
|
69
|
+
int uniqueInt = uniqueIds.getAndIncrement();
|
|
70
|
+
Intent[] intents;
|
|
71
|
+
|
|
72
|
+
if (launchActivityIntent != null) {
|
|
73
|
+
intents = new Intent[2];
|
|
74
|
+
intents[0] = launchActivityIntent;
|
|
75
|
+
|
|
76
|
+
receiverIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
77
|
+
intents[1] = receiverIntent;
|
|
78
|
+
} else {
|
|
79
|
+
intents = new Intent[1];
|
|
80
|
+
receiverIntent.setFlags(
|
|
81
|
+
Intent.FLAG_ACTIVITY_NEW_TASK
|
|
82
|
+
| Intent.FLAG_ACTIVITY_MULTIPLE_TASK
|
|
83
|
+
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
|
84
|
+
|
|
85
|
+
intents[0] = receiverIntent;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return PendingIntent.getActivities(
|
|
89
|
+
context,
|
|
90
|
+
uniqueInt,
|
|
91
|
+
intents,
|
|
92
|
+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static void setIntentExtras(
|
|
96
|
+
Intent intent,
|
|
97
|
+
int eventType,
|
|
98
|
+
int notificationId,
|
|
99
|
+
String[] extraKeys,
|
|
100
|
+
Bundle... extraBundles) {
|
|
101
|
+
if (intent == null) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
intent.putExtra(EVENT_TYPE_INTENT_KEY, eventType);
|
|
106
|
+
intent.putExtra(NOTIFICATION_ID_INTENT_KEY, notificationId);
|
|
107
|
+
|
|
108
|
+
for (int i = 0; i < extraKeys.length; i++) {
|
|
109
|
+
String key = extraKeys[i];
|
|
110
|
+
|
|
111
|
+
if (i <= extraBundles.length - 1) {
|
|
112
|
+
Bundle bundle = extraBundles[i];
|
|
113
|
+
intent.putExtra(key, bundle);
|
|
114
|
+
} else {
|
|
115
|
+
intent.putExtra(key, (String) null);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static boolean shouldCreateLaunchActivityIntent(
|
|
121
|
+
NotificationAndroidPressActionModel pressActionModel) {
|
|
122
|
+
if (pressActionModel == null) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (pressActionModel.getLaunchActivity() == null
|
|
127
|
+
&& pressActionModel.getMainComponent() == null) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static Intent createLaunchActivityIntent(
|
|
135
|
+
Context context, int notificationId, NotificationAndroidPressActionModel pressActionModel) {
|
|
136
|
+
if (!shouldCreateLaunchActivityIntent(pressActionModel)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
Intent launchActivityIntent =
|
|
142
|
+
context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
143
|
+
|
|
144
|
+
// Get launchActivity value from payload
|
|
145
|
+
String launchActivity = null;
|
|
146
|
+
if (pressActionModel != null) {
|
|
147
|
+
launchActivity = pressActionModel.getLaunchActivity();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Determine if existing launchActivityIntent should be overwritten
|
|
151
|
+
// to handle a custom launchActivity
|
|
152
|
+
Boolean shouldOverwriteDefaultLaunchActivityIntent = launchActivityIntent == null;
|
|
153
|
+
if (launchActivityIntent != null) {
|
|
154
|
+
// overwrite if custom launch activity set (launch activity in payload does not equal current activity)
|
|
155
|
+
shouldOverwriteDefaultLaunchActivityIntent = launchActivity != "default" && launchActivityIntent.getComponent().getClassName() != launchActivity;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Set new launch activity intent
|
|
159
|
+
if (launchActivity != null && shouldOverwriteDefaultLaunchActivityIntent) {
|
|
160
|
+
Class<?> launchActivityClass = IntentUtils.getLaunchActivity(launchActivity);
|
|
161
|
+
launchActivityIntent = new Intent(context, launchActivityClass);
|
|
162
|
+
|
|
163
|
+
launchActivityIntent.setPackage(null);
|
|
164
|
+
|
|
165
|
+
launchActivityIntent.setFlags(
|
|
166
|
+
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Set any additional flags or main component if specified
|
|
170
|
+
if (pressActionModel.getLaunchActivityFlags() != -1) {
|
|
171
|
+
launchActivityIntent.setFlags(pressActionModel.getLaunchActivityFlags());
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (pressActionModel.getMainComponent() != null) {
|
|
175
|
+
launchActivityIntent.putExtra("mainComponent", pressActionModel.getMainComponent());
|
|
176
|
+
EventBus.postSticky(new MainComponentEvent(pressActionModel.getMainComponent()));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return launchActivityIntent;
|
|
180
|
+
} catch (Exception e) {
|
|
181
|
+
Logger.e(
|
|
182
|
+
"NotificationPendingIntent",
|
|
183
|
+
"Failed to create LaunchActivityIntent for notification " + notificationId,
|
|
184
|
+
e);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
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.Activity;
|
|
21
|
+
import android.content.Intent;
|
|
22
|
+
import android.os.Bundle;
|
|
23
|
+
|
|
24
|
+
public class NotificationReceiverActivity extends Activity {
|
|
25
|
+
@Override
|
|
26
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
27
|
+
super.onCreate(savedInstanceState);
|
|
28
|
+
NotificationReceiverHandler.handleNotification(this, getIntent());
|
|
29
|
+
finish();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Override
|
|
33
|
+
protected void onNewIntent(Intent intent) {
|
|
34
|
+
super.onNewIntent(intent);
|
|
35
|
+
NotificationReceiverHandler.handleNotification(this, intent);
|
|
36
|
+
finish();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
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 static app.notifee.core.NotificationPendingIntent.EVENT_TYPE_INTENT_KEY;
|
|
21
|
+
import static app.notifee.core.NotificationPendingIntent.NOTIFICATION_ID_INTENT_KEY;
|
|
22
|
+
import static app.notifee.core.event.NotificationEvent.TYPE_ACTION_PRESS;
|
|
23
|
+
import static app.notifee.core.event.NotificationEvent.TYPE_PRESS;
|
|
24
|
+
|
|
25
|
+
import android.app.RemoteInput;
|
|
26
|
+
import android.content.Context;
|
|
27
|
+
import android.content.Intent;
|
|
28
|
+
import android.os.Bundle;
|
|
29
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
30
|
+
import app.notifee.core.event.InitialNotificationEvent;
|
|
31
|
+
import app.notifee.core.event.MainComponentEvent;
|
|
32
|
+
import app.notifee.core.event.NotificationEvent;
|
|
33
|
+
import app.notifee.core.model.NotificationAndroidPressActionModel;
|
|
34
|
+
import app.notifee.core.model.NotificationModel;
|
|
35
|
+
|
|
36
|
+
public class NotificationReceiverHandler {
|
|
37
|
+
public static final String REMOTE_INPUT_RECEIVER_KEY =
|
|
38
|
+
"app.notifee.core.ReceiverService.REMOTE_INPUT_RECEIVER_KEY";
|
|
39
|
+
private static final String TAG = "NotificationReceiverHandler";
|
|
40
|
+
|
|
41
|
+
static void handleNotification(Context context, Intent intent) {
|
|
42
|
+
if (!intent.hasExtra("notification")) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (context != null && ContextHolder.getApplicationContext() == null) {
|
|
47
|
+
ContextHolder.setApplicationContext(context.getApplicationContext());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
handleNotificationIntent(context, intent);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private static void handleNotificationIntent(Context context, Intent intent) {
|
|
54
|
+
int type = intent.getIntExtra(EVENT_TYPE_INTENT_KEY, 0);
|
|
55
|
+
|
|
56
|
+
if (type == 0) {
|
|
57
|
+
// no-op, ignore intent
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
switch (type) {
|
|
62
|
+
case TYPE_PRESS:
|
|
63
|
+
handleNotificationPressIntent(context, intent);
|
|
64
|
+
break;
|
|
65
|
+
case TYPE_ACTION_PRESS:
|
|
66
|
+
handleNotificationActionIntent(context, intent);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private static void handleNotificationActionIntent(Context context, Intent intent) {
|
|
72
|
+
Bundle notification = intent.getBundleExtra("notification");
|
|
73
|
+
Bundle pressAction = intent.getBundleExtra("pressAction");
|
|
74
|
+
|
|
75
|
+
if (notification == null || pressAction == null) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(notification);
|
|
80
|
+
NotificationAndroidPressActionModel pressActionBundle =
|
|
81
|
+
NotificationAndroidPressActionModel.fromBundle(pressAction);
|
|
82
|
+
|
|
83
|
+
Bundle extras = new Bundle();
|
|
84
|
+
extras.putBundle("pressAction", pressActionBundle.toBundle());
|
|
85
|
+
|
|
86
|
+
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
|
|
87
|
+
if (remoteInput != null) {
|
|
88
|
+
CharSequence input = remoteInput.getCharSequence(REMOTE_INPUT_RECEIVER_KEY);
|
|
89
|
+
if (input != null) {
|
|
90
|
+
extras.putString("input", input.toString());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
NotificationManagerCompat.from(context)
|
|
95
|
+
.cancel(intent.getIntExtra(NOTIFICATION_ID_INTENT_KEY, 0));
|
|
96
|
+
|
|
97
|
+
InitialNotificationEvent initialNotificationEvent =
|
|
98
|
+
new InitialNotificationEvent(notificationModel, extras);
|
|
99
|
+
EventBus.postSticky(initialNotificationEvent);
|
|
100
|
+
|
|
101
|
+
// Send event
|
|
102
|
+
EventBus.post(new NotificationEvent(TYPE_ACTION_PRESS, notificationModel, extras));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private static void handleNotificationPressIntent(Context context, Intent intent) {
|
|
106
|
+
Bundle notification = intent.getBundleExtra("notification");
|
|
107
|
+
|
|
108
|
+
if (notification == null) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(notification);
|
|
113
|
+
|
|
114
|
+
Bundle pressAction = intent.getBundleExtra("pressAction");
|
|
115
|
+
NotificationAndroidPressActionModel pressActionBundle = null;
|
|
116
|
+
|
|
117
|
+
Bundle extras = new Bundle();
|
|
118
|
+
|
|
119
|
+
if (pressAction != null) {
|
|
120
|
+
pressActionBundle = NotificationAndroidPressActionModel.fromBundle(pressAction);
|
|
121
|
+
extras.putBundle("pressAction", pressActionBundle.toBundle());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
EventBus.post(new NotificationEvent(TYPE_PRESS, notificationModel, extras));
|
|
125
|
+
|
|
126
|
+
if (pressActionBundle == null) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
String mainComponent = pressActionBundle.getMainComponent();
|
|
131
|
+
InitialNotificationEvent initialNotificationEvent =
|
|
132
|
+
new InitialNotificationEvent(notificationModel, extras);
|
|
133
|
+
EventBus.postSticky(initialNotificationEvent);
|
|
134
|
+
|
|
135
|
+
// Send sticky event to save the mainComponent
|
|
136
|
+
if (mainComponent != null) {
|
|
137
|
+
EventBus.postSticky(new MainComponentEvent(mainComponent));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
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.Context;
|
|
21
|
+
import android.content.SharedPreferences;
|
|
22
|
+
|
|
23
|
+
class Preferences {
|
|
24
|
+
private static final String PREFERENCES_FILE = "app.notifee.core";
|
|
25
|
+
private static Preferences sharedInstance = new Preferences();
|
|
26
|
+
private SharedPreferences preferences;
|
|
27
|
+
|
|
28
|
+
static Preferences getSharedInstance() {
|
|
29
|
+
return sharedInstance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
boolean contains(String key) {
|
|
33
|
+
return getPreferences().contains(key);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void setBooleanValue(String key, boolean value) {
|
|
37
|
+
getPreferences().edit().putBoolean(key, value).apply();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
boolean getBooleanValue(String key, boolean defaultValue) {
|
|
41
|
+
return getPreferences().getBoolean(key, defaultValue);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void setLongValue(String key, long value) {
|
|
45
|
+
getPreferences().edit().putLong(key, value).apply();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
long getLongValue(String key, long defaultValue) {
|
|
49
|
+
return getPreferences().getLong(key, defaultValue);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void setIntValue(String key, int value) {
|
|
53
|
+
getPreferences().edit().putInt(key, value).apply();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
int getIntValue(String key, int defaultValue) {
|
|
57
|
+
return getPreferences().getInt(key, defaultValue);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void setStringValue(String key, String value) {
|
|
61
|
+
getPreferences().edit().putString(key, value).apply();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
String getStringValue(String key, String defaultValue) {
|
|
65
|
+
return getPreferences().getString(key, defaultValue);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void clearAll() {
|
|
69
|
+
getPreferences().edit().clear().apply();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private SharedPreferences getPreferences() {
|
|
73
|
+
if (preferences != null) return preferences;
|
|
74
|
+
preferences =
|
|
75
|
+
ContextHolder.getApplicationContext()
|
|
76
|
+
.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
|
|
77
|
+
return preferences;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
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.BroadcastReceiver;
|
|
21
|
+
import android.content.Context;
|
|
22
|
+
import android.content.Intent;
|
|
23
|
+
import android.util.Log;
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* This is invoked when the phone restarts to ensure that all notifications created by the alarm manager
|
|
27
|
+
* are rescheduled correctly, as Android removes all scheduled alarms when the phone shuts down.
|
|
28
|
+
*/
|
|
29
|
+
public class RebootBroadcastReceiver extends BroadcastReceiver {
|
|
30
|
+
@Override
|
|
31
|
+
public void onReceive(Context context, Intent intent) {
|
|
32
|
+
Log.i("RebootReceiver", "Received reboot event");
|
|
33
|
+
if (ContextHolder.getApplicationContext() == null) {
|
|
34
|
+
ContextHolder.setApplicationContext(context.getApplicationContext());
|
|
35
|
+
}
|
|
36
|
+
new NotifeeAlarmManager().rescheduleNotifications();
|
|
37
|
+
}
|
|
38
|
+
}
|