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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations