use of cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount 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.gamification.socialAccount.SocialMediaAccount 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.gamification.socialAccount.SocialMediaAccount in project androidApp by InspectorIncognito.
the class LoginStartTask method start.
@Override
public void start() {
SocialAccountLoaderManager manager = new SocialAccountLoaderManager();
manager.loadAccount(new SocialAccountLoaderManager.LoaderInterface() {
@Override
public void onLoad(SocialMediaAccount account, String nickname) {
TranSappAccountManager.loginWithTransapp(LoginStartTask.this, nickname, account);
}
@Override
public void onError() {
ready();
}
});
}
use of cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount 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.gamification.socialAccount.SocialMediaAccount in project androidApp by InspectorIncognito.
the class FacebookAccountLoginner method login.
@Override
public void login() {
Log.d(TAG, "Login Facebook Account");
final AccessTokenTracker tracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
Log.d(TAG, "onCurrentAccessTokenChanged");
this.stopTracking();
loginFragment.startLoading();
dataManager.getCredentials(new CredentialsListener() {
@Override
public void onSuccess(SocialMediaAccount account) {
loginFragment.stopLoading();
listener.onSuccess(account);
}
@Override
public void onError(ServerStatusCode error) {
loginFragment.stopLoading();
listener.onError(error);
}
});
}
};
Log.d(TAG, "Starting tracker");
tracker.startTracking();
LoginManager.getInstance().logInWithReadPermissions(loginFragment, Arrays.asList("email", "public_profile"));
TranSappApplication.getAppSharedPreferences().edit().putBoolean(TranSappApplication.getAppContext().getString(R.string.facebook_log_in), true).apply();
}
Aggregations