Search in sources :

Example 1 with KindOfVerification

use of com.waz.api.KindOfVerification 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)

Example 2 with KindOfVerification

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

the class AppEntryStore method submitCode.

@Override
public void submitCode(String phoneVerificationCode, final ErrorCallback errorCallback) {
    setAndStorePhoneVerificationCode(phoneVerificationCode);
    if (entryPoint == AppEntryState.PHONE_REGISTER) {
        zMessagingApi.verifyPhoneNumber(countryCode + phone, phoneVerificationCode, KindOfVerification.PREVERIFY_ON_REGISTRATION, new ZMessagingApi.PhoneNumberVerificationListener() {

            @Override
            public void onVerified(KindOfVerification kindOfVerification) {
                appEntryStateCallback.tagAppEntryEvent(new VerifiedPhoneEvent(OutcomeAttribute.SUCCESS, "", "", getPhoneRegistrationContext()));
                setState(AppEntryState.PHONE_SET_NAME);
            }

            @Override
            public void onVerificationFailed(KindOfVerification kindOfVerification, int errorCode, String message, String label) {
                appEntryStateCallback.tagAppEntryEvent(new VerifiedPhoneEvent(OutcomeAttribute.FAIL, String.valueOf(errorCode), message + "; " + label, getPhoneRegistrationContext()));
                if (AppEntryError.PHONE_INVALID_REGISTRATION_CODE.correspondsTo(errorCode, label)) {
                    errorCallback.onError(AppEntryError.PHONE_INVALID_REGISTRATION_CODE);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
            }
        });
    } else if (entryPoint == AppEntryState.PHONE_SIGN_IN) {
        ignoreSelfUpdates = true;
        zMessagingApi.login(CredentialsFactory.phoneCredentials(countryCode + phone, phoneVerificationCode), new LoginListener() {

            @Override
            public void onSuccess(Self self) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.success(PhoneVerification.Context.SIGN_IN));
                appEntryStateCallback.tagAppEntryEvent(new LoggedInEvent(true));
                bindSelf(self);
                setState(AppEntryState.PHONE_SIGNED_IN);
                ignoreSelfUpdates = false;
            }

            @Override
            public void onFailed(int errorCode, String message, String label) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.error(PhoneVerification.Context.SIGN_IN));
                if (AppEntryError.PHONE_INVALID_LOGIN_CODE.correspondsTo(errorCode, "")) {
                    errorCallback.onError(AppEntryError.PHONE_INVALID_LOGIN_CODE);
                } else if (AppEntryError.TOO_MANY_ATTEMPTS.correspondsTo(errorCode, "")) {
                    errorCallback.onError(AppEntryError.TOO_MANY_ATTEMPTS);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
                ignoreSelfUpdates = false;
            }
        });
    } else if (entryPoint == AppEntryState.EMAIL_SIGN_IN) {
        zMessagingApi.verifyPhoneNumber(countryCode + phone, phoneVerificationCode, KindOfVerification.VERIFY_ON_UPDATE, new ZMessagingApi.PhoneNumberVerificationListener() {

            @Override
            public void onVerified(KindOfVerification kindOfVerification) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.success(PhoneVerification.Context.POST_LOGIN));
                setState(AppEntryState.LOGGED_IN);
            }

            @Override
            public void onVerificationFailed(KindOfVerification kindOfVerification, int errorCode, String message, String label) {
                appEntryStateCallback.tagAppEntryEvent(PhoneVerification.error(PhoneVerification.Context.POST_LOGIN));
                if (AppEntryError.PHONE_INVALID_ADD_CODE.correspondsTo(errorCode, label)) {
                    errorCallback.onError(AppEntryError.PHONE_INVALID_ADD_CODE);
                } else {
                    errorCallback.onError(AppEntryError.PHONE_REGISTER_GENERIC_ERROR);
                }
            }
        });
    }
}
Also used : LoggedInEvent(com.waz.zclient.core.controllers.tracking.events.session.LoggedInEvent) ZMessagingApi(com.waz.api.ZMessagingApi) LoginListener(com.waz.api.LoginListener) KindOfVerification(com.waz.api.KindOfVerification) VerifiedPhoneEvent(com.waz.zclient.core.controllers.tracking.events.registration.VerifiedPhoneEvent) Self(com.waz.api.Self)

Aggregations

KindOfVerification (com.waz.api.KindOfVerification)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 KindOfAccess (com.waz.api.KindOfAccess)1 LoginListener (com.waz.api.LoginListener)1 Self (com.waz.api.Self)1 ZMessagingApi (com.waz.api.ZMessagingApi)1 VerifiedPhoneEvent (com.waz.zclient.core.controllers.tracking.events.registration.VerifiedPhoneEvent)1 LoggedInEvent (com.waz.zclient.core.controllers.tracking.events.session.LoggedInEvent)1 OnTextChangedListener (com.waz.zclient.pages.main.profile.views.OnTextChangedListener)1