Search in sources :

Example 1 with Request

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

the class ServerSentBus method createBus.

public static void createBus(final String licensePlate, final String service, final ConstructorListener listener) {
    Request.RequestListener<String> requestListener = new Request.RequestListener<String>() {

        @Override
        public void onRequestError() {
        }

        @Override
        public void onRequestResult(@NonNull String machineUUID) {
            int color = new ServiceHelper(TranSappApplication.getAppContext()).getColorId(service);
            listener.busConstructed(new ServerSentBus("left", service, "", machineUUID, "", licensePlate, 0, 0, 0, color, 0, "", new ArrayList<ServerSentEvent>()));
        }
    };
    Request<String> request = new GetUUIDRequest(requestListener, licensePlate);
    ServerController.sendRequest(request, null);
}
Also used : NonNull(android.support.annotation.NonNull) Request(cl.smartcities.isci.transportinspector.serverConnection.requests.Request) GetUUIDRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.GetUUIDRequest) ArrayList(java.util.ArrayList) ServiceHelper(cl.smartcities.isci.transportinspector.database.ServiceHelper) GetUUIDRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.GetUUIDRequest)

Example 2 with Request

use of cl.smartcities.isci.transportinspector.serverConnection.requests.Request 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)

Example 3 with Request

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

the class TranSappAccountManager method loginWithTransapp.

public static void loginWithTransapp(final AccountLogInListener outerListener, final String nickname, final SocialMediaAccount socialMediaAccount) {
    LoginRequest request = new LoginRequest(new Request.RequestListener<String>() {

        @Override
        public void onRequestError() {
            socialMediaAccount.logout();
            outerListener.onError(new ServerStatusCode(ServerStatusCode.SERVER_ERROR));
        }

        @Override
        public void onRequestResult(@NonNull String result) {
            Log.d(TAG, "Server responded");
            handleLoginResult(result, outerListener, nickname, socialMediaAccount);
        }
    }, nickname, socialMediaAccount);
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    ServerController.sendRequest(request, null);
}
Also used : 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) LoginRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LoginRequest)

Example 4 with Request

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

the class Bus method createBus.

private static void createBus(final String licensePlate, final String service, final ConstructorListener listener) {
    Request.RequestListener<String> requestListener = new Request.RequestListener<String>() {

        @Override
        public void onRequestError() {
        }

        @Override
        public void onRequestResult(@NonNull String response) {
            try {
                listener.busConstructed(new Bus(service, licensePlate, response));
            } catch (JSONException ignored) {
            }
        }
    };
    Request<String> request = new GetUUIDRequest(requestListener, licensePlate);
    ServerController.sendRequest(request, null);
}
Also used : ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus) NonNull(android.support.annotation.NonNull) Request(cl.smartcities.isci.transportinspector.serverConnection.requests.Request) GetUUIDRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.GetUUIDRequest) JSONException(org.json.JSONException) GetUUIDRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.GetUUIDRequest)

Example 5 with Request

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

the class UserFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    final TranSappAccount account = TranSappAccountManager.getCurrentAccount();
    if (account == null) {
        getActivity().finish();
        return;
    }
    RankingRequest request = new RankingRequest(new Request.RequestListener<Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>>>() {

        @Override
        public void onRequestError() {
        }

        @Override
        public void onRequestResult(@NonNull Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>> response) {
            ArrayList<TranSappUser> ranking = response.second;
            for (TranSappUser user : ranking) {
                if (user.userId.equals(account.currentUser.userId) && !account.currentUser.userId.equals("")) {
                    if (account.currentUser.globalRankingPosition != user.globalRankingPosition) {
                        account.updateRankingData(user.globalRankingPosition);
                        if (UserFragment.this.getActivity() != null && !UserFragment.this.getActivity().isFinishing()) {
                            updateUI();
                        }
                    }
                }
            }
        }
    }, account);
    ServerController.sendRequest(request, null);
}
Also used : TranSappAccount(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount) Request(cl.smartcities.isci.transportinspector.serverConnection.requests.Request) RankingRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest) TranSappUser(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser) ArrayList(java.util.ArrayList) RankingRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest) Pair(android.support.v4.util.Pair)

Aggregations

Request (cl.smartcities.isci.transportinspector.serverConnection.requests.Request)6 NonNull (android.support.annotation.NonNull)2 Pair (android.support.v4.util.Pair)2 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)2 GetUUIDRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.GetUUIDRequest)2 LoginRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LoginRequest)2 LogoutRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LogoutRequest)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 ServiceHelper (cl.smartcities.isci.transportinspector.database.ServiceHelper)1 TranSappAccount (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount)1 TranSappUser (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser)1 ServerSentBus (cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)1 RankingRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest)1 EvaluationQuestionRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.EvaluationQuestionRequest)1 JSONObject (org.json.JSONObject)1