mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 15:15:09 +00:00
Refactor action extraction
This commit is contained in:
@@ -236,25 +236,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
np.set("actions", extractActions(notification, key));
|
||||||
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("id", key);
|
np.set("id", key);
|
||||||
np.set("isClearable", statusBarNotification.isClearable());
|
np.set("isClearable", statusBarNotification.isClearable());
|
||||||
@@ -331,6 +313,37 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
return null;
|
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) {
|
private Pair<String, String> extractConversation(Notification notification) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
|
||||||
return new Pair<>(null, null);
|
return new Pair<>(null, null);
|
||||||
|
Reference in New Issue
Block a user