Prevent shared element animation when we're not on the initial media.

This commit is contained in:
Alex Hart
2023-02-15 12:13:50 -04:00
committed by Greyson Parrelli
parent 6fbfb87bd6
commit a3a29d5cb2
2 changed files with 16 additions and 2 deletions

View File

@@ -25,6 +25,9 @@ class MediaPreviewV2Activity : PassphraseRequiredActivity(), VoiceNoteMediaContr
private val viewModel: MediaPreviewV2ViewModel by viewModels()
private val lifecycleDisposable = LifecycleDisposable()
private val args by lazy {
MediaIntentFactory.requireArguments(intent.extras!!)
}
private lateinit var transitionImageView: ImageView
@@ -34,8 +37,6 @@ class MediaPreviewV2Activity : PassphraseRequiredActivity(), VoiceNoteMediaContr
}
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
val args = MediaIntentFactory.requireArguments(intent.extras!!)
if (MediaPreviewCache.drawable != null) {
val originalCorners = ShapeAppearanceModel.Builder()
.setTopLeftCornerSize(args.sharedElementArgs.topLeft)
@@ -122,6 +123,14 @@ class MediaPreviewV2Activity : PassphraseRequiredActivity(), VoiceNoteMediaContr
MediaPreviewCache.drawable = null
}
override fun finishAfterTransition() {
if (viewModel.shouldFinishAfterTransition(args.initialMediaUri)) {
super.finishAfterTransition()
} else {
super.finish()
}
}
companion object {
private const val FRAGMENT_TAG = "media_preview_fragment_v2"
const val SHARED_ELEMENT_TRANSITION_NAME = "thumb"

View File

@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.mediapreview
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.lifecycle.ViewModel
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Completable
@@ -31,6 +32,10 @@ class MediaPreviewV2ViewModel : ViewModel() {
store.update { it.copy(isInSharedAnimation = isInSharedAnimation) }
}
fun shouldFinishAfterTransition(initialMediaUri: Uri): Boolean {
return currentPosition in store.state.mediaRecords.indices && store.state.mediaRecords[currentPosition].toMedia()?.uri == initialMediaUri
}
fun fetchAttachments(context: Context, startingAttachmentId: AttachmentId, threadId: Long, sorting: MediaTable.Sorting, forceRefresh: Boolean = false) {
if (store.state.loadState == MediaPreviewV2State.LoadState.INIT || forceRefresh) {
disposables += store.update(repository.getAttachments(context, startingAttachmentId, threadId, sorting)) { result: MediaPreviewRepository.Result, oldState: MediaPreviewV2State ->