From 07607e0f376113721b70c8ddd1dca7e8641c0b2d Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 5 Sep 2020 04:52:40 +0530 Subject: PasswordFragment: use runCatching to replace exception handling Signed-off-by: Harsh Shandilya --- app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/src') 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") } } -- cgit v1.2.3