From 9c5f5b428ac1ed753c5795a77f62ada40e8797ad Mon Sep 17 00:00:00 2001 From: pokkst Date: Fri, 18 Nov 2022 15:58:15 -0600 Subject: [PATCH] Add password confirm text field --- .../onboarding/OnboardingFragment.java | 88 ++++++++++++++----- .../main/res/layout/fragment_onboarding.xml | 21 ++++- app/src/main/res/values/strings.xml | 2 + 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java b/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java index 41c8a81..efd8157 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java @@ -75,6 +75,16 @@ public class OnboardingFragment extends Fragment { }; private EditText walletProxyAddressEditText; private EditText walletProxyPortEditText; + private EditText walletPasswordEditText; + private EditText walletPasswordConfirmEditText; + private EditText walletSeedEditText; + private EditText walletRestoreHeightEditText; + private Button createWalletButton; + private TextView moreOptionsDropdownTextView; + private SwitchCompat torSwitch; + private ConstraintLayout proxySettingsLayout; + private ImageView moreOptionsChevronImageView; + private CheckBox seedOffsetCheckbox; @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -86,22 +96,41 @@ public class OnboardingFragment extends Fragment { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mViewModel = new ViewModelProvider(this).get(OnboardingViewModel.class); - EditText walletPasswordEditText = view.findViewById(R.id.wallet_password_edittext); - EditText walletSeedEditText = view.findViewById(R.id.wallet_seed_edittext); - EditText walletRestoreHeightEditText = view.findViewById(R.id.wallet_restore_height_edittext); - Button createWalletButton = view.findViewById(R.id.create_wallet_button); - TextView moreOptionsDropdownTextView = view.findViewById(R.id.advanced_settings_dropdown_textview); - ImageView moreOptionsChevronImageView = view.findViewById(R.id.advanced_settings_chevron_imageview); - SwitchCompat torSwitch = view.findViewById(R.id.tor_onboarding_switch); - ConstraintLayout proxySettingsLayout = view.findViewById(R.id.wallet_proxy_settings_layout); - CheckBox seedOffsetCheckbox = view.findViewById(R.id.seed_offset_checkbox); + walletPasswordEditText = view.findViewById(R.id.wallet_password_edittext); + walletPasswordConfirmEditText = view.findViewById(R.id.wallet_password_confirm_edittext); + walletSeedEditText = view.findViewById(R.id.wallet_seed_edittext); + walletRestoreHeightEditText = view.findViewById(R.id.wallet_restore_height_edittext); + createWalletButton = view.findViewById(R.id.create_wallet_button); + moreOptionsDropdownTextView = view.findViewById(R.id.advanced_settings_dropdown_textview); + moreOptionsChevronImageView = view.findViewById(R.id.advanced_settings_chevron_imageview); + torSwitch = view.findViewById(R.id.tor_onboarding_switch); + proxySettingsLayout = view.findViewById(R.id.wallet_proxy_settings_layout); + seedOffsetCheckbox = view.findViewById(R.id.seed_offset_checkbox); walletProxyAddressEditText = view.findViewById(R.id.wallet_proxy_address_edittext); walletProxyPortEditText = view.findViewById(R.id.wallet_proxy_port_edittext); seedOffsetCheckbox.setChecked(useOffset); + bindListeners(); + bindObservers(); + } + + private void bindObservers() { + mViewModel.showMoreOptions.observe(getViewLifecycleOwner(), show -> { + if (show) { + moreOptionsChevronImageView.setImageResource(R.drawable.ic_keyboard_arrow_up); + walletSeedEditText.setVisibility(View.VISIBLE); + walletRestoreHeightEditText.setVisibility(View.VISIBLE); + } else { + moreOptionsChevronImageView.setImageResource(R.drawable.ic_keyboard_arrow_down); + walletSeedEditText.setVisibility(View.GONE); + walletRestoreHeightEditText.setVisibility(View.GONE); + } + }); + } + + private void bindListeners() { moreOptionsDropdownTextView.setOnClickListener(view12 -> mViewModel.onMoreOptionsClicked()); moreOptionsChevronImageView.setOnClickListener(view12 -> mViewModel.onMoreOptionsClicked()); - seedOffsetCheckbox.setOnCheckedChangeListener((compoundButton, b) -> useOffset = b); createWalletButton.setOnClickListener(view1 -> { @@ -109,11 +138,32 @@ public class OnboardingFragment extends Fragment { ((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> { createOrImportWallet( walletPasswordEditText.getText().toString(), + walletPasswordConfirmEditText.getText().toString(), walletSeedEditText.getText().toString().trim(), walletRestoreHeightEditText.getText().toString().trim() ); }); }); + walletPasswordEditText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void afterTextChanged(Editable editable) { + String text = editable.toString(); + if (text.isEmpty()) { + walletPasswordConfirmEditText.setText(null); + walletPasswordConfirmEditText.setVisibility(View.GONE); + } else { + walletPasswordConfirmEditText.setVisibility(View.VISIBLE); + } + } + }); walletSeedEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { @@ -155,29 +205,21 @@ public class OnboardingFragment extends Fragment { mViewModel.updateProxy(((MoneroApplication)getActivity().getApplication())); }); - - mViewModel.showMoreOptions.observe(getViewLifecycleOwner(), show -> { - if (show) { - moreOptionsChevronImageView.setImageResource(R.drawable.ic_keyboard_arrow_up); - walletSeedEditText.setVisibility(View.VISIBLE); - walletRestoreHeightEditText.setVisibility(View.VISIBLE); - } else { - moreOptionsChevronImageView.setImageResource(R.drawable.ic_keyboard_arrow_down); - walletSeedEditText.setVisibility(View.GONE); - walletRestoreHeightEditText.setVisibility(View.GONE); - } - }); } private void prepareDefaultNode() { PrefService.getInstance().getNode(); } - private void createOrImportWallet(String walletPassword, String walletSeed, String restoreHeightText) { + private void createOrImportWallet(String walletPassword, String confirmedPassword, String walletSeed, String restoreHeightText) { String offset = useOffset ? walletPassword : ""; MainActivity mainActivity = (MainActivity) getActivity(); if (mainActivity != null) { if (!walletPassword.isEmpty()) { + if(!walletPassword.equals(confirmedPassword)) { + mainActivity.runOnUiThread(() -> Toast.makeText(mainActivity, getString(R.string.invalid_confirmed_password), Toast.LENGTH_SHORT).show()); + return; + } PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_PASSWORD, true).apply(); } long restoreHeight = getNewRestoreHeight(); diff --git a/app/src/main/res/layout/fragment_onboarding.xml b/app/src/main/res/layout/fragment_onboarding.xml index 65a8769..941db2a 100644 --- a/app/src/main/res/layout/fragment_onboarding.xml +++ b/app/src/main/res/layout/fragment_onboarding.xml @@ -24,23 +24,38 @@ android:id="@+id/wallet_password_edittext" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginBottom="32dp" android:background="@drawable/edittext_bg" android:hint="@string/password_optional" android:inputType="textPassword" - app:layout_constraintBottom_toTopOf="@id/tor_onboarding_switch" + app:layout_constraintBottom_toTopOf="@id/wallet_password_confirm_edittext" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/create_wallet_textview" tools:visibility="visible" /> + + + app:layout_constraintTop_toBottomOf="@id/wallet_password_confirm_edittext"/> Error creating tx Create wallet Invalid mnemonic + Passwords do not match Copied to clipboard Night mode Display wallet keys @@ -53,6 +54,7 @@ Recovery phrase (optional) Restore height (optional) Password (optional) + Confirm password Password Unlock Enter password