Avoid unnecessary transition setup in reader if not transitioning

This commit is contained in:
arkon 2022-02-01 10:31:44 -05:00
parent 271253fd0b
commit 408c7b2ca6
2 changed files with 19 additions and 10 deletions

View File

@ -891,15 +891,20 @@ class MangaController :
private fun openChapter(chapter: Chapter, sharedElement: View? = null) { private fun openChapter(chapter: Chapter, sharedElement: View? = null) {
val activity = activity ?: return val activity = activity ?: return
val intent = ReaderActivity.newIntent(activity, presenter.manga, chapter)
activity.apply { activity.apply {
val intent = ReaderActivity.newIntent(activity, presenter.manga, chapter)
if (sharedElement != null && Build.VERSION.SDK_INT != Build.VERSION_CODES.O) { if (sharedElement != null && Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
sharedElement, sharedElement,
ReaderActivity.SHARED_ELEMENT_NAME ReaderActivity.SHARED_ELEMENT_NAME
) )
startActivity(intent, activityOptions.toBundle()) startActivity(
intent.apply {
putExtra(ReaderActivity.EXTRA_IS_TRANSITION, true)
},
activityOptions.toBundle(),
)
} else { } else {
startActivity(intent) startActivity(intent)
} }

View File

@ -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.MaterialContainerTransform
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback
import dev.chrisbanes.insetter.applyInsetter import dev.chrisbanes.insetter.applyInsetter
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
@ -110,6 +111,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
private const val ENABLED_BUTTON_IMAGE_ALPHA = 255 private const val ENABLED_BUTTON_IMAGE_ALPHA = 255
private const val DISABLED_BUTTON_IMAGE_ALPHA = 64 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" const val SHARED_ELEMENT_NAME = "reader_shared_element_root"
} }
@ -158,15 +160,17 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
applyAppTheme(preferences) applyAppTheme(preferences)
// Setup shared element transitions // Setup shared element transitions
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS) if (intent.extras?.getBoolean(EXTRA_IS_TRANSITION) == true) {
findViewById<View>(android.R.id.content)?.let { contentView -> window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
contentView.transitionName = SHARED_ELEMENT_NAME findViewById<View>(android.R.id.content)?.let { contentView ->
setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback()) contentView.transitionName = SHARED_ELEMENT_NAME
window.sharedElementEnterTransition = buildContainerTransform(true) setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback())
window.sharedElementReturnTransition = buildContainerTransform(false) window.sharedElementEnterTransition = buildContainerTransform(true)
window.sharedElementReturnTransition = buildContainerTransform(false)
// Postpone custom transition until manga ready // Postpone custom transition until manga ready
postponeEnterTransition() postponeEnterTransition()
}
} }
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)