Search in sources :

Example 1 with FirebaseNetworkException

use of com.google.firebase.FirebaseNetworkException in project FirebaseUI-Android by firebase.

the class CheckEmailFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mHandler = new ViewModelProvider(this).get(CheckEmailHandler.class);
    mHandler.init(getFlowParams());
    FragmentActivity activity = getActivity();
    if (!(activity instanceof CheckEmailListener)) {
        throw new IllegalStateException("Activity must implement CheckEmailListener");
    }
    mListener = (CheckEmailListener) activity;
    mHandler.getOperation().observe(getViewLifecycleOwner(), new ResourceObserver<User>(this, R.string.fui_progress_dialog_checking_accounts) {

        @Override
        protected void onSuccess(@NonNull User user) {
            String email = user.getEmail();
            String provider = user.getProviderId();
            mEmailEditText.setText(email);
            // noinspection ConstantConditions new user
            if (provider == null) {
                mListener.onNewUser(new User.Builder(EmailAuthProvider.PROVIDER_ID, email).setName(user.getName()).setPhotoUri(user.getPhotoUri()).build());
            } else if (provider.equals(EmailAuthProvider.PROVIDER_ID) || provider.equals(EMAIL_LINK_PROVIDER)) {
                mListener.onExistingEmailUser(user);
            } else {
                mListener.onExistingIdpUser(user);
            }
        }

        @Override
        protected void onFailure(@NonNull Exception e) {
            if (e instanceof FirebaseUiException && ((FirebaseUiException) e).getErrorCode() == ErrorCodes.DEVELOPER_ERROR) {
                mListener.onDeveloperFailure(e);
            }
            if (e instanceof FirebaseNetworkException) {
                Snackbar.make(getView(), getString(R.string.fui_no_internet), Snackbar.LENGTH_SHORT).show();
            }
        // Otherwise just let the user enter their data
        }
    });
    if (savedInstanceState != null) {
        return;
    }
    // Check for email
    String email = getArguments().getString(ExtraConstants.EMAIL);
    if (!TextUtils.isEmpty(email)) {
        mEmailEditText.setText(email);
        validateAndProceed();
    } else if (getFlowParams().enableHints) {
        mHandler.fetchCredential();
    }
}
Also used : User(com.firebase.ui.auth.data.model.User) FirebaseNetworkException(com.google.firebase.FirebaseNetworkException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) FragmentActivity(androidx.fragment.app.FragmentActivity) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) ViewModelProvider(androidx.lifecycle.ViewModelProvider) FirebaseNetworkException(com.google.firebase.FirebaseNetworkException)

Aggregations

FragmentActivity (androidx.fragment.app.FragmentActivity)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)1 User (com.firebase.ui.auth.data.model.User)1 FirebaseNetworkException (com.google.firebase.FirebaseNetworkException)1