aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-05 20:44:15 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-09-05 22:49:38 +0530
commitbd49bcfb034910d7e1089348d0f5108e296dddf1 (patch)
treeb6b910872b336c2ae836ed7815fdbc8745b244f5
parent3a0bf37c000288a5ef5906b395a50be5fcfa7c7f (diff)
DecryptActivity: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt19
1 files changed, 12 insertions, 7 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt
index f2f50e8e..e0e82cd7 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt
@@ -16,6 +16,8 @@ import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult
import androidx.lifecycle.lifecycleScope
import com.github.ajalt.timberkt.e
+import com.github.michaelbull.result.onFailure
+import com.github.michaelbull.result.runCatching
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.databinding.DecryptLayoutBinding
import com.zeapo.pwdstore.model.PasswordEntry
@@ -68,10 +70,12 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
copyTextToClipboard(name)
true
}
- try {
- passwordLastChanged.text = resources.getString(R.string.last_changed, lastChangedString)
- } catch (e: RuntimeException) {
- passwordLastChanged.visibility = View.GONE
+ passwordLastChanged.run {
+ runCatching {
+ text = resources.getString(R.string.last_changed, lastChangedString)
+ }.onFailure {
+ visibility = View.GONE
+ }
}
}
}
@@ -142,7 +146,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
api?.executeApiAsync(data, inputStream, outputStream) { result ->
when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
OpenPgpApi.RESULT_CODE_SUCCESS -> {
- try {
+ runCatching {
val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
val showExtraContent = settings.getBoolean(PreferenceKeys.SHOW_EXTRA_CONTENT, true)
val monoTypeface = Typeface.createFromAsset(assets, "fonts/sourcecodepro.ttf")
@@ -198,7 +202,8 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
// then return to the standard 30 second affair.
val remainingTime = entry.totpPeriod - (System.currentTimeMillis() % entry.totpPeriod)
withContext(Dispatchers.Main) {
- otpText.setText(entry.calculateTotpCode() ?: "Error")
+ otpText.setText(entry.calculateTotpCode()
+ ?: "Error")
}
delay(remainingTime.seconds)
repeat(Int.MAX_VALUE) {
@@ -216,7 +221,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
if (settings.getBoolean(PreferenceKeys.COPY_ON_DECRYPT, false)) {
copyPasswordToClipboard(entry.password)
}
- } catch (e: Exception) {
+ }.onFailure { e ->
e(e)
}
}