Search in sources :

Example 51 with JSObject

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;
}
Also used : JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject)

Example 52 with JSObject

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;
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) ParseException(java.text.ParseException)

Example 53 with JSObject

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;
}
Also used : JSONObject(org.json.JSONObject) JSArray(com.getcapacitor.JSArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) JSObject(com.getcapacitor.JSObject) ParseException(java.text.ParseException)

Example 54 with JSObject

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;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException)

Example 55 with JSObject

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"));
    }
}
Also used : JSObject(com.getcapacitor.JSObject)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4