mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Move load-state into its own data-store.
This commit is contained in:
committed by
Greyson Parrelli
parent
e8570c3680
commit
4359336fd5
@@ -0,0 +1,8 @@
|
||||
package org.thoughtcrime.securesms.stories.viewer
|
||||
|
||||
data class StoryLoadState(
|
||||
val isContentReady: Boolean = false,
|
||||
val isCrossfaderReady: Boolean = false
|
||||
) {
|
||||
fun isReady(): Boolean = isContentReady && isCrossfaderReady
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import androidx.viewpager2.widget.ViewPager2
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import org.signal.core.util.getParcelableArrayListCompat
|
||||
import org.signal.core.util.getParcelableCompat
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
@@ -115,8 +116,11 @@ class StoryViewerFragment :
|
||||
if (state.skipCrossfade) {
|
||||
viewModel.setCrossfaderIsReady(true)
|
||||
}
|
||||
}
|
||||
|
||||
if (state.loadState.isReady()) {
|
||||
lifecycleDisposable += viewModel.loadState.subscribe {
|
||||
if (it.isReady()) {
|
||||
Log.d(TAG, "Content is ready, clearing crossfader.")
|
||||
storyCrossfader.alpha = 0f
|
||||
}
|
||||
}
|
||||
@@ -203,6 +207,8 @@ class StoryViewerFragment :
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(StoryViewerFragment::class.java)
|
||||
|
||||
private const val ARGS = "args"
|
||||
private const val HIDDEN = "hidden"
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ data class StoryViewerState(
|
||||
val page: Int = -1,
|
||||
val crossfadeSource: CrossfadeSource,
|
||||
val crossfadeTarget: CrossfadeTarget? = null,
|
||||
val loadState: LoadState = LoadState(),
|
||||
val skipCrossfade: Boolean = false,
|
||||
val noPosts: Boolean = false
|
||||
) {
|
||||
@@ -26,11 +25,4 @@ data class StoryViewerState(
|
||||
object None : CrossfadeTarget()
|
||||
data class Record(val messageRecord: MmsMessageRecord) : CrossfadeTarget()
|
||||
}
|
||||
|
||||
data class LoadState(
|
||||
val isContentReady: Boolean = false,
|
||||
val isCrossfaderReady: Boolean = false
|
||||
) {
|
||||
fun isReady(): Boolean = isContentReady && isCrossfaderReady
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.Flowable
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
@@ -34,10 +35,13 @@ class StoryViewerViewModel(
|
||||
)
|
||||
)
|
||||
|
||||
private val loadStore = RxStore(StoryLoadState())
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
val stateSnapshot: StoryViewerState get() = store.state
|
||||
val state: Flowable<StoryViewerState> = store.stateFlowable
|
||||
val loadState: Flowable<StoryLoadState> = loadStore.stateFlowable.distinctUntilChanged().observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
private val hidden = mutableSetOf<RecipientId>()
|
||||
|
||||
@@ -47,7 +51,7 @@ class StoryViewerViewModel(
|
||||
private val childScrollStatePublisher: BehaviorSubject<Boolean> = BehaviorSubject.createDefault(false)
|
||||
val allowParentScrolling: Observable<Boolean> = Observable.combineLatest(
|
||||
childScrollStatePublisher.distinctUntilChanged(),
|
||||
state.toObservable().map { it.loadState.isReady() }.distinctUntilChanged()
|
||||
loadState.toObservable().map { it.isReady() }.distinctUntilChanged()
|
||||
) { a, b -> !a && b }
|
||||
|
||||
var hasConsumedInitialState = false
|
||||
@@ -80,14 +84,14 @@ class StoryViewerViewModel(
|
||||
}
|
||||
|
||||
fun setContentIsReady() {
|
||||
store.update {
|
||||
it.copy(loadState = it.loadState.copy(isContentReady = true))
|
||||
loadStore.update {
|
||||
it.copy(isContentReady = true)
|
||||
}
|
||||
}
|
||||
|
||||
fun setCrossfaderIsReady(isReady: Boolean) {
|
||||
store.update {
|
||||
it.copy(loadState = it.loadState.copy(isCrossfaderReady = isReady))
|
||||
loadStore.update {
|
||||
it.copy(isCrossfaderReady = isReady)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +155,7 @@ class StoryViewerViewModel(
|
||||
override fun onCleared() {
|
||||
disposables.clear()
|
||||
store.dispose()
|
||||
loadStore.dispose()
|
||||
}
|
||||
|
||||
fun setSelectedPage(page: Int) {
|
||||
|
||||
@@ -370,10 +370,12 @@ class StoryViewerPageFragment :
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleDisposable += sharedViewModel.state.distinctUntilChanged().observeOn(AndroidSchedulers.mainThread()).subscribe { parentState ->
|
||||
viewModel.setIsRunningSharedElementAnimation(!parentState.loadState.isCrossfaderReady)
|
||||
storyContentContainer.visible = parentState.loadState.isCrossfaderReady
|
||||
lifecycleDisposable += sharedViewModel.loadState.subscribe {
|
||||
viewModel.setIsRunningSharedElementAnimation(!it.isCrossfaderReady)
|
||||
storyContentContainer.visible = it.isCrossfaderReady
|
||||
}
|
||||
|
||||
lifecycleDisposable += sharedViewModel.state.distinctUntilChanged().observeOn(AndroidSchedulers.mainThread()).subscribe { parentState ->
|
||||
if (parentState.pages.size <= parentState.page) {
|
||||
viewModel.setIsSelectedPage(false)
|
||||
} else if (storyViewerPageArgs.recipientId == parentState.pages[parentState.page]) {
|
||||
|
||||
Reference in New Issue
Block a user