Skip to content

Commit

Permalink
Prevent shared element animation when we're not on the initial media.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and greyson-signal committed Feb 15, 2023
1 parent 6fbfb87 commit a3a29d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down

0 comments on commit a3a29d5

Please sign in to comment.