Skip to content

Commit 3a0cf8e

Browse files
committed
Added notificationAction to LiveNotification
1 parent 55455dc commit 3a0cf8e

13 files changed

+262
-37
lines changed

.idea/deploymentTargetSelector.xml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ android {
7373
}
7474

7575
dependencies {
76-
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2'
76+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.3'
7777
implementation fileTree(dir: 'libs', include: ['*.jar'])
7878
testImplementation 'junit:junit:4.13.2'
7979
androidTestImplementation 'androidx.test.ext:junit:1.2.1'

app/src/main/java/com/noti/main/service/FirebaseMessageService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public interface OnNotificationRemoveRequest {
129129
}
130130

131131
public static OnNotificationRemoveRequest removeListener;
132+
public static OnNotificationRemoveRequest removeListenerAll;
132133
public static OnNotificationRemoveRequest removeListenerById;
133134

134135
@Override

app/src/main/java/com/noti/main/service/NotiListenerService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class NotiListenerService extends NotificationListenerService {
7777
private static final Object pastNotificationLock = new Object();
7878
private volatile StatusBarNotification pastNotification = null;
7979
private final FirebaseMessageService.OnNotificationRemoveRequest onRemoveRequestListener = this::cancelNotification;
80+
private final FirebaseMessageService.OnNotificationRemoveRequest onRemoveRequestAllListener = (unused) -> cancelAllNotifications();
8081
private final FirebaseMessageService.OnNotificationRemoveRequest onRemoveRequestListenerById = key -> {
8182
StatusBarNotification[] notifications = this.getActiveNotifications();
8283
for (StatusBarNotification statusBarNotification : notifications) {
@@ -114,6 +115,7 @@ public void onCreate() {
114115
super.onCreate();
115116
if (instance == null) initService(this);
116117
FirebaseMessageService.removeListener = onRemoveRequestListener;
118+
FirebaseMessageService.removeListenerAll = onRemoveRequestAllListener;
117119
FirebaseMessageService.removeListenerById = onRemoveRequestListenerById;
118120
}
119121

app/src/main/java/com/noti/main/service/backend/PacketBonding.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,7 @@ public static void runBondingSchedule(Context context, JSONObject notification,
6060
for(JSONObject o : onWriteArrayList) {
6161
array.put(o);
6262
}
63-
64-
JSONObject finalNotification = new JSONObject();
65-
finalNotification.put("type", PacketConst.SERVICE_TYPE_PACKET_BONDING);
66-
finalNotification.put(PacketConst.KEY_PACKET_BONDING_ARRAY, array.toString());
67-
finalNotification.put(PacketConst.KEY_DEVICE_ID, NotiListenerService.getUniqueID());
68-
finalNotification.put(PacketConst.KEY_DEVICE_NAME, NotiListenerService.getDeviceName());
69-
70-
if(BuildConfig.DEBUG) Log.d("PacketBonding", String.format("Sending %d bonded packets together...", array.length()));
71-
NotiListenerService.proxyToBackend(finalNotification, "PacketBonding", context, false);
63+
sendBondingArrayNow(context, array);
7264
}
7365
} catch (JSONException | NoSuchAlgorithmException e) {
7466
e.printStackTrace();
@@ -78,6 +70,17 @@ public static void runBondingSchedule(Context context, JSONObject notification,
7870
}, selectedDelay, TimeUnit.MILLISECONDS);
7971
}
8072

73+
public static void sendBondingArrayNow(Context context, JSONArray array) throws JSONException, NoSuchAlgorithmException {
74+
JSONObject finalNotification = new JSONObject();
75+
finalNotification.put("type", PacketConst.SERVICE_TYPE_PACKET_BONDING);
76+
finalNotification.put(PacketConst.KEY_PACKET_BONDING_ARRAY, array.toString());
77+
finalNotification.put(PacketConst.KEY_DEVICE_ID, NotiListenerService.getUniqueID());
78+
finalNotification.put(PacketConst.KEY_DEVICE_NAME, NotiListenerService.getDeviceName());
79+
80+
if(BuildConfig.DEBUG) Log.d("PacketBonding", String.format("Sending %d bonded packets together...", array.length()));
81+
NotiListenerService.proxyToBackend(finalNotification, "PacketBonding", context, false);
82+
}
83+
8184
@SuppressWarnings("unchecked")
8285
public static void processPacketBonding(Map<String, String> map, OnPacketBondingCallback callback) {
8386
String rawData = map.get(PacketConst.KEY_PACKET_BONDING_ARRAY);

app/src/main/java/com/noti/main/service/livenoti/LiveNotiProcess.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.noti.main.BuildConfig;
1010
import com.noti.main.service.FirebaseMessageService;
1111
import com.noti.main.service.backend.PacketConst;
12+
import com.noti.main.service.mirnoti.NotificationActionProcess;
1213
import com.noti.main.service.mirnoti.NotificationsData;
1314

1415
import java.util.ArrayList;
@@ -24,6 +25,7 @@ public class LiveNotiProcess {
2425
public static final String REQUEST_LIVE_NOTIFICATION = "request_live_notification";
2526
public static final String RESPONSE_LIVE_NOTIFICATION = "response_live_notification";
2627
public static final String REQUEST_NOTIFICATION_ACTION = "response_notification_action";
28+
public static final String REQUEST_NOTIFICATION_DISMISS_ALL = "request_notification_dismiss_all";
2729

2830
public static onLiveNotificationUploadCompleteListener mOnLiveNotificationDownloadCompleteListener;
2931
public static onLiveNotificationUploadCompleteListener mOnLiveNotificationUploadCompleteListener;
@@ -49,6 +51,11 @@ public static void onProcessReceive(Map<String, String> map, Context context) {
4951
case REQUEST_LIVE_NOTIFICATION -> LiveNotiRequests.postLiveNotificationData(context, map);
5052
case RESPONSE_LIVE_NOTIFICATION -> LiveNotiRequests.getLiveNotificationData(context, map);
5153
case REQUEST_NOTIFICATION_ACTION -> FirebaseMessageService.startNewRemoteActivity(context, map);
54+
case REQUEST_NOTIFICATION_DISMISS_ALL -> {
55+
if(FirebaseMessageService.removeListenerAll != null) {
56+
FirebaseMessageService.removeListenerAll.onRequested(null);
57+
}
58+
}
5259
default -> {
5360
if(BuildConfig.DEBUG) {
5461
Log.e("LiveNotification", "onProcessReceive failed: Action type is not supported: " + map.get(PacketConst.KEY_ACTION_TYPE));
@@ -72,6 +79,10 @@ public static String toStringLiveNotificationList(Context context) throws JsonPr
7279
continue;
7380
}
7481

82+
if(Objects.requireNonNullElse(statusBarNotification.getNotification().actions, new Object[0]).length > 0) {
83+
NotificationActionProcess.registerAction(statusBarNotification);
84+
}
85+
7586
try {
7687
finalDataList.add(new NotificationsData(context, statusBarNotification).toString());
7788
keyList.add(statusBarNotification.getKey());

app/src/main/java/com/noti/main/service/mirnoti/NotificationActionProcess.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.noti.main.service.FirebaseMessageService;
2121

22+
import java.util.Objects;
2223
import java.util.concurrent.ConcurrentHashMap;
2324

2425
public class NotificationActionProcess {
@@ -121,7 +122,7 @@ public void onReceive(Context context, Intent intent) {
121122
return;
122123
}
123124

124-
String key = intent.getStringExtra(NotificationRequest.KEY_NOTIFICATION_KEY);
125+
String key = Objects.requireNonNullElse(intent.getStringExtra(NotificationRequest.KEY_NOTIFICATION_KEY), "");
125126
int index = intent.getIntExtra(NotificationRequest.KEY_NOTIFICATION_ACTION_INDEX, 0);
126127

127128
if(intent.getBooleanExtra(NotificationRequest.KEY_NOTIFICATION_HAS_INPUT, false)) {
@@ -134,7 +135,7 @@ public void onReceive(Context context, Intent intent) {
134135
intent.getStringExtra("device_name"), intent.getStringExtra("device_id"));
135136
}
136137

137-
final int uniqueCode = intent.getIntExtra(NotificationRequest.KEY_NOTIFICATION_HASHCODE, -1);
138+
final int uniqueCode = intent.getIntExtra(NotificationRequest.KEY_NOTIFICATION_HASHCODE, key.hashCode());
138139
if(uniqueCode != -1) {
139140
if(FirebaseMessageService.removeListenerById == null) {
140141
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

app/src/main/java/com/noti/main/service/mirnoti/NotificationRequest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,21 @@ public static void receptionNotification(Context context, @Nullable String Packa
151151
if(BuildConfig.DEBUG) Log.d("data-receive", notificationBody.toString());
152152
NotiListenerService.sendNotification(notificationBody, Package, context);
153153
}
154+
155+
public static void requestDismissAllNotifications(Context context, String DEVICE_NAME, String DEVICE_ID) {
156+
JSONObject notificationBody = new JSONObject();
157+
try {
158+
notificationBody.put(PacketConst.KEY_ACTION_TYPE, LiveNotiProcess.REQUEST_NOTIFICATION_DISMISS_ALL);
159+
notificationBody.put("type","pair|live_notification");
160+
notificationBody.put("device_name", NotiListenerService.getDeviceName());
161+
notificationBody.put("device_id", NotiListenerService.getUniqueID());
162+
notificationBody.put("send_device_name", DEVICE_NAME);
163+
notificationBody.put("send_device_id", DEVICE_ID);
164+
} catch (JSONException e) {
165+
Log.e("Noti", "onCreate: " + e.getMessage() );
166+
}
167+
168+
if(BuildConfig.DEBUG) Log.d("data-receive", notificationBody.toString());
169+
NotiListenerService.sendNotification(notificationBody, "NotificationRequest", context);
170+
}
154171
}

0 commit comments

Comments
 (0)