From 367e55de3cfb0821898c41413ecdb6d284763081 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Sat, 14 Sep 2019 03:48:18 -0400 Subject: add save-and-copy button (#537) --- .../java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 26 ++++++++++++++++------ .../main/res/drawable/ic_done_copy_white_24dp.xml | 12 ++++++++++ app/src/main/res/menu/pgp_handler_new_password.xml | 5 +++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/ic_done_copy_white_24dp.xml 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 7364cf35..70e10561 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -168,6 +168,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { R.id.share_password_as_plaintext -> shareAsPlaintext() R.id.edit_password -> editPassword() R.id.crypto_confirm_add -> encrypt() + R.id.crypto_confirm_add_and_copy -> encrypt(true) R.id.crypto_cancel_add -> { if (passwordEntry?.hotpIsIncremented() == false) { setResult(RESULT_CANCELED) @@ -408,7 +409,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { /** * Encrypts the password and the extra content */ - private fun encrypt() { + private fun encrypt(copy: Boolean = false) { // if HOTP was incremented, we leave fields as is; they have already been set if (intent.getStringExtra("OPERATION") != "INCREMENT") { editName = crypto_password_file_edit.text.toString().trim() @@ -426,6 +427,10 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { return } + if (copy) { + copyPasswordToClipBoard() + } + val data = Intent() data.action = OpenPgpApi.ACTION_ENCRYPT @@ -635,10 +640,17 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } private fun copyPasswordToClipBoard() { - if (findViewById(R.id.crypto_password_show) == null) - return + var pass = passwordEntry?.password + + if (findViewById(R.id.crypto_password_show) == null) { + if (editPass == null) { + return + } else { + pass = editPass + } + } - val clip = ClipData.newPlainText("pgp_handler_result_pm", passwordEntry?.password) + val clip = ClipData.newPlainText("pgp_handler_result_pm", pass) clipboard.setPrimaryClip(clip) var clearAfter = 45 @@ -738,12 +750,12 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } val container = findViewById(R.id.crypto_container_decrypt) - container.visibility = View.VISIBLE + container?.visibility = View.VISIBLE val extraText = findViewById(R.id.crypto_extra_show) - if (extraText.text.isNotEmpty()) - findViewById(R.id.crypto_extra_show_layout).visibility = View.VISIBLE + if (extraText?.text?.isNotEmpty() ?: false) + findViewById(R.id.crypto_extra_show_layout)?.visibility = View.VISIBLE if (showTime == 0) { // treat 0 as forever, and the user must exit and/or clear clipboard on their own diff --git a/app/src/main/res/drawable/ic_done_copy_white_24dp.xml b/app/src/main/res/drawable/ic_done_copy_white_24dp.xml new file mode 100644 index 00000000..20b3e5da --- /dev/null +++ b/app/src/main/res/drawable/ic_done_copy_white_24dp.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/menu/pgp_handler_new_password.xml b/app/src/main/res/menu/pgp_handler_new_password.xml index 9c8dd34b..83b58758 100644 --- a/app/src/main/res/menu/pgp_handler_new_password.xml +++ b/app/src/main/res/menu/pgp_handler_new_password.xml @@ -12,4 +12,9 @@ pwstore:showAsAction="ifRoom" android:id="@+id/crypto_confirm_add" /> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b6bfb31e..8e54490f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,6 +103,7 @@ Select Cancel Save + Save and Copy Search -- cgit v1.2.3