Search in sources :

Example 1 with SocialMediaAccount

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;
}
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 SocialMediaAccount

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();
    }
}
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 SocialMediaAccount

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();
        }
    });
}
Also used : SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) SocialAccountLoaderManager(cl.smartcities.isci.transportinspector.gamification.SocialAccountLoaderManager)

Example 4 with SocialMediaAccount

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;
}
Also used : EditText(android.widget.EditText) SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) TranSappAccount(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount) AvatarView(agency.tango.android.avatarview.views.AvatarView) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) ProgressDialog(android.app.ProgressDialog) AvatarView(agency.tango.android.avatarview.views.AvatarView) View(android.view.View) AccountLogInListener(cl.smartcities.isci.transportinspector.gamification.ui.listener.AccountLogInListener)

Example 5 with SocialMediaAccount

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();
}
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

SocialMediaAccount (cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount)5 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)4 CredentialsListener (cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)3 View (android.view.View)2 AvatarView (agency.tango.android.avatarview.views.AvatarView)1 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 SocialAccountLoaderManager (cl.smartcities.isci.transportinspector.gamification.SocialAccountLoaderManager)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 TranSappAccount (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount)1 AccountLogInListener (cl.smartcities.isci.transportinspector.gamification.ui.listener.AccountLogInListener)1 AccessToken (com.facebook.AccessToken)1 AccessTokenTracker (com.facebook.AccessTokenTracker)1