Search in sources :

Example 1 with WebAppPinStatusListener

use of com.connectsdk.service.sessions.WebAppSession.WebAppPinStatusListener in project butter-android by butterproject.

the class WebOSTVService method isWebAppPinned.

private ServiceCommand<WebAppPinStatusListener> isWebAppPinned(boolean isSubscription, String webAppId, final WebAppPinStatusListener listener) {
    if (webAppId == null || webAppId.length() == 0) {
        if (listener != null) {
            listener.onError(new ServiceCommandError(-1, "You must provide a valid web app id", null));
        }
        return null;
    }
    String uri = "ssap://webapp/isWebAppPinned";
    JSONObject payload = new JSONObject();
    try {
        payload.put("webAppId", webAppId);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(final Object response) {
            JSONObject obj = (JSONObject) response;
            boolean status = obj.optBoolean("pinned");
            if (listener != null) {
                listener.onSuccess(status);
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<WebAppPinStatusListener> request;
    if (isSubscription)
        request = new URLServiceSubscription<WebAppPinStatusListener>(this, uri, payload, true, responseListener);
    else
        request = new ServiceCommand<WebAppPinStatusListener>(this, uri, payload, true, responseListener);
    request.send();
    return request;
}
Also used : WebAppPinStatusListener(com.connectsdk.service.sessions.WebAppSession.WebAppPinStatusListener) JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Aggregations

ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)1 ServiceCommand (com.connectsdk.service.command.ServiceCommand)1 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)1 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)1 WebAppPinStatusListener (com.connectsdk.service.sessions.WebAppSession.WebAppPinStatusListener)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1