Fix crash in MessageViewContainerFragment.onPendingIntentResult()

`onPendingIntentResult()` is called before the fragment is in the RESUMED state. This lead to an exception in the `messageViewFragment` property getter when it was checking the value of `isResumed`.
This commit is contained in:
cketti 2022-08-05 13:52:10 +02:00
parent 853c07e8f2
commit bf41af8cae

View file

@ -44,13 +44,17 @@ class MessageViewContainerFragment : Fragment() {
private val messageViewFragment: MessageViewFragment
get() {
check(isResumed)
val itemId = adapter.getItemId(messageReference)
// ViewPager2/FragmentStateAdapter don't provide an easy way to get hold of the Fragment for the active
// page. So we're using an implementation detail (the fragment tag) to find the fragment.
return childFragmentManager.findFragmentByTag("f$itemId") as MessageViewFragment
return findMessageViewFragment()
}
private fun findMessageViewFragment(): MessageViewFragment {
val itemId = adapter.getItemId(messageReference)
// ViewPager2/FragmentStateAdapter don't provide an easy way to get hold of the Fragment for the active
// page. So we're using an implementation detail (the fragment tag) to find the fragment.
return childFragmentManager.findFragmentByTag("f$itemId") as MessageViewFragment
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -221,7 +225,7 @@ class MessageViewContainerFragment : Fragment() {
}
fun onPendingIntentResult(requestCode: Int, resultCode: Int, data: Intent?) {
messageViewFragment.onPendingIntentResult(requestCode, resultCode, data)
findMessageViewFragment().onPendingIntentResult(requestCode, resultCode, data)
}
private class MessageViewContainerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {