Search in sources :

Example 1 with KindOfAccess

use of com.waz.api.KindOfAccess in project wire-android by wireapp.

the class AppEntryStore method resendPhone.

@Override
public void resendPhone(final SuccessCallback successCallback, final ErrorCallback errorCallback) {
    boolean isEntryPointPhoneSignIn = entryPoint == AppEntryState.PHONE_SIGN_IN;
    final boolean isEntryPointPhoneRegister = entryPoint == AppEntryState.PHONE_REGISTER;
    boolean isEntryPointEmailSignIn = entryPoint == AppEntryState.EMAIL_SIGN_IN;
    if (isEntryPointPhoneSignIn) {
        zMessagingApi.requestPhoneConfirmationCode(countryCode + phone, KindOfAccess.LOGIN, new ZMessagingApi.PhoneConfirmationCodeRequestListener() {

            @Override
            public void onConfirmationCodeSent(KindOfAccess kindOfAccess) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.resent(PhoneVerification.Context.SIGN_IN));
                successCallback.onSuccess();
            }

            @Override
            public void onPasswordExists(KindOfAccess kindOfAccess) {
            }

            @Override
            public void onConfirmationCodeSendingFailed(KindOfAccess kindOfAccess, int errorCode, String message, String label) {
                if (AppEntryError.PHONE_PENDING_LOGIN.correspondsTo(errorCode, label)) {
                    errorCallback.onError(AppEntryError.PHONE_PENDING_LOGIN);
                } else if (AppEntryError.PHONE_BUDGET_EXHAUSTED.correspondsTo(errorCode, label)) {
                    errorCallback.onError(AppEntryError.PHONE_BUDGET_EXHAUSTED);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
            }
        });
    } else if (isEntryPointPhoneRegister || isEntryPointEmailSignIn) {
        zMessagingApi.requestPhoneConfirmationCode(countryCode + phone, KindOfAccess.REGISTRATION, new ZMessagingApi.PhoneConfirmationCodeRequestListener() {

            @Override
            public void onConfirmationCodeSent(KindOfAccess kindOfAccess) {
                if (isEntryPointPhoneRegister) {
                    appEntryStateCallback.tagAppEntryEvent(new ResentPhoneVerificationEvent(OutcomeAttribute.SUCCESS, "", getPhoneRegistrationContext()));
                } else {
                    appEntryStateCallback.tagAppEntryEvent(PhoneVerification.resent(PhoneVerification.Context.POST_LOGIN));
                }
                successCallback.onSuccess();
            }

            @Override
            public void onPasswordExists(KindOfAccess kindOfAccess) {
            }

            @Override
            public void onConfirmationCodeSendingFailed(KindOfAccess kindOfAccess, int errorCode, String message, String label) {
                if (isEntryPointPhoneRegister) {
                    appEntryStateCallback.tagAppEntryEvent(new ResentPhoneVerificationEvent(OutcomeAttribute.FAIL, String.valueOf(errorCode), registrationEventContext));
                } else {
                    appEntryStateCallback.tagAppEntryEvent(PhoneVerification.codeRequestErrorSignIn());
                }
                if (AppEntryError.PHONE_BUDGET_EXHAUSTED.correspondsTo(errorCode, label)) {
                    errorCallback.onError(AppEntryError.PHONE_BUDGET_EXHAUSTED);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
            }
        });
    }
}
Also used : ResentPhoneVerificationEvent(com.waz.zclient.core.controllers.tracking.events.registration.ResentPhoneVerificationEvent) ZMessagingApi(com.waz.api.ZMessagingApi) KindOfAccess(com.waz.api.KindOfAccess)

Example 2 with KindOfAccess

use of com.waz.api.KindOfAccess in project wire-android by wireapp.

the class AppEntryStore method triggerVerificationCodeCallToUser.

@Override
public void triggerVerificationCodeCallToUser(final SuccessCallback successCallback, final ErrorCallback errorCallback) {
    final boolean isEntryPointPhoneRegister = entryPoint == AppEntryState.PHONE_REGISTER;
    boolean isEntryPointPhoneSignIn = entryPoint == AppEntryState.PHONE_SIGN_IN;
    KindOfAccess kindOfAccess = KindOfAccess.REGISTRATION;
    if (isEntryPointPhoneSignIn) {
        kindOfAccess = KindOfAccess.LOGIN;
    }
    zMessagingApi.requestPhoneConfirmationCall(countryCode + phone, kindOfAccess, new ZMessagingApi.PhoneConfirmationCodeRequestListener() {

        @Override
        public void onConfirmationCodeSent(KindOfAccess kindOfAccess) {
            if (isEntryPointPhoneRegister) {
                appEntryStateCallback.tagAppEntryEvent(new RequestedPhoneVerificationCallEvent(OutcomeAttribute.SUCCESS, "", getPhoneRegistrationContext()));
            }
            successCallback.onSuccess();
        }

        @Override
        public void onPasswordExists(KindOfAccess kindOfAccess) {
        }

        @Override
        public void onConfirmationCodeSendingFailed(KindOfAccess kindOfAccess, int errorCode, String message, String label) {
            if (isEntryPointPhoneRegister) {
                appEntryStateCallback.tagAppEntryEvent(new RequestedPhoneVerificationCallEvent(OutcomeAttribute.FAIL, "", getPhoneRegistrationContext()));
            }
            if (AppEntryError.PHONE_BUDGET_EXHAUSTED.correspondsTo(errorCode, label)) {
                errorCallback.onError(AppEntryError.PHONE_BUDGET_EXHAUSTED);
            } else {
                errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
            }
        }
    });
}
Also used : ZMessagingApi(com.waz.api.ZMessagingApi) KindOfAccess(com.waz.api.KindOfAccess) RequestedPhoneVerificationCallEvent(com.waz.zclient.core.controllers.tracking.events.registration.RequestedPhoneVerificationCallEvent)

