From 44f7c9a5459fe42520021f7602a4927e90d6d48f Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 20 Oct 2019 11:14:49 +0200 Subject: [PATCH] Added animations for toolbar transitions --- .../java/com/topjohnwu/magisk/extensions/XView.kt | 11 ++++++++++- .../com/topjohnwu/magisk/redesign/MainActivity.kt | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/extensions/XView.kt b/app/src/main/java/com/topjohnwu/magisk/extensions/XView.kt index b34338d3d..dc7773f4a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/extensions/XView.kt +++ b/app/src/main/java/com/topjohnwu/magisk/extensions/XView.kt @@ -1,7 +1,11 @@ package com.topjohnwu.magisk.extensions import android.view.View +import android.view.ViewGroup import android.view.ViewTreeObserver +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import androidx.transition.AutoTransition +import androidx.transition.TransitionManager fun View.setOnViewReadyListener(callback: () -> Unit) = addOnGlobalLayoutListener(true, callback) @@ -11,4 +15,9 @@ fun View.addOnGlobalLayoutListener(oneShot: Boolean = false, callback: () -> Uni if (oneShot) viewTreeObserver.removeOnGlobalLayoutListener(this) callback() } - }) \ No newline at end of file + }) + +fun ViewGroup.startAnimations() { + val transition = AutoTransition().setInterpolator(FastOutSlowInInterpolator()) + TransitionManager.beginDelayedTransition(this, transition) +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt index 6b59776a0..02871a3af 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt @@ -16,6 +16,7 @@ import com.ncapdevi.fragnav.FragNavController import com.topjohnwu.magisk.Const import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding +import com.topjohnwu.magisk.extensions.startAnimations import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.redesign.compat.CompatActivity import com.topjohnwu.magisk.redesign.compat.CompatNavigationDelegate @@ -136,7 +137,8 @@ open class MainActivity : CompatActivity( viewModel.insets.value = insets } - fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) { + private fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) { + binding.mainToolbar.startAnimations() when { isEnabled -> binding.mainToolbar.setNavigationIcon(R.drawable.ic_back_md2) else -> binding.mainToolbar.navigationIcon = null