Fix crash when trying to reply when there is no post to reply to.

fork-5.53.8
Alex Hart 2022-07-05 09:43:36 -03:00 zatwierdzone przez Greyson Parrelli
rodzic a51dfa1470
commit adbdb97a28
2 zmienionych plików z 23 dodań i 13 usunięć

Wyświetl plik

@ -25,7 +25,6 @@ import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.view.GestureDetectorCompat import androidx.core.view.GestureDetectorCompat
import androidx.core.view.animation.PathInterpolatorCompat import androidx.core.view.animation.PathInterpolatorCompat
import androidx.core.view.doOnNextLayout import androidx.core.view.doOnNextLayout
import androidx.core.view.isVisible
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
@ -257,8 +256,9 @@ class StoryViewerPageFragment :
} }
override fun onRequestSegmentProgressPercentage(): Float? { override fun onRequestSegmentProgressPercentage(): Float? {
val attachmentUri = if (viewModel.hasPost() && viewModel.getPost().content.isVideo()) { val storyPost = viewModel.getPost() ?: return null
viewModel.getPost().content.uri val attachmentUri = if (storyPost.content.isVideo()) {
storyPost.content.uri
} else { } else {
null null
} }
@ -292,7 +292,7 @@ class StoryViewerPageFragment :
return@subscribe return@subscribe
} }
if (!viewModel.hasPost() || !viewModel.getPost().content.isVideo() || volumeState.level < 0) { if (!viewModel.hasPost() || viewModel.getPost()?.content?.isVideo() != true || volumeState.level < 0) {
return@subscribe return@subscribe
} }
@ -578,8 +578,9 @@ class StoryViewerPageFragment :
} }
private fun resumeProgress() { private fun resumeProgress() {
if (progressBar.segmentCount != 0 && viewModel.hasPost()) { val storyPost = viewModel.getPost() ?: return
val postUri = viewModel.getPost().content.uri if (progressBar.segmentCount != 0) {
val postUri = storyPost.content.uri
if (postUri != null) { if (postUri != null) {
progressBar.start() progressBar.start()
videoControlsDelegate.resume(postUri) videoControlsDelegate.resume(postUri)
@ -593,20 +594,21 @@ class StoryViewerPageFragment :
} }
private fun startReply(isFromNotification: Boolean = false, groupReplyStartPosition: Int = -1) { private fun startReply(isFromNotification: Boolean = false, groupReplyStartPosition: Int = -1) {
val storyPostId: Long = viewModel.getPost().id val storyPost = viewModel.getPost() ?: return
val storyPostId: Long = storyPost.id
val replyFragment: DialogFragment = when (viewModel.getSwipeToReplyState()) { val replyFragment: DialogFragment = when (viewModel.getSwipeToReplyState()) {
StoryViewerPageState.ReplyState.NONE -> return StoryViewerPageState.ReplyState.NONE -> return
StoryViewerPageState.ReplyState.SELF -> StoryViewsBottomSheetDialogFragment.create(storyPostId) StoryViewerPageState.ReplyState.SELF -> StoryViewsBottomSheetDialogFragment.create(storyPostId)
StoryViewerPageState.ReplyState.GROUP -> StoryGroupReplyBottomSheetDialogFragment.create( StoryViewerPageState.ReplyState.GROUP -> StoryGroupReplyBottomSheetDialogFragment.create(
storyPostId, storyPostId,
viewModel.getPost().group!!.id, storyPost.group!!.id,
isFromNotification, isFromNotification,
groupReplyStartPosition groupReplyStartPosition
) )
StoryViewerPageState.ReplyState.PRIVATE -> StoryDirectReplyDialogFragment.create(storyPostId) StoryViewerPageState.ReplyState.PRIVATE -> StoryDirectReplyDialogFragment.create(storyPostId)
StoryViewerPageState.ReplyState.GROUP_SELF -> StoryViewsAndRepliesDialogFragment.create( StoryViewerPageState.ReplyState.GROUP_SELF -> StoryViewsAndRepliesDialogFragment.create(
storyPostId, storyPostId,
viewModel.getPost().group!!.id, storyPost.group!!.id,
if (isFromNotification) StoryViewsAndRepliesDialogFragment.StartPage.REPLIES else getViewsAndRepliesDialogStartPage(), if (isFromNotification) StoryViewsAndRepliesDialogFragment.StartPage.REPLIES else getViewsAndRepliesDialogStartPage(),
isFromNotification, isFromNotification,
groupReplyStartPosition groupReplyStartPosition
@ -631,7 +633,7 @@ class StoryViewerPageFragment :
} }
private fun getViewsAndRepliesDialogStartPage(): StoryViewsAndRepliesDialogFragment.StartPage { private fun getViewsAndRepliesDialogStartPage(): StoryViewsAndRepliesDialogFragment.StartPage {
return if (viewModel.getPost().replyCount > 0) { return if (viewModel.requirePost().replyCount > 0) {
StoryViewsAndRepliesDialogFragment.StartPage.REPLIES StoryViewsAndRepliesDialogFragment.StartPage.REPLIES
} else { } else {
StoryViewsAndRepliesDialogFragment.StartPage.VIEWS StoryViewsAndRepliesDialogFragment.StartPage.VIEWS

Wyświetl plik

@ -148,12 +148,20 @@ class StoryViewerPageViewModel(
return store.state.selectedPostIndex in store.state.posts.indices return store.state.selectedPostIndex in store.state.posts.indices
} }
fun getPost(): StoryPost { fun getPost(): StoryPost? {
return store.state.posts[store.state.selectedPostIndex] return if (hasPost()) {
store.state.posts[store.state.selectedPostIndex]
} else {
null
}
}
fun requirePost(): StoryPost {
return getPost()!!
} }
fun forceDownloadSelectedPost() { fun forceDownloadSelectedPost() {
disposables += repository.forceDownload(getPost()).subscribe() disposables += repository.forceDownload(requirePost()).subscribe()
} }
fun startDirectReply(storyId: Long, recipientId: RecipientId) { fun startDirectReply(storyId: Long, recipientId: RecipientId) {