From d6d2de83127cd0744c7b3442e9940c53dd2059a9 Mon Sep 17 00:00:00 2001 From: 0140454 Date: Fri, 15 Jun 2018 03:33:23 +0800 Subject: [PATCH] Inform user the progress or result of opening wallet (#297) --- .../com/m2049r/xmrwallet/util/Helper.java | 106 +++++++++++++----- .../main/res/drawable/ic_error_red_36dp.xml | 27 +++++ app/src/main/res/drawable/ic_fingerprint.xml | 47 ++++---- .../main/res/drawable/ic_info_green_36dp.xml | 27 +++++ app/src/main/res/layout/prompt_password.xml | 4 +- app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-it/strings.xml | 2 + app/src/main/res/values-nb/strings.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 2 + app/src/main/res/values-zh-rTW/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 13 files changed, 177 insertions(+), 50 deletions(-) create mode 100644 app/src/main/res/drawable/ic_error_red_36dp.xml create mode 100644 app/src/main/res/drawable/ic_info_green_36dp.xml diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java index 86c27fa..bf2f04e 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java @@ -32,6 +32,7 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.VectorDrawable; import android.hardware.fingerprint.FingerprintManager; +import android.os.AsyncTask; import android.os.Build; import android.os.CancellationSignal; import android.os.Environment; @@ -67,6 +68,7 @@ import java.net.MalformedURLException; import java.net.SocketTimeoutException; import java.net.URL; import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.HttpsURLConnection; @@ -381,6 +383,7 @@ public class Helper { } static AlertDialog openDialog = null; // for preventing opening of multiple dialogs + static AsyncTask loginTask = null; static public void promptPassword(final Context context, final String wallet, boolean fingerprintDisabled, final PasswordAction action) { if (openDialog != null) return; // we are already asking for password @@ -393,11 +396,68 @@ public class Helper { final TextInputLayout etPassword = (TextInputLayout) promptsView.findViewById(R.id.etPassword); etPassword.setHint(context.getString(R.string.prompt_password, wallet)); + final TextView tvOpenPrompt = (TextView) promptsView.findViewById(R.id.tvOpenPrompt); + final Drawable icFingerprint = context.getDrawable(R.drawable.ic_fingerprint); + final Drawable icError = context.getDrawable(R.drawable.ic_error_red_36dp); + final Drawable icInfo = context.getDrawable(R.drawable.ic_info_green_36dp); + final boolean fingerprintAuthCheck = FingerprintHelper.isFingerPassValid(context, wallet); final boolean fingerprintAuthAllowed = !fingerprintDisabled && fingerprintAuthCheck; final CancellationSignal cancelSignal = new CancellationSignal(); + final AtomicBoolean incorrectSavedPass = new AtomicBoolean(false); + class LoginWalletTask extends AsyncTask { + private String pass; + private boolean fingerprintUsed; + + LoginWalletTask(String pass, boolean fingerprintUsed) { + this.pass = pass; + this.fingerprintUsed = fingerprintUsed; + } + + @Override + protected void onPreExecute() { + tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icInfo, null, null, null); + tvOpenPrompt.setText(context.getText(R.string.prompt_open_wallet)); + tvOpenPrompt.setVisibility(View.VISIBLE); + } + + @Override + protected Boolean doInBackground(Void... unused) { + return processPasswordEntry(context, wallet, pass, fingerprintUsed, action); + } + + @Override + protected void onPostExecute(Boolean result) { + if (result) { + Helper.hideKeyboardAlways((Activity) context); + cancelSignal.cancel(); + openDialog.dismiss(); + openDialog = null; + } else { + if (fingerprintUsed) { + incorrectSavedPass.set(true); + tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icError, null, null, null); + tvOpenPrompt.setText(context.getText(R.string.bad_saved_password)); + } else { + if (!fingerprintAuthAllowed) { + tvOpenPrompt.setVisibility(View.GONE); + } else if (incorrectSavedPass.get()) { + tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icError, null, null, null); + tvOpenPrompt.setText(context.getText(R.string.bad_password)); + } else { + tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icFingerprint, null, null, null); + tvOpenPrompt.setText(context.getText(R.string.prompt_fingerprint_auth)); + } + etPassword.setError(context.getString(R.string.bad_password)); + } + } + + loginTask = null; + } + } + etPassword.getEditText().addTextChangedListener(new TextWatcher() { @Override @@ -427,6 +487,10 @@ public class Helper { public void onClick(DialogInterface dialog, int id) { Helper.hideKeyboardAlways((Activity) context); cancelSignal.cancel(); + if (loginTask != null) { + loginTask.cancel(true); + loginTask = null; + } dialog.cancel(); openDialog = null; } @@ -440,30 +504,28 @@ public class Helper { fingerprintAuthCallback = new FingerprintManager.AuthenticationCallback() { @Override public void onAuthenticationError(int errMsgId, CharSequence errString) { - ((TextView) promptsView.findViewById(R.id.txtFingerprintAuth)).setText(errString); + tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icError, null, null, null); + tvOpenPrompt.setText(errString); } @Override public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { try { String userPass = KeyStoreHelper.loadWalletUserPass(context, wallet); - if (Helper.processPasswordEntry(context, wallet, userPass, true, action)) { - Helper.hideKeyboardAlways((Activity) context); - openDialog.dismiss(); - openDialog = null; - } else { - etPassword.setError(context.getString(R.string.bad_password)); + if (loginTask == null) { + loginTask = new LoginWalletTask(userPass, true); + loginTask.execute(); } } catch (KeyStoreHelper.BrokenPasswordStoreException ex) { etPassword.setError(context.getString(R.string.bad_password)); - // TODO: better errror message here - what would it be? + // TODO: better error message here - what would it be? } } @Override public void onAuthenticationFailed() { - ((TextView) promptsView.findViewById(R.id.txtFingerprintAuth)) - .setText(context.getString(R.string.bad_fingerprint)); + tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icError, null, null, null); + tvOpenPrompt.setText(context.getString(R.string.bad_fingerprint)); } }; } @@ -472,7 +534,9 @@ public class Helper { @Override public void onShow(DialogInterface dialog) { if (fingerprintAuthAllowed && fingerprintAuthCallback != null) { - promptsView.findViewById(R.id.txtFingerprintAuth).setVisibility(View.VISIBLE); + tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icFingerprint, null, null, null); + tvOpenPrompt.setText(context.getText(R.string.prompt_fingerprint_auth)); + tvOpenPrompt.setVisibility(View.VISIBLE); FingerprintHelper.authenticate(context, cancelSignal, fingerprintAuthCallback); } Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); @@ -480,13 +544,9 @@ public class Helper { @Override public void onClick(View view) { String pass = etPassword.getEditText().getText().toString(); - if (processPasswordEntry(context, wallet, pass, false, action)) { - Helper.hideKeyboardAlways((Activity) context); - cancelSignal.cancel(); - openDialog.dismiss(); - openDialog = null; - } else { - etPassword.setError(context.getString(R.string.bad_password)); + if (loginTask == null) { + loginTask = new LoginWalletTask(pass, false); + loginTask.execute(); } } }); @@ -498,13 +558,9 @@ public class Helper { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { String pass = etPassword.getEditText().getText().toString(); - if (processPasswordEntry(context, wallet, pass, false, action)) { - Helper.hideKeyboardAlways((Activity) context); - cancelSignal.cancel(); - openDialog.dismiss(); - openDialog = null; - } else { - etPassword.setError(context.getString(R.string.bad_password)); + if (loginTask == null) { + loginTask = new LoginWalletTask(pass, false); + loginTask.execute(); } return true; } diff --git a/app/src/main/res/drawable/ic_error_red_36dp.xml b/app/src/main/res/drawable/ic_error_red_36dp.xml new file mode 100644 index 0000000..5ca78b7 --- /dev/null +++ b/app/src/main/res/drawable/ic_error_red_36dp.xml @@ -0,0 +1,27 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_fingerprint.xml b/app/src/main/res/drawable/ic_fingerprint.xml index 81eccc5..604b5c2 100644 --- a/app/src/main/res/drawable/ic_fingerprint.xml +++ b/app/src/main/res/drawable/ic_fingerprint.xml @@ -1,37 +1,40 @@ + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> + android:width="36dp" + android:height="36dp" + android:viewportWidth="36.0" + android:viewportHeight="36.0"> + android:fillColor="#009688" + android:pathData="M18,18m -18, 0a 18, 18 0 1, 0 36, 0a 18, 18 0 1, 0 -36, 0" /> + android:pathData="m23.815,10.47c-0.08,0 -0.16,-0.02 -0.23,-0.06c-1.92,-0.99 -3.58,-1.41 -5.57,-1.41c-1.98,0 -3.86,0.47 -5.57,1.41c-0.24,0.13 -0.54,0.04 -0.68,-0.2c-0.13,-0.24 -0.04,-0.55 0.2,-0.68c1.86,-1.01 3.9,-1.53 6.05,-1.53c2.13,0 3.99,0.47 6.03,1.52c0.25,0.13 0.34,0.43 0.21,0.67c-0.09,0.18 -0.26,0.28 -0.44,0.28z" /> + android:pathData="m9.505,15.72c-0.1,0 -0.2,-0.03 -0.29,-0.09c-0.23,-0.16 -0.28,-0.47 -0.12,-0.7c0.99,-1.4 2.25,-2.5 3.75,-3.27c3.14,-1.62 7.16,-1.63 10.31,-0.01c1.5,0.77 2.76,1.86 3.75,3.25c0.16,0.22 0.11,0.54 -0.12,0.7c-0.23,0.16 -0.54,0.11 -0.7,-0.12c-0.9,-1.26 -2.04,-2.25 -3.39,-2.94c-2.87,-1.47 -6.54,-1.47 -9.4,0.01c-1.36,0.7 -2.5,1.7 -3.4,2.96c-0.08,0.14 -0.23,0.21 -0.39,0.21z" /> + android:pathData="m15.755,27.79c-0.13,0 -0.26,-0.05 -0.35,-0.15c-0.87,-0.87 -1.34,-1.43 -2.01,-2.64c-0.69,-1.23 -1.05,-2.73 -1.05,-4.34c0,-2.97 2.54,-5.39 5.66,-5.39s5.66,2.42 5.66,5.39c0,0.28 -0.22,0.5 -0.5,0.5s-0.5,-0.22 -0.5,-0.5c0,-2.42 -2.09,-4.39 -4.66,-4.39c-2.57,0 -4.66,1.97 -4.66,4.39c0,1.44 0.32,2.77 0.93,3.85c0.64,1.15 1.08,1.64 1.85,2.42c0.19,0.2 0.19,0.51 0,0.71c-0.11,0.1 -0.24,0.15 -0.37,0.15z" /> + android:pathData="m22.925,25.94c-1.19,0 -2.24,-0.3 -3.1,-0.89c-1.49,-1.01 -2.38,-2.65 -2.38,-4.39c0,-0.28 0.22,-0.5 0.5,-0.5s0.5,0.22 0.5,0.5c0,1.41 0.72,2.74 1.94,3.56c0.71,0.48 1.54,0.71 2.54,0.71c0.24,0 0.64,-0.03 1.04,-0.1c0.27,-0.05 0.53,0.13 0.58,0.41c0.05,0.27 -0.13,0.53 -0.41,0.58c-0.57,0.11 -1.07,0.12 -1.21,0.12z" /> + android:pathData="m20.915,28c-0.04,0 -0.09,-0.01 -0.13,-0.02c-1.59,-0.44 -2.63,-1.03 -3.72,-2.1c-1.4,-1.39 -2.17,-3.24 -2.17,-5.22c0,-1.62 1.38,-2.94 3.08,-2.94c1.7,0 3.08,1.32 3.08,2.94c0,1.07 0.93,1.94 2.08,1.94s2.08,-0.87 2.08,-1.94c0,-3.77 -3.25,-6.83 -7.25,-6.83c-2.84,0 -5.44,1.58 -6.61,4.03c-0.39,0.81 -0.59,1.76 -0.59,2.8c0,0.78 0.07,2.01 0.67,3.61c0.1,0.26 -0.03,0.55 -0.29,0.64c-0.26,0.1 -0.55,-0.04 -0.64,-0.29c-0.49,-1.31 -0.73,-2.61 -0.73,-3.96c0,-1.2 0.23,-2.29 0.68,-3.24c1.33,-2.79 4.28,-4.6 7.51,-4.6c4.55,0 8.25,3.51 8.25,7.83c0,1.62 -1.38,2.94 -3.08,2.94s-3.08,-1.32 -3.08,-2.94c0,-1.07 -0.93,-1.94 -2.08,-1.94s-2.08,0.87 -2.08,1.94c0,1.71 0.66,3.31 1.87,4.51c0.95,0.94 1.86,1.46 3.27,1.85c0.27,0.07 0.42,0.35 0.35,0.61c-0.05,0.23 -0.26,0.38 -0.47,0.38z" /> \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info_green_36dp.xml b/app/src/main/res/drawable/ic_info_green_36dp.xml new file mode 100644 index 0000000..69b7847 --- /dev/null +++ b/app/src/main/res/drawable/ic_info_green_36dp.xml @@ -0,0 +1,27 @@ + + + + + diff --git a/app/src/main/res/layout/prompt_password.xml b/app/src/main/res/layout/prompt_password.xml index b38b7ce..fdd7e43 100644 --- a/app/src/main/res/layout/prompt_password.xml +++ b/app/src/main/res/layout/prompt_password.xml @@ -23,12 +23,10 @@ \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a67f189..d47c0fd 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -133,8 +133,10 @@ Passwort für %1$s Fingerabdruck-Authentifizierung möglich.\nBitte Sensor berühren. Passwort bestätigen + [Opening the wallet…] Fingerabdruck nicht erkannt. Nochmals versuchen. Falsches Passwort! + [Saved password is incorrect.\nPlease enter password manually.] Wallet existiert nicht! Daemonadresse muss gesetzt sein! Wallet entspricht nicht dem ausgewähltem Netz diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5943fe6..48fb2b5 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -80,8 +80,10 @@ Contraseña para %1$s Puedes poner tu dedo en el sensor para autorizar con tu huella. Confirmar Contraseña + [Opening the wallet…] Huella no reconocida. Inténtalo nuevamente. ¡Contraseña incorrecta! + [Saved password is incorrect.\nPlease enter password manually.] ¡El monedero no existe! ¡La dirección del daemon debe estar configurada! El monedero no coincide con la red seleccionada diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f882df5..4936abb 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -134,8 +134,10 @@ Mot de passe pour %1$s Vous pouvez également ouvrir le portefeuille avec votre empreinte digitale.\nMerci de toucher le capteur. Confirmez le mot de passe + [Opening the wallet…] Empreinte digitale non reconnue. Résessayez. Mot de passe incorrect ! + [Saved password is incorrect.\nPlease enter password manually.] Portefeuille inexistant ! L\'adresse du démon ne peut pas être configurée ! Portefeuille incompatible avec le réseau sélectionné diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 0864410..d425a67 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -133,8 +133,10 @@ Password per %1$s Puoi aprire il portafoglio anche usando la tua impronta digitale./nTocca il sensore. Conferma Password + [Opening the wallet…] Impronta digitale non riconosciuta. Prova di nuovo. Password errata! + [Saved password is incorrect.\nPlease enter password manually.] Il portafoglio non esiste! Deve essere impostato l\'indirizzo del Daemon! Il portafoglio non si abbina con la rete selezionata diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index a75bbf4..e3e0cee 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -131,8 +131,10 @@ Passord for %1$s [You can also open wallet using fingerprint.\nPlease touch sensor.] Bekreft passord + [Opening the wallet…] [Fingerprint not recognized. Try again.] Feil passord! + [Saved password is incorrect.\nPlease enter password manually.] Lommebok eksisterer ikke! Daemon-adresse må være gitt! Lommebok matcher ikke valgt nett diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 1dd0d0f..6b9864f 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -132,8 +132,10 @@ %1$s 的密码 你也可以使用指纹来开启钱包。\n请轻触你的指纹感应器。 确认密码 + [Opening the wallet…] 无法识别指纹,请再试一次。 密码错误! + [Saved password is incorrect.\nPlease enter password manually.] 钱包不存在! 必需要设定节点位置! 钱包不符合选择的网络 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index b79efe1..2a9ef36 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -133,8 +133,10 @@ %1$s 的密碼 你也可以使用指紋來開啟錢包。\n請輕觸你的指紋感應器。 確認密碼 + 正在開啟錢包… 無法辨識的指紋,請再試一次。 密碼錯誤! + 儲存的密碼不正確。\n請手動輸入密碼。 錢包不存在! 必需要設定節點位置! 錢包不符合選擇的網路 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c83ff5..6a2939f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -139,8 +139,10 @@ Password for %1$s You can also open wallet using fingerprint.\nPlease touch sensor. Confirm Password + Opening the wallet… Fingerprint not recognized. Try again. Incorrect password! + Saved password is incorrect.\nPlease enter password manually. Wallet does not exist! Daemon address must be set! Wallet does not match selected net