Search in sources :

Example 1 with LogoutRequest

use of cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LogoutRequest in project androidApp by InspectorIncognito.

the class TranSappAccountManager method logOut.

public static void logOut(final AccountLogOutListener listener) {
    SocialAccountLoaderManager manager = new SocialAccountLoaderManager();
    manager.unloadAccount();
    if (account == null) {
        listener.onLoggedOut();
        return;
    }
    account.socialMediaAccount.logout();
    LogoutRequest request = new LogoutRequest(new Request.RequestListener<String>() {

        @Override
        public void onRequestError() {
            account = null;
            listener.onError(new ServerStatusCode(ServerStatusCode.SERVER_ERROR));
            listener.onLoggedOut();
        }

        @Override
        public void onRequestResult(@NonNull String result) {
            account = null;
            try {
                JSONObject data = new JSONObject(result);
                int status = data.getInt("status");
                if (status != ServerStatusCode.OK) {
                    listener.onError(new ServerStatusCode(status));
                }
            } catch (JSONException e) {
                e.printStackTrace();
                listener.onError(new ServerStatusCode(ServerStatusCode.PARSE_ERROR));
            }
            listener.onLoggedOut();
        }
    }, account);
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    ServerController.sendRequest(request, null);
}
Also used : JSONObject(org.json.JSONObject) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) Request(cl.smartcities.isci.transportinspector.serverConnection.requests.Request) LogoutRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LogoutRequest) LoginRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LoginRequest) JSONException(org.json.JSONException) LogoutRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LogoutRequest)

Aggregations

ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)1 Request (cl.smartcities.isci.transportinspector.serverConnection.requests.Request)1 LoginRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LoginRequest)1 LogoutRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LogoutRequest)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1