ReaderActivity: Fix transition crash on Android 8 (#6542)

This commit is contained in:
Ivan Iskandar 2022-02-03 09:40:48 +07:00 committed by GitHub
parent 19fe689969
commit b6553bdc34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -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,

View File

@ -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<ReaderActivityBinding, ReaderPresenter>()
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) {