Search in sources :

Example 1 with GoogleLoginInfo

use of com.omkarmoghe.pokemap.models.login.GoogleLoginInfo in project Pokemap by omkarmoghe.

the class PokemapSharedPreferences method setLoginInfo.

@Override
public void setLoginInfo(LoginInfo loginInfo) {
    Log.d(TAG, "setLoginInfo: LoginInfo = " + loginInfo);
    clearLoginCredentials();
    if (loginInfo instanceof PtcLoginInfo) {
        Set<String> info = new HashSet<>();
        PtcLoginInfo ptc = (PtcLoginInfo) loginInfo;
        info.add(INFO_TOKEN + ptc.getToken());
        info.add(INFO_USERNAME + ptc.getUsername());
        info.add(INFO_PASSWORD + ptc.getPassword());
        sharedPreferences.edit().putStringSet(PTC_INFO_KEY, info).apply();
    }
    if (loginInfo instanceof GoogleLoginInfo) {
        Set<String> info = new HashSet<>();
        GoogleLoginInfo google = (GoogleLoginInfo) loginInfo;
        info.add(INFO_TOKEN + google.getToken());
        info.add(INFO_REFRESH + google.getRefreshToken());
        Log.d(TAG, "setLoginInfo: Googleinfo = " + info);
        sharedPreferences.edit().putStringSet(GOOGLE_INFO_KEY, info).apply();
    }
}
Also used : PtcLoginInfo(com.omkarmoghe.pokemap.models.login.PtcLoginInfo) GoogleLoginInfo(com.omkarmoghe.pokemap.models.login.GoogleLoginInfo) HashSet(java.util.HashSet)

Example 2 with GoogleLoginInfo

use of com.omkarmoghe.pokemap.models.login.GoogleLoginInfo in project Pokemap by omkarmoghe.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mNianticManager = NianticManager.getInstance();
    mGoogleManager = GoogleManager.getInstance();
    mPref = new PokemapSharedPreferences(this);
    setContentView(R.layout.activity_login);
    mNianticAuthListener = new NianticManager.AuthListener() {

        @Override
        public void authSuccessful() {
            finishLogin();
        }

        @Override
        public void authFailed(String message, String provider) {
            switch(provider) {
                case LoginInfo.PROVIDER_PTC:
                    showPTCLoginFailed();
                    break;
                case LoginInfo.PROVIDER_GOOGLE:
                    showGoogleLoginFailed();
                    break;
            }
            Log.d(TAG, "authFailed() called with: message = [" + message + "]");
        }
    };
    mNianticLoginListener = new NianticManager.LoginListener() {

        @Override
        public void authSuccessful(String authToken) {
            Log.d(TAG, "authSuccessful() called with: authToken = [" + authToken + "]");
            PtcLoginInfo info = new PtcLoginInfo(authToken, mUsernameView.getText().toString(), mPasswordView.getText().toString());
            mPref.setLoginInfo(info);
            mNianticManager.setLoginInfo(LoginActivity.this, info, mNianticAuthListener);
        }

        @Override
        public void authFailed(String message) {
            Log.e(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
            showPTCLoginFailed();
        }
    };
    mGoogleLoginListener = new GoogleManager.LoginListener() {

        @Override
        public void authSuccessful(String authToken, String refreshToken) {
            GoogleLoginInfo info = new GoogleLoginInfo(authToken, refreshToken);
            Log.d(TAG, "authSuccessful() called with: authToken = [" + authToken + "]");
            mPref.setLoginInfo(info);
            mNianticManager.setLoginInfo(LoginActivity.this, info, mNianticAuthListener);
        }

        @Override
        public void authFailed(String message) {
            Log.d(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
            showGoogleLoginFailed();
        }

        @Override
        public void authRequested(GoogleService.AuthRequest body) {
        //Do nothing
        }
    };
    findViewById(R.id.txtDisclaimer).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(LoginActivity.this).setTitle(getString(R.string.login_warning_title)).setMessage(Html.fromHtml(getString(R.string.login_warning))).setPositiveButton(android.R.string.ok, null).show();
        }
    });
    // Set up the triggerAutoLogin form.
    mUsernameView = (AutoCompleteTextView) findViewById(R.id.username);
    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                validatePTCLoginForm();
                return true;
            }
            return false;
        }
    });
    LoginInfo loginInfo = mPref.getLoginInfo();
    if (loginInfo != null && loginInfo instanceof PtcLoginInfo) {
        mUsernameView.setText(((PtcLoginInfo) loginInfo).getUsername());
        mPasswordView.setText(((PtcLoginInfo) loginInfo).getPassword());
    }
    Button signInButton = (Button) findViewById(R.id.email_sign_in_button);
    signInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            validatePTCLoginForm();
        }
    });
    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);
    SignInButton signInButtonGoogle = (SignInButton) findViewById(R.id.sign_in_button);
    signInButtonGoogle.setSize(SignInButton.SIZE_WIDE);
    signInButtonGoogle.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            GoogleAuthActivity.startForResult(LoginActivity.this, REQUEST_USER_AUTH);
        }
    });
    triggerAutoLogin();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LoginInfo(com.omkarmoghe.pokemap.models.login.LoginInfo) PtcLoginInfo(com.omkarmoghe.pokemap.models.login.PtcLoginInfo) GoogleLoginInfo(com.omkarmoghe.pokemap.models.login.GoogleLoginInfo) PtcLoginInfo(com.omkarmoghe.pokemap.models.login.PtcLoginInfo) GoogleLoginInfo(com.omkarmoghe.pokemap.models.login.GoogleLoginInfo) PokemapSharedPreferences(com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) SignInButton(com.google.android.gms.common.SignInButton) NianticManager(com.omkarmoghe.pokemap.controllers.net.NianticManager) Button(android.widget.Button) SignInButton(com.google.android.gms.common.SignInButton) GoogleService(com.omkarmoghe.pokemap.controllers.net.GoogleService) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) GoogleManager(com.omkarmoghe.pokemap.controllers.net.GoogleManager)

Aggregations

GoogleLoginInfo (com.omkarmoghe.pokemap.models.login.GoogleLoginInfo)2 PtcLoginInfo (com.omkarmoghe.pokemap.models.login.PtcLoginInfo)2 AlertDialog (android.support.v7.app.AlertDialog)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 SignInButton (com.google.android.gms.common.SignInButton)1 PokemapSharedPreferences (com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences)1 GoogleManager (com.omkarmoghe.pokemap.controllers.net.GoogleManager)1 GoogleService (com.omkarmoghe.pokemap.controllers.net.GoogleService)1 NianticManager (com.omkarmoghe.pokemap.controllers.net.NianticManager)1 LoginInfo (com.omkarmoghe.pokemap.models.login.LoginInfo)1 HashSet (java.util.HashSet)1