Search in sources :

Example 11 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode 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)

Example 12 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.

the class GoogleAccountLoader method load.

@Override
public void load(final CredentialsListener listener) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(TranSappApplication.getAppContext().getString(R.string.server_client_id)).build();
    final GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(TranSappApplication.getAppContext()).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
    mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

        @Override
        public void onConnected(@Nullable Bundle bundle) {
            OptionalPendingResult<GoogleSignInResult> pendingResult = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
            if (pendingResult.isDone()) {
                loadDataFromSignInResult(pendingResult.get(), listener, mGoogleApiClient);
            } else {
                pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {

                    @Override
                    public void onResult(@NonNull GoogleSignInResult result) {
                        if (result.isSuccess()) {
                            loadDataFromSignInResult(result, listener, mGoogleApiClient);
                        } else {
                            listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
                        }
                    }
                }, 5000, TimeUnit.MILLISECONDS);
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
        }
    });
    mGoogleApiClient.connect();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) ResultCallback(com.google.android.gms.common.api.ResultCallback) Bundle(android.os.Bundle) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) OptionalPendingResult(com.google.android.gms.common.api.OptionalPendingResult) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult) NonNull(android.support.annotation.NonNull) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions)

Example 13 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.

the class GoogleAccountLoginner method handleSignInResult.

private void handleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        GoogleDataManager manager = new GoogleDataManager();
        manager.getCredentials(listener, acct, mGoogleApiClient);
    } else {
        listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
        mGoogleApiClient.stopAutoManage(compatActivity.getActivity());
        mGoogleApiClient.disconnect();
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)

Aggregations

ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)13 SocialMediaAccount (cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount)4 Intent (android.content.Intent)3 View (android.view.View)3 CredentialsListener (cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)3 AccessToken (com.facebook.AccessToken)3 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 CloseSessionDialog (cl.smartcities.isci.transportinspector.dialogs.CloseSessionDialog)2 AccountLogOutListener (cl.smartcities.isci.transportinspector.gamification.ui.listener.AccountLogOutListener)2 Request (cl.smartcities.isci.transportinspector.serverConnection.requests.Request)2 LoginRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LoginRequest)2 LogoutRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LogoutRequest)2 AccessTokenTracker (com.facebook.AccessTokenTracker)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 AvatarView (agency.tango.android.avatarview.views.AvatarView)1 ProgressDialog (android.app.ProgressDialog)1 NonNull (android.support.annotation.NonNull)1 EditText (android.widget.EditText)1