mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 08:23:00 +01:00
Fix IndexOutOfBoundsException in story viewer back press.
This commit is contained in:
committed by
Alex Hart
parent
1ba9793943
commit
7b4fe7ff40
@@ -91,7 +91,7 @@ class StoryViewerFragment :
|
||||
lifecycleDisposable.bindTo(viewLifecycleOwner)
|
||||
lifecycleDisposable += viewModel.state.observeOn(AndroidSchedulers.mainThread()).subscribe { state ->
|
||||
if (state.noPosts) {
|
||||
onBackPressed(adapter.getRecipientId(storyPager.currentItem))
|
||||
onBackPressed(adapter.getRecipientIdOrNull(storyPager.currentItem))
|
||||
}
|
||||
|
||||
adapter.setPages(state.pages)
|
||||
@@ -102,7 +102,7 @@ class StoryViewerFragment :
|
||||
pagerOnPageSelectedLock = false
|
||||
|
||||
if (state.page >= state.pages.size) {
|
||||
onBackPressed(adapter.getRecipientId(storyPager.currentItem))
|
||||
onBackPressed(adapter.getRecipientIdOrNull(storyPager.currentItem))
|
||||
lifecycleDisposable.clear()
|
||||
}
|
||||
}
|
||||
@@ -155,14 +155,14 @@ class StoryViewerFragment :
|
||||
viewLifecycleOwner,
|
||||
object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
onBackPressed(adapter.getRecipientId(storyPager.currentItem))
|
||||
onBackPressed(adapter.getRecipientIdOrNull(storyPager.currentItem))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun onBackPressed(currentId: RecipientId) {
|
||||
if (viewModel.getInitialRecipientId() != currentId) {
|
||||
private fun onBackPressed(currentId: RecipientId?) {
|
||||
if (currentId == null || viewModel.getInitialRecipientId() != currentId) {
|
||||
requireActivity().finish()
|
||||
} else {
|
||||
ActivityCompat.finishAfterTransition(requireActivity())
|
||||
|
||||
@@ -28,6 +28,10 @@ class StoryViewerPagerAdapter(
|
||||
return pages[position]
|
||||
}
|
||||
|
||||
fun getRecipientIdOrNull(position: Int): RecipientId? {
|
||||
return pages.getOrNull(position)
|
||||
}
|
||||
|
||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView)
|
||||
recyclerView.overScrollMode = RecyclerView.OVER_SCROLL_NEVER
|
||||
|
||||
Reference in New Issue
Block a user