From b6553bdc340454abb4164e040825c125ac530173 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Thu, 3 Feb 2022 09:40:48 +0700 Subject: [PATCH] ReaderActivity: Fix transition crash on Android 8 (#6542) --- .../eu/kanade/tachiyomi/ui/manga/MangaController.kt | 3 +-- .../eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 3 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 d8711b1790..06cb69ad94 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 @@ -6,7 +6,6 @@ import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.graphics.drawable.BitmapDrawable -import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.Menu @@ -893,7 +892,7 @@ class MangaController : val activity = activity ?: return activity.apply { val intent = ReaderActivity.newIntent(activity, presenter.manga, chapter) - if (sharedElement != null && Build.VERSION.SDK_INT != Build.VERSION_CODES.O) { + if (sharedElement != null) { val activityOptions = ActivityOptions.makeSceneTransitionAnimation( activity, sharedElement, 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 4a0560dfcb..b341457ca3 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 @@ -30,6 +30,7 @@ import android.view.animation.AnimationUtils import android.widget.FrameLayout import android.widget.Toast import androidx.core.graphics.ColorUtils +import androidx.core.transition.addListener import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat @@ -609,7 +610,14 @@ class ReaderActivity : BaseRxActivity() val newViewer = ReadingModeType.toViewer(presenter.getMangaReadingMode(), this) updateCropBordersShortcut() - setOrientation(presenter.getMangaOrientationType()) + if (window.sharedElementEnterTransition is MaterialContainerTransform) { + // Wait until transition is complete to avoid crash on API 26 + window.sharedElementEnterTransition.addListener( + onEnd = { setOrientation(presenter.getMangaOrientationType()) } + ) + } else { + setOrientation(presenter.getMangaOrientationType()) + } // Destroy previous viewer if there was one if (prevViewer != null) {