From eef6b7e6545f825b48a4162f39109045b5d00590 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Thu, 28 Jun 2018 11:48:50 +0300 Subject: [PATCH] Improve animation --- .../telegram/ui/MyLocationTabFragment.kt | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index bf1828024f..4b49ab6f96 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -6,7 +6,6 @@ import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable import android.os.Build import android.os.Bundle -import android.support.annotation.ColorRes import android.support.design.widget.AppBarLayout import android.support.v4.app.Fragment import android.support.v4.content.ContextCompat @@ -216,30 +215,27 @@ class MyLocationTabFragment : Fragment(), TelegramListener { searchBox.layoutParams = params } - val animatorSet = AnimatorSet() - animatorSet.duration = 200 - animatorSet.playTogether(cornerAnimator, marginAnimator) - if (appBarCollapsed) { - animatorSet.addListener(object : AnimatorListenerAdapter() { + AnimatorSet().apply { + duration = 200 + playTogether(cornerAnimator, marginAnimator) + addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { - if (appBarCollapsed) { - updateTitleTextColor(R.color.app_bar_title_light) - if (Build.VERSION.SDK_INT >= 21) { - appBarLayout.outlineProvider = appBarOutlineProvider - } + updateTitleTextColor() + if (appBarCollapsed && Build.VERSION.SDK_INT >= 21) { + appBarLayout.outlineProvider = appBarOutlineProvider } } }) - } else { - updateTitleTextColor(R.color.ctrl_active_light) - if (Build.VERSION.SDK_INT >= 21) { - appBarLayout.outlineProvider = null - } + start() + } + + if (!appBarCollapsed && Build.VERSION.SDK_INT >= 21) { + appBarLayout.outlineProvider = null } - animatorSet.start() } - private fun updateTitleTextColor(@ColorRes color: Int) { + private fun updateTitleTextColor() { + val color = if (appBarCollapsed) R.color.app_bar_title_light else R.color.ctrl_active_light context?.also { title.setTextColor(ContextCompat.getColor(it, color)) }