Browse Source

comfirm passphrase input (#6)

V1.1.0-release
JunZhang 5 years ago
committed by GitHub
parent
commit
d9a35b0f2a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 51
      app/src/main/java/com/cobo/cold/ui/fragment/PassphraseFragment.java
  2. 88
      app/src/main/res/layout/passphrase.xml
  3. 1
      app/src/main/res/values-zh-rCN/strings.xml
  4. 1
      app/src/main/res/values/strings.xml

51
app/src/main/java/com/cobo/cold/ui/fragment/PassphraseFragment.java

@ -18,16 +18,17 @@
package com.cobo.cold.ui.fragment;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.Observable;
import androidx.databinding.ObservableField;
import androidx.navigation.Navigation;
@ -46,7 +47,6 @@ import com.cobo.cold.util.Keyboard;
import com.cobo.cold.viewmodel.SetupVaultViewModel;
import java.util.List;
import java.util.Objects;
import static com.cobo.cold.Utilities.IS_SETUP_VAULT;
import static com.cobo.cold.Utilities.IS_SET_PASSPHRASE;
@ -58,7 +58,8 @@ public class PassphraseFragment extends SetupVaultBaseFragment<PassphraseBinding
private static final String SPACE = " ";
private static final int MAX_LENGTH = 128;
private final ObservableField<String> passphrase = new ObservableField<>("");
private final ObservableField<String> passphrase1 = new ObservableField<>("");
private final ObservableField<String> passphrase2 = new ObservableField<>("");
private ModalDialog dialog;
@Override
@ -73,17 +74,31 @@ public class PassphraseFragment extends SetupVaultBaseFragment<PassphraseBinding
if (mActivity instanceof SetupVaultActivity) {
mActivity.finish();
} else {
Keyboard.hide(mActivity, mBinding.input);
Keyboard.hide(mActivity, mBinding.input1);
navigateUp();
}
});
mBinding.setPassphrase(passphrase);
setFilterSpace(mBinding.input);
updateShowHide();
mBinding.eye.setOnClickListener(v -> updateShowHide());
mBinding.setPassphrase1(passphrase1);
mBinding.setPassphrase2(passphrase2);
setFilterSpace(mBinding.input1);
setFilterSpace(mBinding.input2);
mBinding.confirm.setOnClickListener(v -> confirmInput());
mBinding.input.setShowSoftInputOnFocus(false);
mBinding.input.setOnClickListener(v -> Keyboard.show(mActivity, mBinding.input));
Observable.OnPropertyChangedCallback callback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable sender, int propertyId) {
String input1 = passphrase1.get();
String input2 = passphrase2.get();
if (input2.length() >= input1.length() && !input1.equals(input2)) {
mBinding.inputHint.setText(R.string.password_verify_wrong);
mBinding.inputHint.setTextColor(Color.RED);
} else {
mBinding.inputHint.setText(R.string.passphrase_hint3);
mBinding.inputHint.setTextColor(Color.WHITE);
}
}
};
passphrase1.addOnPropertyChangedCallback(callback);
passphrase2.addOnPropertyChangedCallback(callback);
}
private void confirmInput() {
@ -96,7 +111,7 @@ public class PassphraseFragment extends SetupVaultBaseFragment<PassphraseBinding
binding.confirm.setText(R.string.confirm);
dialog.setBinding(binding);
binding.confirm.setOnClickListener(v -> {
Keyboard.hide(mActivity, mBinding.input);
Keyboard.hide(mActivity, mBinding.input1);
dialog.dismiss();
updatePassphrase();
});
@ -105,18 +120,10 @@ public class PassphraseFragment extends SetupVaultBaseFragment<PassphraseBinding
private void updatePassphrase() {
viewModel.setPassword(getArguments().getString(PASSWORD));
viewModel.updatePassphrase(passphrase.get());
viewModel.updatePassphrase(passphrase1.get());
subscribeVaultState(viewModel);
}
private void updateShowHide() {
mBinding.input.setTransformationMethod(mBinding.eye.isChecked() ?
null
:
PasswordTransformationMethod.getInstance());
mBinding.input.setSelection(Objects.requireNonNull(passphrase.get()).length());
}
private void setFilterSpace(EditText editText) {
InputFilter letterFilter = (source, start, end, dest, dstart, dend) -> {
if (SPACE.equals(source.toString())) {
@ -143,7 +150,7 @@ public class PassphraseFragment extends SetupVaultBaseFragment<PassphraseBinding
Utilities.setVaultCreated(mActivity);
Utilities.setVaultId(mActivity, viewModel.getVaultId());
Utilities.setCurrentBelongTo(mActivity,
TextUtils.isEmpty(passphrase.get()) ? "main" : "hidden");
TextUtils.isEmpty(passphrase1.get()) ? "main" : "hidden");
Runnable onComplete = () -> {
Bundle data = new Bundle();
@ -153,7 +160,7 @@ public class PassphraseFragment extends SetupVaultBaseFragment<PassphraseBinding
&& dialog.getDialog().isShowing()) {
dialog.dismiss();
}
if (TextUtils.isEmpty(passphrase.get())) {
if (TextUtils.isEmpty(passphrase1.get())) {
startActivity(new Intent(mActivity, MainActivity.class));
} else {
Navigation.findNavController(mActivity, R.id.nav_host_fragment)

88
app/src/main/res/layout/passphrase.xml

@ -23,7 +23,10 @@
<data>
<variable
name="passphrase"
name="passphrase1"
type="androidx.databinding.ObservableField&lt;String>" />
<variable
name="passphrase2"
type="androidx.databinding.ObservableField&lt;String>" />
</data>
@ -58,7 +61,7 @@
android:id="@+id/hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="10dp"
android:text="@string/passphrase_hint"
android:textColor="@android:color/white"
android:textStyle="bold"
@ -69,43 +72,33 @@
android:id="@+id/hint1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="10dp"
android:text="@string/passphrase_hint1"
android:textColor="@android:color/white"
android:layout_marginHorizontal="16dp"
android:textSize="12sp" />
<RelativeLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="53dp"
android:orientation="horizontal"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp">
<CheckBox
android:id="@+id/eye"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="end|center_vertical"
android:alpha="@{eye.checked ? 1f : 0.4f}"
android:button="@drawable/eye" />
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/input"
android:id="@+id/input1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="0dp"
android:layout_toStartOf="@id/eye"
android:layout_height="wrap_content"
android:background="@null"
android:focusable="true"
android:paddingVertical="5dp"
android:focusableInTouchMode="true"
android:hint="@string/passphrase_hint2"
android:imeOptions="actionDone"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="128"
android:text="@={passphrase}"
android:text="@={passphrase1}"
android:textColor="@color/white"
android:textColorHint="@color/white40"
android:textSize="14sp"
@ -114,19 +107,49 @@
<include
layout="@layout/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
android:layout_height="1dp" />
</LinearLayout>
<TextView
android:layout_marginTop="24dp"
android:layout_marginHorizontal="16dp"
android:id="@+id/input_hint"
android:layout_marginTop="10dp"
android:layout_marginHorizontal="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white40"
android:textColor="@color/white"
android:text="@string/passphrase_hint3" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/input2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:focusable="true"
android:paddingVertical="5dp"
android:focusableInTouchMode="true"
android:hint="@string/passphrase_hint_agian"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLength="128"
android:text="@={passphrase2}"
android:textColor="@color/white"
android:textColorHint="@color/white40"
android:textSize="14sp"
tools:ignore="Autofill" />
<include
layout="@layout/divider"
android:layout_width="match_parent"
android:layout_height="1dp" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
@ -138,6 +161,7 @@
android:layout_width="match_parent"
style="@style/AcceptButton"
android:layout_margin="16dp"
android:text="@string/confirm" />
android:text="@string/confirm"
android:enabled="@{passphrase1.equals(passphrase2)}"/>
</LinearLayout>
</layout>

1
app/src/main/res/values-zh-rCN/strings.xml

@ -118,6 +118,7 @@
<string name="password_modal_title">请输入密码</string>
<string name="passphrase_hint3">密语长度不得超过128个字符;可用大小写字母、数字、符号,禁用空格;</string>
<string name="passphrase_hint2">密语 (Passphrase): 区分大小写</string>
<string name="passphrase_hint_agian">请再次输入密语</string>
<string name="passphrase_hint1">注意:\n1.隐藏金库创建后,其对应的密语(Passphrase)不可修改;请牢记密语(Passphrase),忘记密语(Passphrase)将意味着隐藏金库的资产丢失;\n2. 密语为空,直接点击确定按钮将进入到默认金库</string>
<string name="passphrase_hint">请输入 密语 (Passphrase)</string>
<string name="passphrase_title">密语(Passphrase)金库</string>

1
app/src/main/res/values/strings.xml

@ -139,6 +139,7 @@
<string name="password_modal_title">Please enter password.</string>
<string name="passphrase_hint3">Passphrases cannot exceed 128 characters. Can consist of upper and lower case letters, digits, and symbols, but not spaces. Case Sensitive.</string>
<string name="passphrase_hint2">Enter a Passphrase (case sensitive)</string>
<string name="passphrase_hint_agian">Enter Passphrase Again</string>
<string name="passphrase_hint1">Important Information:\n1. When a Hidden Vault is created, its Passphrase cannot be changed. If the Passphrase is lost or forgotten, the Hidden Vault and all its assets will be irretrievable. Record and store the Passphrase securely before creating a Hidden Vault \n2. Keep the Passphrase field blank to enter the default Vault</string>
<string name="passphrase_hint">Please Input a Passphrase</string>
<string name="passphrase_title">Passphrase Vault</string>

Loading…
Cancel
Save