浏览代码

Adopt OneWayFadeChangeHandler from SY

From https://github.com/jobobby04/TachiyomiSY/commit/d86f3ffad808f01d4f04f136c63c0e11f135748c
arkon 4 年之前
父节点
当前提交
e90b0aaf8b

+ 2 - 3
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<String>, requestCode: I
 
 fun Controller.withFadeTransaction(): RouterTransaction {
     return RouterTransaction.with(this)
-        .pushChangeHandler(FadeChangeHandler())
-        .popChangeHandler(FadeChangeHandler())
+        .pushChangeHandler(OneWayFadeChangeHandler())
+        .popChangeHandler(OneWayFadeChangeHandler())
 }

+ 0 - 1
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 {

+ 43 - 0
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())
+    }
+}