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

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.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<ReaderActivityBinding, ReaderPresenter>()
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<ReaderActivityBinding, ReaderPresenter>()
applyAppTheme(preferences)
// Setup shared element transitions
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
findViewById<View>(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<View>(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)