Search in sources :

Example 1 with CredentialsListener

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;
}
Also used : SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) GoogleAccountLoginner(cl.smartcities.isci.transportinspector.gamification.socialAccount.google.GoogleAccountLoginner) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) FacebookAccountLoginner(cl.smartcities.isci.transportinspector.gamification.socialAccount.facebook.FacebookAccountLoginner) CredentialsListener(cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)

Example 2 with CredentialsListener

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();
    }
}
Also used : SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) FacebookAccountLoader(cl.smartcities.isci.transportinspector.gamification.socialAccount.facebook.FacebookAccountLoader) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) GoogleAccountLoader(cl.smartcities.isci.transportinspector.gamification.socialAccount.google.GoogleAccountLoader) SocialAccountLoader(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialAccountLoader) CredentialsListener(cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)

Example 3 with CredentialsListener

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();
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) AccessToken(com.facebook.AccessToken) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) CredentialsListener(cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)

Aggregations

CredentialsListener (cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)3 SocialMediaAccount (cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount)3 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)3 Intent (android.content.Intent)1 View (android.view.View)1 TextView (android.widget.TextView)1 SocialAccountLoader (cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialAccountLoader)1 FacebookAccountLoader (cl.smartcities.isci.transportinspector.gamification.socialAccount.facebook.FacebookAccountLoader)1 FacebookAccountLoginner (cl.smartcities.isci.transportinspector.gamification.socialAccount.facebook.FacebookAccountLoginner)1 GoogleAccountLoader (cl.smartcities.isci.transportinspector.gamification.socialAccount.google.GoogleAccountLoader)1 GoogleAccountLoginner (cl.smartcities.isci.transportinspector.gamification.socialAccount.google.GoogleAccountLoginner)1 AccessToken (com.facebook.AccessToken)1 AccessTokenTracker (com.facebook.AccessTokenTracker)1