use of cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener 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.CredentialsListener 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.CredentialsListener 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