summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-05 20:20:54 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-09-05 22:49:04 +0530
commit117b5e1d3b65b204628c1e42e5ee4f92d0dad8b1 (patch)
tree0a483da74e9a9929e68dc9ebd53462e1efbe3262 /app/src/main
parent2041ec3f19318777c456ae6e2075f0aff74c45a7 (diff)
SelectFolderFragment: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.kt9
1 files changed, 5 insertions, 4 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.kt b/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.kt
index 7bc32211..e0aeaad7 100644
--- a/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.kt
@@ -11,6 +11,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
+import com.github.michaelbull.result.onFailure
+import com.github.michaelbull.result.runCatching
import com.zeapo.pwdstore.databinding.PasswordRecyclerViewBinding
import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter
import com.zeapo.pwdstore.utils.PasswordItem
@@ -51,7 +53,7 @@ class SelectFolderFragment : 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 (item.type == PasswordItem.TYPE_CATEGORY) {
@@ -60,9 +62,8 @@ class SelectFolderFragment : Fragment(R.layout.password_recycler_view) {
}
}
}
- } catch (e: ClassCastException) {
- throw ClassCastException(
- "$context must implement OnFragmentInteractionListener")
+ }.onFailure {
+ throw ClassCastException("$context must implement OnFragmentInteractionListener")
}
}