diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2018-10-12 13:39:06 +0530 |
|---|---|---|
| committer | Mohamed Zenadi <zeapo@users.noreply.github.com> | 2018-10-12 10:09:06 +0200 |
| commit | b8c5dd85a6e32c47bee1bbb531846e6aef0dcb30 (patch) | |
| tree | f695cdfad9b9eb437e8a7c3302ba3805ad445fc3 /app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt | |
| parent | 8e9c2363bb75a7024aa9ac30673a46259fda4c2e (diff) | |
| download | HardenedPass-b8c5dd85a6e32c47bee1bbb531846e6aef0dcb30.tar.gz HardenedPass-b8c5dd85a6e32c47bee1bbb531846e6aef0dcb30.zip | |
treewide: Cleanup relevant build warnings (#433)
Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 91 |
1 files changed, 45 insertions, 46 deletions
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 4300aeba..4afc6e19 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -93,7 +93,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { setContentView(R.layout.encrypt_layout) generate_password?.setOnClickListener { - pwgenDialogFragment().show(fragmentManager, "generator") + pwgenDialogFragment().show(supportFragmentManager, "generator") } title = getString(R.string.new_password_title) @@ -149,7 +149,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { * Shows a simple toast message */ private fun showToast(message: String) { - runOnUiThread({ Toast.makeText(this, message, Toast.LENGTH_SHORT).show() }) + runOnUiThread { Toast.makeText(this, message, Toast.LENGTH_SHORT).show() } } /** @@ -193,7 +193,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { api = api ?: OpenPgpApi(this, mServiceConnection?.service) } - private fun decryptAndVerify(receivedIntent: Intent? = null): Unit { + private fun decryptAndVerify(receivedIntent: Intent? = null) { val data = receivedIntent ?: Intent() data.action = ACTION_DECRYPT_VERIFY @@ -293,26 +293,26 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { dialogBuilder.setView(checkLayout) dialogBuilder.setMessage(R.string.dialog_update_body) .setCancelable(false) - .setPositiveButton(R.string.dialog_update_positive, DialogInterface.OnClickListener { dialog, id -> + .setPositiveButton(R.string.dialog_update_positive) { _, _ -> run { calculateAndCommitHotp(entry) - if (rememberCheck.isChecked()) { + if (rememberCheck.isChecked) { val editor = settings.edit() editor.putBoolean("hotp_remember_check", true) editor.putBoolean("hotp_remember_choice", true) editor.commit() } } - }) - .setNegativeButton(R.string.dialog_update_negative, DialogInterface.OnClickListener { dialog, id -> - run { - calculateHotp(entry) - val editor = settings.edit() - editor.putBoolean("hotp_remember_check", true) - editor.putBoolean("hotp_remember_choice", false) - editor.commit() - } - }) + } + .setNegativeButton(R.string.dialog_update_negative) { _, _ -> + run { + calculateHotp(entry) + val editor = settings.edit() + editor.putBoolean("hotp_remember_check", true) + editor.putBoolean("hotp_remember_choice", false) + editor.commit() + } + } val updateDialog = dialogBuilder.create() updateDialog.setTitle(R.string.dialog_update_title) updateDialog.show() @@ -378,34 +378,33 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { val path = if (intent.getBooleanExtra("fromDecrypt", false)) fullPath else "$fullPath/$editName.gpg" - api?.executeApiAsync(data, iStream, oStream, { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { - OpenPgpApi.RESULT_CODE_SUCCESS -> { - try { - // TODO This might fail, we should check that the write is successful - val outputStream = FileUtils.openOutputStream(File(path)) - outputStream.write(oStream.toByteArray()) - outputStream.close() - - val returnIntent = Intent() - returnIntent.putExtra("CREATED_FILE", path) - returnIntent.putExtra("NAME", editName) - - // if coming from decrypt screen->edit button - if (intent.getBooleanExtra("fromDecrypt", false)) { - returnIntent.putExtra("OPERATION", "EDIT") - returnIntent.putExtra("needCommit", true) - } - setResult(RESULT_OK, returnIntent) - finish() - - } catch (e: Exception) { - Log.e(TAG, "An Exception occurred", e) + api?.executeApiAsync(data, iStream, oStream) { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { + OpenPgpApi.RESULT_CODE_SUCCESS -> { + try { + // TODO This might fail, we should check that the write is successful + val outputStream = FileUtils.openOutputStream(File(path)) + outputStream.write(oStream.toByteArray()) + outputStream.close() + + val returnIntent = Intent() + returnIntent.putExtra("CREATED_FILE", path) + returnIntent.putExtra("NAME", editName) + + // if coming from decrypt screen->edit button + if (intent.getBooleanExtra("fromDecrypt", false)) { + returnIntent.putExtra("OPERATION", "EDIT") + returnIntent.putExtra("needCommit", true) } + setResult(RESULT_OK, returnIntent) + finish() + } catch (e: Exception) { + Log.e(TAG, "An Exception occurred", e) } - OpenPgpApi.RESULT_CODE_ERROR -> handleError(result) } + OpenPgpApi.RESULT_CODE_ERROR -> handleError(result) + } - }) + } } @@ -415,7 +414,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { private fun editPassword() { setContentView(R.layout.encrypt_layout) generate_password?.setOnClickListener { - pwgenDialogFragment().show(fragmentManager, "generator") + pwgenDialogFragment().show(supportFragmentManager, "generator") } title = getString(R.string.edit_password_title) @@ -482,7 +481,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { private fun getKeyIds(receivedIntent: Intent? = null) { val data = receivedIntent ?: Intent() data.action = OpenPgpApi.ACTION_GET_KEY_IDS - api?.executeApiAsync(data, null, null, { result: Intent? -> + api?.executeApiAsync(data, null, null) { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { OpenPgpApi.RESULT_CODE_SUCCESS -> { try { @@ -503,7 +502,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID) OpenPgpApi.RESULT_CODE_ERROR -> handleError(result) } - }) + } } override fun onError(e: Exception?) {} @@ -737,11 +736,11 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { } companion object { - val OPEN_PGP_BOUND = 101 - val REQUEST_DECRYPT = 202 - val REQUEST_KEY_ID = 203 + const val OPEN_PGP_BOUND = 101 + const val REQUEST_DECRYPT = 202 + const val REQUEST_KEY_ID = 203 - val TAG = "PgpActivity" + const val TAG = "PgpActivity" private var delayTask: DelayShow? = null |
