use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class LocalNotification method buildLocalNotificationPendingList.
public static JSObject buildLocalNotificationPendingList(List<LocalNotification> notifications) {
JSObject result = new JSObject();
JSArray jsArray = new JSArray();
for (LocalNotification notification : notifications) {
JSObject jsNotification = new JSObject();
jsNotification.put("id", notification.getId());
jsNotification.put("title", notification.getTitle());
jsNotification.put("body", notification.getBody());
LocalNotificationSchedule schedule = notification.getSchedule();
if (schedule != null) {
JSObject jsSchedule = new JSObject();
jsSchedule.put("at", schedule.getAt());
jsSchedule.put("every", schedule.getEvery());
jsSchedule.put("count", schedule.getCount());
jsSchedule.put("on", schedule.getOnObj());
jsSchedule.put("repeats", schedule.isRepeating());
jsNotification.put("schedule", jsSchedule);
}
jsNotification.put("extra", notification.getExtra());
jsArray.put(jsNotification);
}
result.put("notifications", jsArray);
return result;
}
use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class LocalNotification method buildNotificationFromJSObject.
public static LocalNotification buildNotificationFromJSObject(JSObject jsonObject) throws ParseException {
LocalNotification localNotification = new LocalNotification();
localNotification.setSource(jsonObject.toString());
localNotification.setId(jsonObject.getInteger("id"));
localNotification.setBody(jsonObject.getString("body"));
localNotification.setLargeBody(jsonObject.getString("largeBody"));
localNotification.setSummaryText(jsonObject.getString("summaryText"));
localNotification.setActionTypeId(jsonObject.getString("actionTypeId"));
localNotification.setGroup(jsonObject.getString("group"));
localNotification.setSound(jsonObject.getString("sound"));
localNotification.setTitle(jsonObject.getString("title"));
localNotification.setSmallIcon(jsonObject.getString("smallIcon"));
localNotification.setLargeIcon(jsonObject.getString("largeIcon"));
localNotification.setIconColor(jsonObject.getString("iconColor"));
localNotification.setAttachments(LocalNotificationAttachment.getAttachments(jsonObject));
localNotification.setGroupSummary(jsonObject.getBoolean("groupSummary", false));
localNotification.setChannelId(jsonObject.getString("channelId"));
JSObject schedule = jsonObject.getJSObject("schedule");
if (schedule != null) {
localNotification.setSchedule(new LocalNotificationSchedule(schedule));
}
localNotification.setExtra(jsonObject.getJSObject("extra"));
localNotification.setOngoing(jsonObject.getBoolean("ongoing", false));
localNotification.setAutoCancel(jsonObject.getBoolean("autoCancel", true));
try {
JSONArray inboxList = jsonObject.getJSONArray("inboxList");
if (inboxList != null) {
List<String> inboxStringList = new ArrayList<>();
for (int i = 0; i < inboxList.length(); i++) {
inboxStringList.add(inboxList.getString(i));
}
localNotification.setInboxList(inboxStringList);
}
} catch (Exception ex) {
}
return localNotification;
}
use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class LocalNotification method buildNotificationList.
/**
* Build list of the notifications from remote plugin call
*/
public static List<LocalNotification> buildNotificationList(PluginCall call) {
JSArray notificationArray = call.getArray("notifications");
if (notificationArray == null) {
call.reject("Must provide notifications array as notifications option");
return null;
}
List<LocalNotification> resultLocalNotifications = new ArrayList<>(notificationArray.length());
List<JSONObject> notificationsJson;
try {
notificationsJson = notificationArray.toList();
} catch (JSONException e) {
call.reject("Provided notification format is invalid");
return null;
}
for (JSONObject jsonNotification : notificationsJson) {
JSObject notification = null;
try {
notification = JSObject.fromJSONObject(jsonNotification);
} catch (JSONException e) {
call.reject("Invalid JSON object sent to NotificationPlugin", e);
return null;
}
try {
LocalNotification activeLocalNotification = buildNotificationFromJSObject(notification);
resultLocalNotifications.add(activeLocalNotification);
} catch (ParseException e) {
call.reject("Invalid date format sent to Notification plugin", e);
return null;
}
}
return resultLocalNotifications;
}
use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class LocalNotificationAttachment method getAttachments.
public static List<LocalNotificationAttachment> getAttachments(JSObject notification) {
List<LocalNotificationAttachment> attachmentsList = new ArrayList<>();
JSONArray attachments = null;
try {
attachments = notification.getJSONArray("attachments");
} catch (Exception e) {
}
if (attachments != null) {
for (int i = 0; i < attachments.length(); i++) {
LocalNotificationAttachment newAttachment = new LocalNotificationAttachment();
JSONObject jsonObject = null;
try {
jsonObject = attachments.getJSONObject(i);
} catch (JSONException e) {
}
if (jsonObject != null) {
JSObject jsObject = null;
try {
jsObject = JSObject.fromJSONObject(jsonObject);
} catch (JSONException e) {
}
newAttachment.setId(jsObject.getString("id"));
newAttachment.setUrl(jsObject.getString("url"));
try {
newAttachment.setOptions(jsObject.getJSONObject("options"));
} catch (JSONException e) {
}
attachmentsList.add(newAttachment);
}
}
}
return attachmentsList;
}
use of com.getcapacitor.JSObject in project capacitor-plugins by ionic-team.
the class LocalNotificationSchedule method buildOnElement.
private void buildOnElement(JSObject schedule) {
JSObject onJson = schedule.getJSObject("on");
if (onJson != null) {
this.on = new DateMatch();
on.setYear(onJson.getInteger("year"));
on.setMonth(onJson.getInteger("month"));
on.setDay(onJson.getInteger("day"));
on.setWeekday(onJson.getInteger("weekday"));
on.setHour(onJson.getInteger("hour"));
on.setMinute(onJson.getInteger("minute"));
on.setSecond(onJson.getInteger("second"));
}
}
Aggregations