mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 05:07:40 +00:00
Refactor action extraction
This commit is contained in:
parent
7c723eea8c
commit
4cdda3f31b
@ -236,25 +236,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
}
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (notification.actions != null && notification.actions.length > 0) {
|
||||
actions.put(key, new LinkedList<>());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (Notification.Action action : notification.actions) {
|
||||
|
||||
if (null == action.title)
|
||||
continue;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
|
||||
if (action.getRemoteInputs() != null && action.getRemoteInputs().length > 0)
|
||||
continue;
|
||||
|
||||
jsonArray.put(action.title.toString());
|
||||
actions.get(key).add(action);
|
||||
}
|
||||
np.set("actions", jsonArray);
|
||||
}
|
||||
}
|
||||
np.set("actions", extractActions(notification, key));
|
||||
|
||||
np.set("id", key);
|
||||
np.set("isClearable", statusBarNotification.isClearable());
|
||||
@ -331,6 +313,37 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JSONArray extractActions(Notification notification, String key) {
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (notification.actions == null || notification.actions.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
actions.put(key, new LinkedList<>());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
for (Notification.Action action : notification.actions) {
|
||||
|
||||
if (null == action.title)
|
||||
continue;
|
||||
|
||||
// Check whether it is a reply action. We have special treatment for them
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
|
||||
if (action.getRemoteInputs() != null && action.getRemoteInputs().length > 0)
|
||||
continue;
|
||||
|
||||
jsonArray.put(action.title.toString());
|
||||
actions.get(key).add(action);
|
||||
}
|
||||
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
private Pair<String, String> extractConversation(Notification notification) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
|
||||
return new Pair<>(null, null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user