summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-05 04:52:40 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-09-05 22:49:02 +0530
commit07607e0f376113721b70c8ddd1dca7e8641c0b2d (patch)
treede6f96f098f937eaec4e540154df9a34e52653d2 /app
parent5896acc8eb74804222bc120043bf98c70257dcff (diff)
PasswordFragment: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt6
1 files changed, 4 insertions, 2 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
index 2305ac94..36ea7ae4 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
@@ -23,6 +23,8 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.michaelbull.result.fold
+import com.github.michaelbull.result.runCatching
+import com.github.michaelbull.result.onFailure
import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.databinding.PasswordRecyclerViewBinding
import com.zeapo.pwdstore.git.BaseGitActivity
@@ -254,7 +256,7 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) {
override fun onAttach(context: Context) {
super.onAttach(context)
- try {
+ runCatching {
listener = object : OnFragmentInteractionListener {
override fun onFragmentInteraction(item: PasswordItem) {
if (settings.getString(PreferenceKeys.SORT_ORDER) == PasswordRepository.PasswordSortOrder.RECENTLY_USED.name) {
@@ -276,7 +278,7 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) {
}
}
}
- } catch (e: ClassCastException) {
+ }.onFailure {
throw ClassCastException("$context must implement OnFragmentInteractionListener")
}
}