Ensure stub is never resolved if not needed.

fork-5.53.8
Alex Hart 2022-06-27 10:04:39 -03:00 zatwierdzone przez Cody Henthorne
rodzic e10c20ffd7
commit 0ac5782f1f
2 zmienionych plików z 23 dodań i 10 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.stories.viewer.page package org.thoughtcrime.securesms.stories.viewer.page
import android.view.ViewStub import android.view.ViewStub
import androidx.core.view.isVisible
import org.thoughtcrime.securesms.blurhash.BlurHash import org.thoughtcrime.securesms.blurhash.BlurHash
import org.thoughtcrime.securesms.stories.StoryFirstTimeNavigationView import org.thoughtcrime.securesms.stories.StoryFirstTimeNavigationView
import org.thoughtcrime.securesms.util.views.Stub import org.thoughtcrime.securesms.util.views.Stub
@ -29,6 +30,22 @@ class StoryFirstNavigationStub(viewStub: ViewStub) : Stub<StoryFirstTimeNavigati
} }
} }
fun showIfAble(ableToShow: Boolean) {
if (ableToShow) {
get().show()
}
}
fun isVisible(): Boolean {
return resolved() && get().isVisible
}
fun hide() {
if (resolved()) {
get().hide()
}
}
override fun get(): StoryFirstTimeNavigationView { override fun get(): StoryFirstTimeNavigationView {
val needsResolve = !resolved() val needsResolve = !resolved()
val view = super.get() val view = super.get()

Wyświetl plik

@ -390,27 +390,27 @@ class StoryViewerPageFragment :
resumeProgress() resumeProgress()
} }
val wasDisplayingNavigationView = isFirstTimeNavVisible() val wasDisplayingNavigationView = storyFirstTimeNavigationViewStub.isVisible()
when { when {
state.hideChromeImmediate -> { state.hideChromeImmediate -> {
hideChromeImmediate() hideChromeImmediate()
storyCaptionContainer.visible = false storyCaptionContainer.visible = false
storyFirstTimeNavigationViewStub.takeIf { it.resolved() }?.get()?.hide() storyFirstTimeNavigationViewStub.hide()
} }
state.hideChrome -> { state.hideChrome -> {
hideChrome() hideChrome()
storyCaptionContainer.visible = true storyCaptionContainer.visible = true
storyFirstTimeNavigationViewStub.get().show() storyFirstTimeNavigationViewStub.showIfAble(!SignalStore.storyValues().userHasSeenFirstNavView)
} }
else -> { else -> {
showChrome() showChrome()
storyCaptionContainer.visible = true storyCaptionContainer.visible = true
storyFirstTimeNavigationViewStub.get().show() storyFirstTimeNavigationViewStub.showIfAble(!SignalStore.storyValues().userHasSeenFirstNavView)
} }
} }
val isDisplayingNavigationView = isFirstTimeNavVisible() val isDisplayingNavigationView = storyFirstTimeNavigationViewStub.isVisible()
if (isDisplayingNavigationView && Build.VERSION.SDK_INT >= 31) { if (isDisplayingNavigationView && Build.VERSION.SDK_INT >= 31) {
hideChromeImmediate() hideChromeImmediate()
storyContentContainer.setRenderEffect(RenderEffect.createBlurEffect(100f, 100f, Shader.TileMode.CLAMP)) storyContentContainer.setRenderEffect(RenderEffect.createBlurEffect(100f, 100f, Shader.TileMode.CLAMP))
@ -419,7 +419,7 @@ class StoryViewerPageFragment :
} }
if (wasDisplayingNavigationView xor isDisplayingNavigationView) { if (wasDisplayingNavigationView xor isDisplayingNavigationView) {
viewModel.setIsDisplayingFirstTimeNavigation(isFirstTimeNavVisible()) viewModel.setIsDisplayingFirstTimeNavigation(storyFirstTimeNavigationViewStub.isVisible())
} }
} }
@ -473,10 +473,6 @@ class StoryViewerPageFragment :
viewModel.setIsDisplayingForwardDialog(false) viewModel.setIsDisplayingForwardDialog(false)
} }
private fun isFirstTimeNavVisible(): Boolean {
return storyFirstTimeNavigationViewStub.takeIf { it.resolved() }?.get()?.isVisible ?: false
}
private fun calculateDurationForText(textContent: StoryPost.Content.TextContent): Long { private fun calculateDurationForText(textContent: StoryPost.Content.TextContent): Long {
val divisionsOf15 = textContent.length / CHARACTERS_PER_SECOND val divisionsOf15 = textContent.length / CHARACTERS_PER_SECOND
return TimeUnit.SECONDS.toMillis(divisionsOf15) + MIN_TEXT_STORY_PLAYBACK return TimeUnit.SECONDS.toMillis(divisionsOf15) + MIN_TEXT_STORY_PLAYBACK