From e90b0aaf8bb14e4b3070e5353cdd3f892d7cca6f Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 23 Aug 2020 10:42:20 -0400 Subject: [PATCH] Adopt OneWayFadeChangeHandler from SY From https://github.com/jobobby04/TachiyomiSY/commit/d86f3ffad808f01d4f04f136c63c0e11f135748c --- .../ui/base/controller/ConductorExtensions.kt | 5 +-- .../ui/base/controller/DialogController.kt | 1 - .../controller/OneWayFadeChangeHandler.kt | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt index ef42399129..f5c2277ace 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt @@ -6,7 +6,6 @@ import androidx.core.content.ContextCompat import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction -import com.bluelinelabs.conductor.changehandler.FadeChangeHandler fun Router.popControllerWithTag(tag: String): Boolean { val controller = getControllerWithTag(tag) @@ -30,6 +29,6 @@ fun Controller.requestPermissionsSafe(permissions: Array, requestCode: I fun Controller.withFadeTransaction(): RouterTransaction { return RouterTransaction.with(this) - .pushChangeHandler(FadeChangeHandler()) - .popChangeHandler(FadeChangeHandler()) + .pushChangeHandler(OneWayFadeChangeHandler()) + .popChangeHandler(OneWayFadeChangeHandler()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt index 0e487cb03e..321d55c402 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt @@ -14,7 +14,6 @@ import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler * A controller that displays a dialog window, floating on top of its activity's window. * This is a wrapper over [Dialog] object like [android.app.DialogFragment]. * - * * Implementations should override this class and implement [.onCreateDialog] to create a custom dialog, such as an [android.app.AlertDialog] */ abstract class DialogController : RestoreViewOnCreateController { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt new file mode 100644 index 0000000000..b1209e0b4e --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt @@ -0,0 +1,43 @@ +package eu.kanade.tachiyomi.ui.base.controller + +import android.animation.Animator +import android.animation.AnimatorSet +import android.view.View +import android.view.ViewGroup +import com.bluelinelabs.conductor.ControllerChangeHandler +import com.bluelinelabs.conductor.changehandler.FadeChangeHandler + +/** + * A variation of [FadeChangeHandler] that only fades in. + */ +class OneWayFadeChangeHandler : FadeChangeHandler { + constructor() + constructor(removesFromViewOnPush: Boolean) : super(removesFromViewOnPush) + constructor(duration: Long) : super(duration) + constructor(duration: Long, removesFromViewOnPush: Boolean) : super( + duration, + removesFromViewOnPush + ) + + override fun getAnimator( + container: ViewGroup, + from: View?, + to: View?, + isPush: Boolean, + toAddedToContainer: Boolean + ): Animator { + if (to != null) { + return super.getAnimator(container, from, to, isPush, toAddedToContainer) + } + + if (from != null && (!isPush || removesFromViewOnPush())) { + container.removeView(from) + } + + return AnimatorSet() + } + + override fun copy(): ControllerChangeHandler { + return OneWayFadeChangeHandler(animationDuration, removesFromViewOnPush()) + } +}