use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.
the class UserFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_account_user_fragment, container, false);
progressImage = view.findViewById(R.id.activity_account_user_fragment_level_progress_image);
userName = view.findViewById(R.id.activity_account_user_fragment_user_name);
score = view.findViewById(R.id.activity_account_user_fragment_user_score);
level = view.findViewById(R.id.activity_account_user_fragment_user_level);
userBusAvatarTitle = view.findViewById(R.id.user_bus_avatar_title);
levelBackground = view.findViewById(R.id.level_background);
levelName = view.findViewById(R.id.level_name);
rankingFrame = view.findViewById(R.id.ranking_frame);
rankingPosition = view.findViewById(R.id.ranking_position);
rankingButton = view.findViewById(R.id.ranking_layout);
rankingProgressBar = view.findViewById(R.id.ranking_progress_bar);
rankingProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.green_button), android.graphics.PorterDuff.Mode.SRC_IN);
View busPickerButton = view.findViewById(R.id.bus_layout);
userBusAvatarView = view.findViewById(R.id.user_bus_avatar);
View closeSessionButton = view.findViewById(R.id.close_session_button);
closeSessionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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());
}
});
View editButton = view.findViewById(R.id.edit_button);
editButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getActivity(), AccountSettingsActivity.class), USER_SETTINGS_CODE);
}
});
busPickerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getActivity(), AccountBusPickerActivity.class), USER_BUS_PICKER_CODE);
}
});
updateUI();
return view;
}
use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.
the class FacebookDataManager method getCredentials.
void getCredentials(final CredentialsListener listener) {
Log.d(TAG, "getUserData");
final AccessToken currentToken = AccessToken.getCurrentAccessToken();
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", null, HttpMethod.GET, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
Profile profile = Profile.getCurrentProfile();
String email = response.getJSONObject().getString("email");
String name = response.getJSONObject().getString("name");
String imageUri = profile.getProfilePictureUri(200, 200).toString();
SocialMediaCredentials credentials = new SocialMediaCredentials(currentToken.getToken(), currentToken.getUserId(), FACEBOOK_ACCOUNT, name, email, imageUri);
listener.onSuccess(new FacebookAccount(credentials));
} catch (JSONException | NullPointerException e) {
listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
Log.e(TAG, e.getMessage() == null ? "null message" : e.getMessage());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.
the class LoginFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_account_login_fragment, container, false);
facebookCallbackManager = CallbackManager.Factory.create();
googleCallbackManager = new GoogleAccountLoginner.CallbackManager();
facebookLoginView = view.findViewById(R.id.login_button);
googleLoginView = view.findViewById(R.id.google_signin_button);
loadingView = view.findViewById(R.id.loading_layout);
termsAndConditions = view.findViewById(R.id.terms_and_conditions);
termsAndConditions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.terms_and_conditions_url)));
startActivity(browserIntent);
}
});
// termsAndConditions.setMovementMethod(LinkMovementMethod.getInstance());
// termsAndConditions.setText(text);
final CredentialsListener listener = new CredentialsListener() {
@Override
public void onSuccess(SocialMediaAccount account) {
SocialMediaAccount.setCurrentAccount(account);
loginCallback.onSocialNetworkLogin();
}
@Override
public void onError(ServerStatusCode error) {
facebookLoginView.setClickable(true);
googleLoginView.setClickable(true);
if (error.getErrorCode() == ServerStatusCode.INVALID_USER) {
throw new IllegalStateException("Point of no return: There is no possible flow for this");
} else {
Toast.makeText(TranSappApplication.getAppContext(), "No se pudo iniciar sesiĆ³n", Toast.LENGTH_SHORT).show();
}
}
};
facebookLoginView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
facebookLoginView.setClickable(false);
googleLoginView.setClickable(false);
FacebookAccountLoginner loginner = new FacebookAccountLoginner(listener, LoginFragment.this);
loginner.login();
}
});
googleLoginView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
googleLoginView.setClickable(false);
facebookLoginView.setClickable(false);
GoogleAccountLoginner loginner = new GoogleAccountLoginner(listener, LoginFragment.this, googleCallbackManager);
loginner.login();
}
});
return view;
}
use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.
the class SocialAccountLoaderManager method loadAccount.
public void loadAccount(final LoaderInterface loaderInterface) {
String accountType = preferences.getString(accountTypeKey, accountTypeKeyNull);
CredentialsListener listener = new CredentialsListener() {
@Override
public void onSuccess(SocialMediaAccount account) {
String nickname = TranSappApplication.getAppSharedPreferences().getString(SAVED_NICKNAME, "");
loaderInterface.onLoad(account, nickname);
}
@Override
public void onError(ServerStatusCode error) {
loaderInterface.onError();
}
};
switch(accountType) {
case SocialMediaAccount.FACEBOOK_ACCOUNT:
SocialAccountLoader facebookAccountLoader = new FacebookAccountLoader();
facebookAccountLoader.load(listener);
break;
case SocialMediaAccount.GOOGLE_ACCOUNT:
SocialAccountLoader googleAccountLoader = new GoogleAccountLoader();
googleAccountLoader.load(listener);
break;
default:
loaderInterface.onError();
}
}
use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.
the class TranSappAccountManager method handleLoginResult.
private static void handleLoginResult(String result, AccountLogInListener listener, String nickname, SocialMediaAccount socialMediaAccount) {
try {
JSONObject data = new JSONObject(result);
int status = data.getInt("status");
if (status == ServerStatusCode.OK) {
account = createAccountFromLoginResult(result, nickname, socialMediaAccount);
} else {
Log.d(TAG, "Server responded error code " + status);
socialMediaAccount.logout();
listener.onError(new ServerStatusCode(status));
return;
}
} catch (JSONException e) {
e.printStackTrace();
socialMediaAccount.logout();
Log.d(TAG, "Server respond parse error");
listener.onError(new ServerStatusCode(ServerStatusCode.PARSE_ERROR));
return;
}
listener.onAccountReady(account);
}
Aggregations