From 408c7b2ca6a999eec22bbe401536841382dee4ad Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 1 Feb 2022 10:31:44 -0500 Subject: [PATCH] Avoid unnecessary transition setup in reader if not transitioning --- .../tachiyomi/ui/manga/MangaController.kt | 9 +++++++-- .../tachiyomi/ui/reader/ReaderActivity.kt | 20 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index e1d0e2ee88..d8711b1790 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -891,15 +891,20 @@ class MangaController : private fun openChapter(chapter: Chapter, sharedElement: View? = null) { val activity = activity ?: return - val intent = ReaderActivity.newIntent(activity, presenter.manga, chapter) activity.apply { + val intent = ReaderActivity.newIntent(activity, presenter.manga, chapter) if (sharedElement != null && Build.VERSION.SDK_INT != Build.VERSION_CODES.O) { val activityOptions = ActivityOptions.makeSceneTransitionAnimation( activity, sharedElement, ReaderActivity.SHARED_ELEMENT_NAME ) - startActivity(intent, activityOptions.toBundle()) + startActivity( + intent.apply { + putExtra(ReaderActivity.EXTRA_IS_TRANSITION, true) + }, + activityOptions.toBundle(), + ) } else { startActivity(intent) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 7d4953a222..4a0560dfcb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -43,6 +43,7 @@ import com.google.android.material.slider.Slider import com.google.android.material.transition.platform.MaterialContainerTransform import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback import dev.chrisbanes.insetter.applyInsetter +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga @@ -110,6 +111,7 @@ class ReaderActivity : BaseRxActivity() private const val ENABLED_BUTTON_IMAGE_ALPHA = 255 private const val DISABLED_BUTTON_IMAGE_ALPHA = 64 + const val EXTRA_IS_TRANSITION = "${BuildConfig.APPLICATION_ID}.READER_IS_TRANSITION" const val SHARED_ELEMENT_NAME = "reader_shared_element_root" } @@ -158,15 +160,17 @@ class ReaderActivity : BaseRxActivity() applyAppTheme(preferences) // Setup shared element transitions - window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS) - findViewById(android.R.id.content)?.let { contentView -> - contentView.transitionName = SHARED_ELEMENT_NAME - setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback()) - window.sharedElementEnterTransition = buildContainerTransform(true) - window.sharedElementReturnTransition = buildContainerTransform(false) + if (intent.extras?.getBoolean(EXTRA_IS_TRANSITION) == true) { + window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS) + findViewById(android.R.id.content)?.let { contentView -> + contentView.transitionName = SHARED_ELEMENT_NAME + setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback()) + window.sharedElementEnterTransition = buildContainerTransform(true) + window.sharedElementReturnTransition = buildContainerTransform(false) - // Postpone custom transition until manga ready - postponeEnterTransition() + // Postpone custom transition until manga ready + postponeEnterTransition() + } } super.onCreate(savedInstanceState)