Search in sources :

Example 1 with EmailValidator

use of com.nightonke.saver.util.EmailValidator in project CoCoin by Nightonke.

the class AccountBookSettingActivity method userRegister.

private void userRegister() {
    registerDialog = new MaterialDialog.Builder(this).title(R.string.go_register).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).customView(R.layout.dialog_user_register, true).build();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    registerDialogView = registerDialog.getCustomView();
    registerDialogButton = (CircularProgressButton) registerDialogView.findViewById(R.id.button);
    registerDialogButton.setTypeface(CoCoinUtil.GetTypeface());
    registerDialogButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            registerDialogButton.setProgress(1);
            registerDialog.setCancelable(false);
            // User register, a new user////////////////////////////////////////////////////////////////////////
            final User user = new User();
            // basic info
            user.setUsername(registerUserName.getText().toString());
            user.setPassword(registerPassword.getText().toString());
            user.setEmail(registerUserEmail.getText().toString());
            user.setAndroidId(CoCoinApplication.getAndroidId());
            if (BuildConfig.DEBUG)
                Log.d("CoCoin", "Android Id: " + user.getAndroidId());
            // settings info
            // user.setLogo();
            user.setIsMonthLimit(SettingManager.getInstance().getIsMonthLimit());
            user.setMonthLimit(SettingManager.getInstance().getMonthLimit());
            user.setIsColorRemind(SettingManager.getInstance().getIsColorRemind());
            user.setMonthWarning(SettingManager.getInstance().getMonthWarning());
            user.setRemindColor(SettingManager.getInstance().getRemindColor());
            user.setIsForbidden(SettingManager.getInstance().getIsForbidden());
            user.setAccountBookName(SettingManager.getInstance().getAccountBookName());
            user.setAccountBookPassword(SettingManager.getInstance().getPassword());
            // Todo store tag order
            user.setShowPicture(SettingManager.getInstance().getShowPicture());
            user.setIsHollow(SettingManager.getInstance().getIsHollow());
            user.setLogoObjectId("");
            user.signUp(CoCoinApplication.getAppContext(), new SaveListener() {

                @Override
                public void onSuccess() {
                    registerDialogButton.setProgress(0);
                    registerDialog.setCancelable(true);
                    registerDialogButton.setIdleText(getResourceString(R.string.register_complete));
                    // if register successfully/////////////////////////////////////////////////////////////////////////
                    SettingManager.getInstance().setLoggenOn(true);
                    SettingManager.getInstance().setUserName(registerUserName.getText().toString());
                    SettingManager.getInstance().setUserEmail(registerUserEmail.getText().toString());
                    SettingManager.getInstance().setUserPassword(registerPassword.getText().toString());
                    showToast(4, registerUserName.getText().toString());
                    // if login successfully////////////////////////////////////////////////////////////////////////////
                    user.login(CoCoinApplication.getAppContext(), new SaveListener() {

                        @Override
                        public void onSuccess() {
                            SettingManager.getInstance().setTodayViewInfoShouldChange(true);
                            updateViews();
                        // use a new method
                        //                                RecordManager.updateOldRecordsToServer();
                        }

                        @Override
                        public void onFailure(int code, String msg) {
                        // if login failed//////////////////////////////////////////////////////////////////////////////////
                        }
                    });
                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            if (registerDialog != null)
                                registerDialog.dismiss();
                            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
                        }
                    }, 500);
                }

                // if register failed///////////////////////////////////////////////////////////////////////////////
                @Override
                public void onFailure(int code, String msg) {
                    if (BuildConfig.DEBUG)
                        Log.d("CoCoin", "Register failed: " + msg);
                    String tip = getResourceString(R.string.network_disconnection);
                    if (msg.charAt(1) == 's')
                        tip = getResourceString(R.string.user_name_exist);
                    if (msg.charAt(0) == 'e')
                        tip = getResourceString(R.string.user_email_exist);
                    if (msg.charAt(1) == 'n')
                        tip = getResourceString(R.string.user_mobile_exist);
                    registerDialogButton.setIdleText(tip);
                    registerDialogButton.setProgress(0);
                    registerDialog.setCancelable(true);
                }
            });
        }
    });
    final MDButton positiveAction = registerDialog.getActionButton(DialogAction.POSITIVE);
    positiveAction.setEnabled(false);
    final EmailValidator emailValidator = new EmailValidator();
    TextView userNameTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_user_name_text);
    TextView userEmailTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_user_email_text);
    TextView userPasswordTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_password_text);
    userNameTV.setTypeface(CoCoinUtil.GetTypeface());
    userEmailTV.setTypeface(CoCoinUtil.GetTypeface());
    userPasswordTV.setTypeface(CoCoinUtil.GetTypeface());
    registerUserName = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_user_name);
    registerUserEmail = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_user_email);
    registerPassword = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_password);
    registerUserName.setTypeface(CoCoinUtil.GetTypeface());
    registerUserName.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
            registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
            if (emailValidator.validate(registerUserEmail.getText().toString())) {
                registerUserEmail.validate();
            } else {
                registerUserEmail.invalidate();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    registerUserEmail.setTypeface(CoCoinUtil.GetTypeface());
    registerUserEmail.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
            registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
            if (emailValidator.validate(registerUserEmail.getText().toString())) {
                registerUserEmail.validate();
            } else {
                registerUserEmail.invalidate();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    registerPassword.setTypeface(CoCoinUtil.GetTypeface());
    registerPassword.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
            registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
            if (emailValidator.validate(registerUserEmail.getText().toString())) {
                registerUserEmail.validate();
            } else {
                registerUserEmail.invalidate();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    registerDialog.show();
}
Also used : SaveListener(cn.bmob.v3.listener.SaveListener) MDButton(com.afollestad.materialdialogs.internal.MDButton) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) EmailValidator(com.nightonke.saver.util.EmailValidator) Handler(android.os.Handler) InputMethodManager(android.view.inputmethod.InputMethodManager) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) View(android.view.View) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) TextView(android.widget.TextView)

Aggregations

Handler (android.os.Handler)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 TextView (android.widget.TextView)1 BmobUser (cn.bmob.v3.BmobUser)1 SaveListener (cn.bmob.v3.listener.SaveListener)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 MDButton (com.afollestad.materialdialogs.internal.MDButton)1 User (com.nightonke.saver.model.User)1 RiseNumberTextView (com.nightonke.saver.ui.RiseNumberTextView)1 EmailValidator (com.nightonke.saver.util.EmailValidator)1 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)1 MaterialIconView (net.steamcrafted.materialiconlib.MaterialIconView)1