kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix lifecycle state for media preview.
After a fragment is destroyed, the media remains loaded in the view model, and it is up to the re-created fragment to take that loaded data and make it ready to be viewed.main
rodzic
bae070e60e
commit
9f2c7a65ac
|
@ -292,10 +292,10 @@ class MediaPreviewV2Fragment : Fragment(R.layout.fragment_media_preview_v2), Med
|
|||
ViewCompat.setOnApplyWindowInsetsListener(viewToAnchor) { view: View, windowInsetsCompat: WindowInsetsCompat ->
|
||||
val layoutParams = view.layoutParams as MarginLayoutParams
|
||||
layoutParams.setMargins(
|
||||
windowInsetsCompat.getSystemWindowInsetLeft(),
|
||||
windowInsetsCompat.systemWindowInsetLeft,
|
||||
layoutParams.topMargin,
|
||||
windowInsetsCompat.getSystemWindowInsetRight(),
|
||||
windowInsetsCompat.getSystemWindowInsetBottom()
|
||||
windowInsetsCompat.systemWindowInsetRight,
|
||||
windowInsetsCompat.systemWindowInsetBottom
|
||||
)
|
||||
view.layoutParams = layoutParams
|
||||
windowInsetsCompat
|
||||
|
@ -440,6 +440,11 @@ class MediaPreviewV2Fragment : Fragment(R.layout.fragment_media_preview_v2), Med
|
|||
getMediaPreviewFragmentFromChildFragmentManager(binding.mediaPager.currentItem)?.pause()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
viewModel.onDestroyView()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ARGS_KEY: String = "args"
|
||||
|
||||
|
|
|
@ -26,8 +26,7 @@ class MediaPreviewV2ViewModel : ViewModel() {
|
|||
|
||||
fun fetchAttachments(startingAttachmentId: AttachmentId, threadId: Long, sorting: MediaDatabase.Sorting, forceRefresh: Boolean = false) {
|
||||
if (store.state.loadState == MediaPreviewV2State.LoadState.INIT || forceRefresh) {
|
||||
disposables += store.update(repository.getAttachments(startingAttachmentId, threadId, sorting)) {
|
||||
result: MediaPreviewRepository.Result, oldState: MediaPreviewV2State ->
|
||||
disposables += store.update(repository.getAttachments(startingAttachmentId, threadId, sorting)) { result: MediaPreviewRepository.Result, oldState: MediaPreviewV2State ->
|
||||
if (oldState.leftIsRecent) {
|
||||
oldState.copy(
|
||||
position = result.initialPosition,
|
||||
|
@ -76,4 +75,10 @@ class MediaPreviewV2ViewModel : ViewModel() {
|
|||
disposables.dispose()
|
||||
store.dispose()
|
||||
}
|
||||
|
||||
fun onDestroyView() {
|
||||
store.update { oldState ->
|
||||
oldState.copy(loadState = MediaPreviewV2State.LoadState.DATA_LOADED)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue