Search in sources :

Example 1 with RadarTripOptions

use of io.radar.sdk.RadarTripOptions in project flutter-radar by radarlabs.

the class RadarFlutterPlugin method startTrip.

public void startTrip(MethodCall call, Result result) throws JSONException {
    HashMap tripOptionsMap = (HashMap) call.arguments;
    JSONObject tripOptionsJson = jsonForMap(tripOptionsMap);
    RadarTripOptions tripOptions = RadarTripOptions.fromJson(tripOptionsJson);
    Radar.startTrip(tripOptions);
    result.success(true);
}
Also used : RadarTripOptions(io.radar.sdk.RadarTripOptions) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap)

Example 2 with RadarTripOptions

use of io.radar.sdk.RadarTripOptions in project capacitor-radar by radarlabs.

the class RadarPlugin method updateTrip.

@PluginMethod
public void updateTrip(PluginCall call) {
    JSObject optionsObj = call.getObject("options");
    JSONObject optionsJson = RadarPlugin.jsonObjectForJSObject(optionsObj);
    if (optionsJson == null) {
        call.reject("options is required");
        return;
    }
    RadarTripOptions options = RadarTripOptions.fromJson(optionsJson);
    RadarTrip.RadarTripStatus status = RadarTrip.RadarTripStatus.UNKNOWN;
    if (call.hasOption("status")) {
        String statusStr = call.getString("status");
        if (statusStr.equals("STARTED") || statusStr.equals("started")) {
            status = RadarTrip.RadarTripStatus.STARTED;
        } else if (statusStr.equals("APPROACHING") || statusStr.equals("approaching")) {
            status = RadarTrip.RadarTripStatus.APPROACHING;
        } else if (statusStr.equals("ARRIVED") || statusStr.equals("arrived")) {
            status = RadarTrip.RadarTripStatus.ARRIVED;
        } else if (statusStr.equals("COMPLETED") || statusStr.equals("completed")) {
            status = RadarTrip.RadarTripStatus.COMPLETED;
        } else if (statusStr.equals("CANCELED") || statusStr.equals("canceled")) {
            status = RadarTrip.RadarTripStatus.CANCELED;
        }
    }
    Radar.updateTrip(options, status, new Radar.RadarTripCallback() {

        @Override
        public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
            JSObject ret = new JSObject();
            ret.put("status", status.toString());
            if (trip != null) {
                ret.put("trip", RadarPlugin.jsObjectForJSONObject(trip.toJson()));
            }
            if (events != null) {
                ret.put("events", RadarPlugin.jsArrayForArray(events));
            }
            call.resolve(ret);
        }
    });
}
Also used : RadarTripOptions(io.radar.sdk.RadarTripOptions) JSONObject(org.json.JSONObject) RadarEvent(io.radar.sdk.model.RadarEvent) Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) RadarTrip(io.radar.sdk.model.RadarTrip) PluginMethod(com.getcapacitor.PluginMethod)

Example 3 with RadarTripOptions

use of io.radar.sdk.RadarTripOptions in project capacitor-radar by radarlabs.

the class RadarPlugin method startTrip.

@PluginMethod()
public void startTrip(PluginCall call) {
    JSObject optionsObj = call.getObject("options");
    JSONObject optionsJson = RadarPlugin.jsonObjectForJSObject(optionsObj);
    if (optionsJson == null) {
        call.reject("options is required");
        return;
    }
    RadarTripOptions options = RadarTripOptions.fromJson(optionsJson);
    Radar.startTrip(options, new Radar.RadarTripCallback() {

        @Override
        public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
            JSObject ret = new JSObject();
            ret.put("status", status.toString());
            if (trip != null) {
                ret.put("trip", RadarPlugin.jsObjectForJSONObject(trip.toJson()));
            }
            if (events != null) {
                ret.put("events", RadarPlugin.jsArrayForArray(events));
            }
            call.resolve(ret);
        }
    });
}
Also used : RadarTripOptions(io.radar.sdk.RadarTripOptions) JSONObject(org.json.JSONObject) RadarEvent(io.radar.sdk.model.RadarEvent) Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) RadarTrip(io.radar.sdk.model.RadarTrip) PluginMethod(com.getcapacitor.PluginMethod)

Example 4 with RadarTripOptions

use of io.radar.sdk.RadarTripOptions in project flutter-radar by radarlabs.

the class RadarFlutterPlugin method getTripOptions.

public void getTripOptions(Result result) {
    RadarTripOptions tripOptions = Radar.getTripOptions();
    HashMap<String, Object> map = new Gson().fromJson(tripOptions.toJson().toString(), HashMap.class);
    result.success(map);
}
Also used : RadarTripOptions(io.radar.sdk.RadarTripOptions) Gson(com.google.gson.Gson) JSONObject(org.json.JSONObject)

Aggregations

RadarTripOptions (io.radar.sdk.RadarTripOptions)4 JSONObject (org.json.JSONObject)4 JSObject (com.getcapacitor.JSObject)2 PluginMethod (com.getcapacitor.PluginMethod)2 Radar (io.radar.sdk.Radar)2 RadarEvent (io.radar.sdk.model.RadarEvent)2 RadarTrip (io.radar.sdk.model.RadarTrip)2 Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1