Fix freeze of first story first post.

fork-5.53.8
Alex Hart 2022-05-12 13:31:13 -03:00 zatwierdzone przez Cody Henthorne
rodzic bcfe2fef72
commit e51841a28b
4 zmienionych plików z 50 dodań i 2 usunięć

Wyświetl plik

@ -257,6 +257,7 @@ class StoryViewerPageFragment :
progressBar.setPosition(viewModel.getRestartIndex())
videoControlsDelegate.restart()
}
viewModel.setIsFirstPage(parentState.page == 0)
viewModel.setIsSelectedPage(true)
when (parentState.crossfadeSource) {
is StoryViewerState.CrossfadeSource.TextModel -> storyCrossfader.setSourceView(parentState.crossfadeSource.storyTextPostModel)

Wyświetl plik

@ -3,7 +3,8 @@ package org.thoughtcrime.securesms.stories.viewer.page
data class StoryViewerPageState(
val posts: List<StoryPost> = emptyList(),
val selectedPostIndex: Int = 0,
val replyState: ReplyState = ReplyState.NONE
val replyState: ReplyState = ReplyState.NONE,
val isFirstPage: Boolean = false
) {
/**
* Indicates which Reply method is available when the user swipes on the dialog

Wyświetl plik

@ -116,7 +116,9 @@ class StoryViewerPageViewModel(
}
val postIndex = store.state.selectedPostIndex
setSelectedPostIndex(max(-1, postIndex - 1))
val minIndex = if (store.state.isFirstPage) 0 else -1
setSelectedPostIndex(max(minIndex, postIndex - 1))
}
fun getRestartIndex(): Int {
@ -155,6 +157,10 @@ class StoryViewerPageViewModel(
storyViewerPlaybackStore.update { it.copy(isDisplayingSlate = isDisplayingSlate) }
}
fun setIsFirstPage(isFirstPage: Boolean) {
store.update { it.copy(isFirstPage = isFirstPage) }
}
fun setIsSelectedPage(isSelectedPage: Boolean) {
storyViewerPlaybackStore.update { it.copy(isSelectedPage = isSelectedPage) }
}

Wyświetl plik

@ -38,6 +38,46 @@ class StoryViewerPageViewModelTest {
RxJavaPlugins.reset()
}
@Test
fun `Given first page and first post, when I goToPreviousPost, then I expect storyIndex to be 0`() {
// GIVEN
val storyPosts = createStoryPosts(3) { true }
whenever(repository.getStoryPostsFor(any())).thenReturn(Observable.just(storyPosts))
val testSubject = createTestSubject()
testSubject.setIsFirstPage(true)
testScheduler.triggerActions()
// WHEN
testSubject.goToPreviousPost()
testScheduler.triggerActions()
// THEN
val testSubscriber = testSubject.state.test()
testSubscriber.assertValueAt(0) { it.selectedPostIndex == 0 }
}
@Test
fun `Given first page and second post, when I goToPreviousPost, then I expect storyIndex to be 0`() {
// GIVEN
val storyPosts = createStoryPosts(3) { true }
whenever(repository.getStoryPostsFor(any())).thenReturn(Observable.just(storyPosts))
val testSubject = createTestSubject()
testSubject.setIsFirstPage(true)
testScheduler.triggerActions()
testSubject.goToNextPost()
testScheduler.triggerActions()
// WHEN
testSubject.goToPreviousPost()
testScheduler.triggerActions()
// THEN
val testSubscriber = testSubject.state.test()
testSubscriber.assertValueAt(0) { it.selectedPostIndex == 0 }
}
@Test
fun `Given no initial story and 3 records all viewed, when I initialize, then I expect storyIndex to be 0`() {
// GIVEN