From 5a34f444c22687d791d9694b6fef2c630a4a3d0f Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 31 May 2020 13:42:31 +0530 Subject: Completely revamp decrypted password screen (#817) * Completely revamp decrypted password screen Signed-off-by: Harsh Shandilya * update changelog Signed-off-by: Harsh Shandilya Co-authored-by: Fabian Henneke --- CHANGELOG.md | 3 + .../java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 176 ++++++--------------- app/src/main/res/layout/decrypt_layout.xml | 155 +++++------------- app/src/main/res/values-ar/strings.xml | 1 - app/src/main/res/values-cs/strings.xml | 1 - app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-fr/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values/strings.xml | 2 +- 10 files changed, 93 insertions(+), 249 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 041eb8e2..88cf637b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added +- Completely revamped decypted password view + ### Changed - **BREAKING**: Remove support for HOTP/TOTP secrets - Please use FIDO keys or a dedicated app like [Aegis](https://github.com/beemdevelopment/Aegis) or [andOTP](https://github.com/andOTP/andOTP). - Reduce Autofill false positives on username fields by removing "name" from list of heuristic terms diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt index d9027230..35550d8d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -4,7 +4,6 @@ */ package com.zeapo.pwdstore.crypto -import android.annotation.SuppressLint import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.ClipData @@ -23,13 +22,9 @@ import android.text.format.DateUtils import android.text.method.PasswordTransformationMethod import android.view.Menu import android.view.MenuItem -import android.view.MotionEvent import android.view.View import android.view.WindowManager -import android.widget.Button -import android.widget.TextView import androidx.appcompat.app.AppCompatActivity -import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.edit import androidx.core.content.getSystemService import androidx.core.widget.doOnTextChanged @@ -48,19 +43,15 @@ import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure import com.zeapo.pwdstore.ui.dialogs.PasswordGeneratorDialogFragment import com.zeapo.pwdstore.ui.dialogs.XkPasswordGeneratorDialogFragment -import kotlinx.android.synthetic.main.decrypt_layout.crypto_container_decrypt -import kotlinx.android.synthetic.main.decrypt_layout.crypto_copy_username -import kotlinx.android.synthetic.main.decrypt_layout.crypto_extra_show -import kotlinx.android.synthetic.main.decrypt_layout.crypto_extra_show_layout -import kotlinx.android.synthetic.main.decrypt_layout.crypto_extra_toggle_show import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_category_decrypt import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_file import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_last_changed -import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_show -import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_show_label -import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_toggle_show -import kotlinx.android.synthetic.main.decrypt_layout.crypto_username_show -import kotlinx.android.synthetic.main.decrypt_layout.crypto_username_show_label +import kotlinx.android.synthetic.main.decrypt_layout.extra_content +import kotlinx.android.synthetic.main.decrypt_layout.extra_content_container +import kotlinx.android.synthetic.main.decrypt_layout.password_text +import kotlinx.android.synthetic.main.decrypt_layout.password_text_container +import kotlinx.android.synthetic.main.decrypt_layout.username_text +import kotlinx.android.synthetic.main.decrypt_layout.username_text_container import kotlinx.android.synthetic.main.encrypt_layout.crypto_extra_edit import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_category import kotlinx.android.synthetic.main.encrypt_layout.crypto_password_edit @@ -119,7 +110,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { val settings: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) } private val keyIDs get() = _keyIDs private var _keyIDs = emptySet() - private var mServiceConnection: OpenPgpServiceConnection? = null + private var serviceConnection: OpenPgpServiceConnection? = null private var delayTask: DelayShow? = null private val receiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -142,8 +133,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { startActivityForResult(intent, OPEN_PGP_BOUND) } else { // bind to service - mServiceConnection = OpenPgpServiceConnection(this, providerPackageName, this) - mServiceConnection?.bindToService() + serviceConnection = OpenPgpServiceConnection(this, providerPackageName, this) + serviceConnection?.bindToService() supportActionBar?.setDisplayHomeAsUpEnabled(true) } @@ -156,12 +147,12 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { val clipboard = clipboard ?: return@setOnLongClickListener false val clip = ClipData.newPlainText("pgp_handler_result_pm", name) clipboard.setPrimaryClip(clip) - showSnackbar(this.resources.getString(R.string.clipboard_username_toast_text)) + showSnackbar(resources.getString(R.string.clipboard_copied_text)) true } crypto_password_last_changed.text = try { - this.resources.getString(R.string.last_changed, lastChangedString) + resources.getString(R.string.last_changed, lastChangedString) } catch (e: RuntimeException) { showSnackbar(getString(R.string.get_last_changed_failed)) "" @@ -277,7 +268,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { override fun onDestroy() { super.onDestroy() - mServiceConnection?.unbindFromService() + serviceConnection?.unbindFromService() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -354,7 +345,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } private fun initOpenPgpApi() { - api = api ?: OpenPgpApi(this, mServiceConnection!!.service!!) + api = api ?: OpenPgpApi(this, serviceConnection!!.service!!) } private fun decryptAndVerify(receivedIntent: Intent? = null) { @@ -372,7 +363,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { val showPassword = settings.getBoolean("show_password", true) val showExtraContent = settings.getBoolean("show_extra_content", true) - crypto_container_decrypt.visibility = View.VISIBLE + password_text_container.visibility = View.VISIBLE val monoTypeface = Typeface.createFromAsset(assets, "fonts/sourcecodepro.ttf") val entry = PasswordEntry(oStream) @@ -385,61 +376,34 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } if (entry.password.isEmpty()) { - crypto_password_show.visibility = View.GONE - crypto_password_show_label.visibility = View.GONE + password_text_container.visibility = View.GONE } else { - crypto_password_show.visibility = View.VISIBLE - crypto_password_show_label.visibility = View.VISIBLE - crypto_password_show.typeface = monoTypeface - crypto_password_show.text = entry.password - } - crypto_password_show.typeface = monoTypeface - crypto_password_show.text = entry.password - - crypto_password_toggle_show.visibility = if (showPassword) View.GONE else View.VISIBLE - crypto_password_show.transformationMethod = if (showPassword) { - null - } else { - HoldToShowPasswordTransformation( - crypto_password_toggle_show, - Runnable { crypto_password_show.text = entry.password } - ) + password_text_container.visibility = View.VISIBLE + password_text.setText(entry.password) + if (!showPassword) { + password_text.transformationMethod = PasswordTransformationMethod.getInstance() + } + password_text_container.setOnClickListener { copyPasswordToClipBoard() } + password_text.setOnClickListener { copyPasswordToClipBoard() } } if (entry.hasExtraContent()) { - crypto_extra_show.typeface = monoTypeface - crypto_extra_show.text = entry.extraContent - - if (showExtraContent) { - crypto_extra_show_layout.visibility = View.VISIBLE - crypto_extra_toggle_show.visibility = View.GONE - crypto_extra_show.transformationMethod = null - } else { - crypto_extra_show_layout.visibility = View.GONE - crypto_extra_toggle_show.visibility = View.VISIBLE - crypto_extra_toggle_show.setOnCheckedChangeListener { _, _ -> - crypto_extra_show.text = entry.extraContent - } - - crypto_extra_show.transformationMethod = object : PasswordTransformationMethod() { - override fun getTransformation(source: CharSequence, view: View): CharSequence { - return if (crypto_extra_toggle_show.isChecked) source else super.getTransformation(source, view) - } - } + extra_content_container.visibility = View.VISIBLE + extra_content.typeface = monoTypeface + extra_content.setText(entry.extraContentWithoutUsername) + if (!showExtraContent) { + extra_content.transformationMethod = PasswordTransformationMethod.getInstance() } + extra_content_container.setOnClickListener { copyTextToClipboard(entry.extraContentWithoutUsername) } + extra_content.setOnClickListener { copyTextToClipboard(entry.extraContentWithoutUsername) } if (entry.hasUsername()) { - crypto_username_show.visibility = View.VISIBLE - crypto_username_show_label.visibility = View.VISIBLE - crypto_copy_username.visibility = View.VISIBLE - - crypto_copy_username.setOnClickListener { copyUsernameToClipBoard(entry.username!!) } - crypto_username_show.typeface = monoTypeface - crypto_username_show.text = entry.username + username_text.typeface = monoTypeface + username_text.setText(entry.username) + username_text_container.setEndIconOnClickListener { copyTextToClipboard(entry.username!!) } + username_text_container.visibility = View.VISIBLE } else { - crypto_username_show.visibility = View.GONE - crypto_username_show_label.visibility = View.GONE - crypto_copy_username.visibility = View.GONE + username_text_container.visibility = View.GONE } } @@ -657,47 +621,9 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } } - @SuppressLint("ClickableViewAccessibility") - private inner class HoldToShowPasswordTransformation constructor(button: Button, private val onToggle: Runnable) : - PasswordTransformationMethod(), View.OnTouchListener { - - private var shown = false - - init { - button.setOnTouchListener(this) - } - - override fun getTransformation(charSequence: CharSequence, view: View): CharSequence { - return if (shown) charSequence else super.getTransformation("12345", view) - } - - override fun onTouch(view: View, motionEvent: MotionEvent): Boolean { - when (motionEvent.action) { - MotionEvent.ACTION_DOWN -> { - shown = true - onToggle.run() - } - MotionEvent.ACTION_UP -> { - shown = false - onToggle.run() - } - } - return false - } - } - private fun copyPasswordToClipBoard() { val clipboard = clipboard ?: return - var pass = passwordEntry?.password - - if (findViewById(R.id.crypto_password_show) == null) { - if (editPass == null) { - return - } else { - pass = editPass - } - } - + val pass = passwordEntry?.password val clip = ClipData.newPlainText("pgp_handler_result_pm", pass) clipboard.setPrimaryClip(clip) @@ -710,23 +636,20 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { if (clearAfter != 0) { setTimer() - showSnackbar(this.resources.getString(R.string.clipboard_password_toast_text, clearAfter)) + showSnackbar(resources.getString(R.string.clipboard_password_toast_text, clearAfter)) } else { - showSnackbar(this.resources.getString(R.string.clipboard_password_no_clear_toast_text)) + showSnackbar(resources.getString(R.string.clipboard_password_no_clear_toast_text)) } } - private fun copyUsernameToClipBoard(username: String) { + private fun copyTextToClipboard(text: String) { val clipboard = clipboard ?: return - val clip = ClipData.newPlainText("pgp_handler_result_pm", username) + val clip = ClipData.newPlainText("pgp_handler_result_pm", text) clipboard.setPrimaryClip(clip) - showSnackbar(resources.getString(R.string.clipboard_username_toast_text)) + showSnackbar(resources.getString(R.string.clipboard_copied_text)) } private fun shareAsPlaintext() { - if (findViewById(R.id.share_password_as_plaintext) == null) - return - val sendIntent = Intent() sendIntent.action = Intent.ACTION_SEND sendIntent.putExtra(Intent.EXTRA_TEXT, passwordEntry?.password) @@ -800,25 +723,18 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } catch (e: NumberFormatException) { 45 } - - val container = findViewById(R.id.crypto_container_decrypt) - container?.visibility = View.VISIBLE - - val extraText = findViewById(R.id.crypto_extra_show) - - if (extraText?.text?.isNotEmpty() == true) - findViewById(R.id.crypto_extra_show_layout)?.visibility = View.VISIBLE + password_text_container?.visibility = View.VISIBLE + if (extra_content?.text?.isNotEmpty() == true) + extra_content_container?.visibility = View.VISIBLE } fun doOnPostExecute() { if (skip) return - if (crypto_password_show != null) { + if (password_text != null) { passwordEntry = null - crypto_password_show.text = "" - crypto_extra_show.text = "" - crypto_extra_show_layout.visibility = View.INVISIBLE - crypto_container_decrypt.visibility = View.INVISIBLE + extra_content_container.visibility = View.INVISIBLE + password_text_container.visibility = View.INVISIBLE finish() } } diff --git a/app/src/main/res/layout/decrypt_layout.xml b/app/src/main/res/layout/decrypt_layout.xml index 932eefd6..590661b3 100644 --- a/app/src/main/res/layout/decrypt_layout.xml +++ b/app/src/main/res/layout/decrypt_layout.xml @@ -68,137 +68,68 @@ app:layout_constraintTop_toBottomOf="@id/crypto_password_last_changed" tools:ignore="ContentDescription" /> - - - - - - + android:editable="false" + android:fontFamily="@font/sourcecodepro" + android:textIsSelectable="true" + tools:text="p@55w0rd!" /> - + - - - - - - - - - - + tools:text="totally_real_user@example.com" /> + + + - - - + android:editable="false" + android:textIsSelectable="true" + tools:text="lots of extra content that will surely fill this \n up well" /> + diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index ecb03154..0ab9c7f1 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -16,7 +16,6 @@ حذف لم يتم إختيار مزود الأوبن بي جي بي بعد ! - تم نسخ إسم المستخدم إلى الحافظة الرجاء إدخال إسم ملف جاري تنفيذ الأمر ... diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 420c0ce4..a6cde10c 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -33,7 +33,6 @@ Nebyl vybrán poskytovatel OpenPGP! Heslo zkopírováno do schránky, máte %d sekund na jeho zkopírování. Heslo zkopírováno do schránky - Jméno zkopírováno do schránky Zadejte prosím jméno souboru Prosím zadejte cestu k souboru Nelze zadat prázdné heslo nebo další obsah diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index adc09762..77d3fb4f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -20,7 +20,6 @@ Kein OpenPGP-Provider ausgewählt! Passwort ist in der Zwischenablage, du hast %d Sekunden, um es einzufügen. - Benutzername ist in der Zwischenablage Bitte setze einen Pfad Du kannst kein leeres Passwort setzen oder leere Extra-Angaben diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5d74c581..7ef91026 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -29,7 +29,6 @@ ¡No se ha seleccionado ningún proveedor OpenGPG! Contraseña copiada al portapapeles, tienes %d segundos para pegarla. Contraseña copiada al portapapeles - Nombre de usuario copiado al portapapeles Por favor selecciona un nombre de archivo No puedes dejar la contraseña y el contenido extra ambos vacíos diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index eb234323..32ee4bec 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -35,7 +35,6 @@ Aucun prestataire OpenPGP sélectionné ! Mot de passe copié dans le presse papier, vous avez %d secondes pour coller celui-ci. - Nom d\'utilisateur copié Renseignez un nom de fichier Vous ne pouvez pas utiliser un mot de passe vide ou des données supplémentaires vide diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a4999f9b..39d22662 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -36,7 +36,6 @@ Не выбран провайдер OpenPGP! Пароль скопирован в буфер обмена, у вас есть %d секунд чтобы вставить его. Пароль скопирован в буфер обмена - Имя пользователя скопировано в буфер обмена Пожалуйста, укажите имя файла Пожалуйста, задайте путь к файлу Вы не можете использовать пустой пароль или пустое поле информации diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d485f923..ffd10068 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -47,7 +47,7 @@ No OpenPGP provider selected! Password copied to clipboard, you have %d seconds to paste it somewhere. Password copied to clipboard - Username copied to clipboard + Copied to clipboard Please provide a file name Please provide a file path You cannot use an empty password or empty extra content -- cgit v1.2.3