mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +00:00
Refactor extractRepliableNotification
This commit is contained in:
@@ -242,9 +242,10 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
np.set("isClearable", statusBarNotification.isClearable());
|
np.set("isClearable", statusBarNotification.isClearable());
|
||||||
np.set("appName", appName == null ? packageName : appName);
|
np.set("appName", appName == null ? packageName : appName);
|
||||||
np.set("time", Long.toString(statusBarNotification.getPostTime()));
|
np.set("time", Long.toString(statusBarNotification.getPostTime()));
|
||||||
|
|
||||||
if (!appDatabase.getPrivacy(packageName, AppDatabase.PrivacyOptions.BLOCK_CONTENTS)) {
|
if (!appDatabase.getPrivacy(packageName, AppDatabase.PrivacyOptions.BLOCK_CONTENTS)) {
|
||||||
RepliableNotification rn = extractRepliableNotification(statusBarNotification);
|
RepliableNotification rn = extractRepliableNotification(statusBarNotification);
|
||||||
if (rn.pendingIntent != null) {
|
if (rn != null) {
|
||||||
np.set("requestReplyId", rn.id);
|
np.set("requestReplyId", rn.id);
|
||||||
pendingIntents.put(rn.id, rn);
|
pendingIntents.put(rn.id, rn);
|
||||||
}
|
}
|
||||||
@@ -441,31 +442,31 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
pendingIntents.remove(id);
|
pendingIntents.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private RepliableNotification extractRepliableNotification(StatusBarNotification statusBarNotification) {
|
private RepliableNotification extractRepliableNotification(StatusBarNotification statusBarNotification) {
|
||||||
RepliableNotification repliableNotification = new RepliableNotification();
|
|
||||||
|
|
||||||
if (statusBarNotification != null) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
return null;
|
||||||
try {
|
}
|
||||||
if (statusBarNotification.getNotification().actions != null) {
|
|
||||||
|
if (statusBarNotification.getNotification().actions == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for (Notification.Action act : statusBarNotification.getNotification().actions) {
|
for (Notification.Action act : statusBarNotification.getNotification().actions) {
|
||||||
if (act != null && act.getRemoteInputs() != null) {
|
if (act != null && act.getRemoteInputs() != null) {
|
||||||
// Is a reply
|
// Is a reply
|
||||||
|
RepliableNotification repliableNotification = new RepliableNotification();
|
||||||
repliableNotification.remoteInputs.addAll(Arrays.asList(act.getRemoteInputs()));
|
repliableNotification.remoteInputs.addAll(Arrays.asList(act.getRemoteInputs()));
|
||||||
repliableNotification.pendingIntent = act.actionIntent;
|
repliableNotification.pendingIntent = act.actionIntent;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repliableNotification.packageName = statusBarNotification.getPackageName();
|
repliableNotification.packageName = statusBarNotification.getPackageName();
|
||||||
repliableNotification.tag = statusBarNotification.getTag();//TODO find how to pass Tag with sending PendingIntent, might fix Hangout problem
|
repliableNotification.tag = statusBarNotification.getTag(); //TODO find how to pass Tag with sending PendingIntent, might fix Hangout problem
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
return repliableNotification;
|
||||||
Log.e(TAG, "problem extracting notification wear for " + statusBarNotification.getNotification().tickerText, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return repliableNotification;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String extractStringFromExtra(Bundle extras, String key) {
|
private static String extractStringFromExtra(Bundle extras, String key) {
|
||||||
|
Reference in New Issue
Block a user