use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode 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.ServerStatusCode 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.ServerStatusCode in project androidApp by InspectorIncognito.
the class FacebookAccountLoader method load.
@Override
public void load(final CredentialsListener listener) {
Log.d(TAG, "Loading account");
boolean hasFacebookLoggedIn = TranSappApplication.getAppSharedPreferences().getBoolean(TranSappApplication.getAppContext().getString(R.string.facebook_log_in), false);
if (!hasFacebookLoggedIn) {
Log.d(TAG, "First time login");
listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
return;
}
if (AccessToken.getCurrentAccessToken() != null) {
Log.d(TAG, "loadDataFromToken");
dataManager.getCredentials(listener);
return;
}
final Timer timer = new Timer();
final AccessTokenTracker tracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
timer.cancel();
stopTracking();
if (currentAccessToken == null) {
Log.d(TAG, "Facebook logged out");
listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
} else {
Log.d(TAG, "Facebook logged in");
dataManager.getCredentials(listener);
}
}
};
Log.d(TAG, "Starting tracker");
tracker.startTracking();
timer.schedule(new TimerTask() {
@Override
public void run() {
tracker.stopTracking();
Log.d(TAG, "Time up");
listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
}
}, 5000);
}
use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.
the class NicknameFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_account_nickname_fragment, container, false);
AvatarView userPicture = view.findViewById(R.id.user_image);
final SocialMediaAccount account = SocialMediaAccount.getCurrentAccount();
if (account == null) {
getActivity().finish();
return view;
}
account.loadImage(userPicture);
View submitButton = view.findViewById(R.id.submit_button);
final EditText nicknameEditText = view.findViewById(R.id.nickname_edit_text);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String nickname = nicknameEditText.getText().toString();
if (nickname.length() == 0) {
Toast.makeText(getContext(), "Debes ingresar un nickname", Toast.LENGTH_SHORT).show();
} else if (nickname.length() > 30) {
Toast.makeText(getContext(), "Ingresa un nick con menos de 30 caracteres", Toast.LENGTH_SHORT).show();
} else {
final ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Iniciando Sesión");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
TranSappAccountManager.loginWithTransapp(new AccountLogInListener() {
@Override
public void onAccountReady(TranSappAccount account) {
loginCallback.onTranSappLogin();
dialog.dismiss();
}
@Override
public void onError(ServerStatusCode error) {
dialog.dismiss();
if (error.getErrorCode() == ServerStatusCode.SERVER_ERROR || error.getErrorCode() == ServerStatusCode.INTERNAL_SERVER_ERROR || error.getErrorCode() == ServerStatusCode.PARSE_ERROR || error.getErrorCode() == ServerStatusCode.INVALID_SESSION_TOKEN) {
Toast.makeText(TranSappApplication.getAppContext(), "No se pudo iniciar sesión con TranSapp", Toast.LENGTH_SHORT).show();
}
}
}, nickname, account);
}
}
});
return view;
}
use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.
the class UserFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (super.onOptionsItemSelected(item)) {
return true;
}
switch(item.getItemId()) {
case R.id.action_settings:
startActivity(new Intent(this.getActivity(), AccountSettingsActivity.class));
return true;
case R.id.action_close_session:
CloseSessionDialog dialog = new CloseSessionDialog();
dialog.setListener(new CloseSessionDialog.OnButtonClickListener() {
@Override
public void onPositiveButtonClick() {
TranSappAccountManager.logOut(new AccountLogOutListener() {
@Override
public void onLoggedOut() {
callback.onLogout();
}
@Override
public void onError(ServerStatusCode error) {
// TODO(aantoine): show error message
callback.onLogout();
}
});
}
@Override
public void onNegativeButtonClick() {
}
});
dialog.show(getFragmentManager(), dialog.getClass().getSimpleName());
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Aggregations