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
Nicholas 2022-10-31 10:08:14 -04:00 zatwierdzone przez GitHub
rodzic bae070e60e
commit 9f2c7a65ac
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 15 dodań i 5 usunięć

Wyświetl plik

@ -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"

Wyświetl plik

@ -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)
}
}
}