Example 3 with KindOfAccess

use of com.waz.api.KindOfAccess in project wire-android by wireapp.

the class VerifyPhoneNumberPreferenceFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final String number = PhoneNumberUtils.formatNumber(getArguments().getString(ARG_PHONE, ""));
    final View view = inflater.inflate(R.layout.fragment_preference_phone_number_verification, container, false);
    final TextInputLayout verificationCodeInputLayout = ViewUtils.getView(view, R.id.til__verification_code);
    verificationCodeInputLayout.setErrorEnabled(true);
    final View backButton = ViewUtils.getView(view, R.id.tv__back_button);
    backButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    final View okButton = ViewUtils.getView(view, R.id.tv__ok_button);
    okButton.setEnabled(false);
    okButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String code = getVerificationCode();
            getStoreFactory().getProfileStore().submitCode(number, code, new ZMessagingApi.PhoneNumberVerificationListener() {

                @Override
                public void onVerified(KindOfVerification kindOfVerification) {
                    dismiss();
                }

                @Override
                public void onVerificationFailed(KindOfVerification kindOfVerification, int errorCode, String message, String label) {
                    if (AppEntryError.PHONE_INVALID_REGISTRATION_CODE.correspondsTo(errorCode, label)) {
                        verificationCodeInputLayout.setError(getString(AppEntryError.PHONE_INVALID_REGISTRATION_CODE.headerResource));
                    } else {
                        verificationCodeInputLayout.setError(getString(AppEntryError.PHONE_REGISTER_GENERIC_ERROR.headerResource));
                    }
                }
            });
        }
    });
    final TextView changeNumberButton = ViewUtils.getView(view, R.id.tv__change_number_button);
    changeNumberButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getContainer() == null) {
                return;
            }
            dismiss();
            getContainer().changePhoneNumber(number);
        }
    });
    final TextView resendButton = ViewUtils.getView(view, R.id.tv__resend_button);
    resendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            resendButton.animate().alpha(0f).start();
            getStoreFactory().getProfileStore().resendPhoneVerificationCode(number, new ZMessagingApi.PhoneConfirmationCodeRequestListener() {

                @Override
                public void onConfirmationCodeSent(KindOfAccess kindOfAccess) {
                    resendButton.animate().alpha(1f).start();
                }

                @Override
                public void onPasswordExists(KindOfAccess kindOfAccess) {
                }

                @Override
                public void onConfirmationCodeSendingFailed(KindOfAccess kindOfAccess, int code, String message, String label) {
                    resendButton.animate().alpha(1f).start();
                    AppEntryUtil.showErrorDialog(getActivity(), AppEntryError.PHONE_REGISTER_GENERIC_ERROR, null);
                }
            });
        }
    });
    final TextView verificationDescription = ViewUtils.getView(view, R.id.tv__verification_description);
    verificationDescription.setText(getString(R.string.pref__account_action__phone_verification__description, number));
    final EditText firstNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__1);
    final EditText secondNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__2);
    final EditText thirdNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__3);
    final EditText fourthNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__4);
    final EditText fifthNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__5);
    final EditText sixthNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__6);
    textBoxes = new LinkedList<>(Arrays.asList(firstNumberEditText, secondNumberEditText, thirdNumberEditText, fourthNumberEditText, fifthNumberEditText, sixthNumberEditText));
    for (int i = 0; i < textBoxes.size(); i++) {
        final EditText textBox = textBoxes.get(i);
        final int finalI = i;
        textBox.setTypeface(TypefaceUtils.getTypeface(getString(R.string.wire__typeface__bold)));
        textBox.addTextChangedListener(new OnTextChangedListener() {

            @Override
            public void afterTextChanged(Editable s) {
                final String val = textBox.getText().toString().trim();
                final char c;
                if (TextUtils.isEmpty(val)) {
                    c = ' ';
                } else {
                    c = val.charAt(0);
                }
                verificationCode[finalI] = c;
                final boolean wasDelete = c == ' ';
                if (!jumpToNextEmptyTextBox(wasDelete)) {
                    okButton.setEnabled(true);
                    if (finalI == textBoxes.size()) {
                        okButton.requestFocus();
                    }
                } else {
                    okButton.setEnabled(false);
                }
            }
        });
    }
    return view;
}
Also used : EditText(android.widget.EditText) OnTextChangedListener(com.waz.zclient.pages.main.profile.views.OnTextChangedListener) KindOfVerification(com.waz.api.KindOfVerification) KindOfAccess(com.waz.api.KindOfAccess) View(android.view.View) TextView(android.widget.TextView) Editable(android.text.Editable) TextView(android.widget.TextView) TextInputLayout(android.support.design.widget.TextInputLayout) Nullable(android.support.annotation.Nullable)

Aggregations

KindOfAccess (com.waz.api.KindOfAccess)3 ZMessagingApi (com.waz.api.ZMessagingApi)2 Nullable (android.support.annotation.Nullable)1 TextInputLayout (android.support.design.widget.TextInputLayout)1 Editable (android.text.Editable)1 View (android.view.View)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 KindOfVerification (com.waz.api.KindOfVerification)1 RequestedPhoneVerificationCallEvent (com.waz.zclient.core.controllers.tracking.events.registration.RequestedPhoneVerificationCallEvent)1 ResentPhoneVerificationEvent (com.waz.zclient.core.controllers.tracking.events.registration.ResentPhoneVerificationEvent)1 OnTextChangedListener (com.waz.zclient.pages.main.profile.views.OnTextChangedListener)1