From 2ff7f806dce524ee9141bbb63355e70277f6c91b Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Tue, 31 Jul 2018 04:36:59 -0400 Subject: [PATCH] Create custom ChangeHandler for controller animations --- .../com/moez/QKSMS/common/QkChangeHandler.kt | 73 +++++++++++++++++++ .../ConversationInfoController.kt | 6 +- .../feature/settings/SettingsController.kt | 15 ++-- .../themepicker/ThemePickerController.kt | 14 ++++ .../src/main/res/layout/about_controller.xml | 3 +- .../main/res/layout/container_activity.xml | 1 - .../main/res/layout/settings_controller.xml | 3 +- .../res/layout/swipe_actions_controller.xml | 3 +- .../res/layout/theme_picker_controller.xml | 1 + 9 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 presentation/src/main/java/com/moez/QKSMS/common/QkChangeHandler.kt diff --git a/presentation/src/main/java/com/moez/QKSMS/common/QkChangeHandler.kt b/presentation/src/main/java/com/moez/QKSMS/common/QkChangeHandler.kt new file mode 100644 index 00000000..b898a74e --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/common/QkChangeHandler.kt @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * This file is part of QKSMS. + * + * QKSMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QKSMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QKSMS. If not, see . + */ +package com.moez.QKSMS.common + +import android.animation.Animator +import android.animation.AnimatorSet +import android.animation.ObjectAnimator +import android.view.View +import android.view.ViewGroup +import android.view.animation.DecelerateInterpolator +import androidx.annotation.NonNull +import androidx.annotation.Nullable +import com.bluelinelabs.conductor.ControllerChangeHandler +import com.bluelinelabs.conductor.changehandler.AnimatorChangeHandler +import com.moez.QKSMS.common.util.extensions.dpToPx + +class QkChangeHandler(removesFromViewOnPush: Boolean = true) : AnimatorChangeHandler(250, removesFromViewOnPush) { + + @NonNull + override fun getAnimator(@NonNull container: ViewGroup, @Nullable from: View?, @Nullable to: View?, isPush: Boolean, toAddedToContainer: Boolean): Animator { + val animatorSet = AnimatorSet() + animatorSet.interpolator = DecelerateInterpolator() + + if (isPush) { + if (from != null) { + animatorSet.play(ObjectAnimator.ofFloat(from, View.TRANSLATION_X, -from.width.toFloat() / 4)) + } + if (to != null) { + to.translationZ = 8.dpToPx(to.context).toFloat() + animatorSet.play(ObjectAnimator.ofFloat(to, View.TRANSLATION_X, to.width.toFloat(), 0f)) + } + } else { + if (from != null) { + from.translationZ = 8.dpToPx(from.context).toFloat() + animatorSet.play(ObjectAnimator.ofFloat(from, View.TRANSLATION_X, from.width.toFloat())) + } + if (to != null) { + // Allow this to have a nice transition when coming off an aborted push animation + val fromLeft = from?.translationX ?: 0f + animatorSet.play(ObjectAnimator.ofFloat(to, View.TRANSLATION_X, fromLeft - to.width / 4, 0f)) + } + } + + return animatorSet + } + + override fun resetFromView(@NonNull from: View) { + from.translationX = 0f + from.translationZ = 0f + } + + @NonNull + override fun copy(): ControllerChangeHandler { + return QkChangeHandler(removesFromViewOnPush()) + } + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt index 549f50e9..e18f48d2 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt @@ -22,10 +22,10 @@ import android.text.InputFilter import android.view.View import androidx.appcompat.app.AlertDialog import com.bluelinelabs.conductor.RouterTransaction -import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.jakewharton.rxbinding2.view.clicks import com.moez.QKSMS.R import com.moez.QKSMS.common.Navigator +import com.moez.QKSMS.common.QkChangeHandler import com.moez.QKSMS.common.base.QkController import com.moez.QKSMS.common.util.extensions.animateLayoutChanges import com.moez.QKSMS.common.util.extensions.dpToPx @@ -157,8 +157,8 @@ class ConversationInfoController(val threadId: Long = 0) : QkController + ObjectAnimator.ofFloat(toolbar, "elevation", toolbar.elevation, 0f).start() + } + } + + override fun onDetach(view: View) { + super.onDetach(view) + + themedActivity?.supportActionBar?.let { toolbar -> + ObjectAnimator.ofFloat(toolbar, "elevation", toolbar.elevation, 8.dpToPx(toolbar.themedContext).toFloat()).start() + } } override fun showQksmsPlusSnackbar() { diff --git a/presentation/src/main/res/layout/about_controller.xml b/presentation/src/main/res/layout/about_controller.xml index 1231c44b..1c15ce29 100644 --- a/presentation/src/main/res/layout/about_controller.xml +++ b/presentation/src/main/res/layout/about_controller.xml @@ -20,7 +20,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?android:attr/windowBackground"> diff --git a/presentation/src/main/res/layout/settings_controller.xml b/presentation/src/main/res/layout/settings_controller.xml index 49c1e1ea..e4dd98e5 100644 --- a/presentation/src/main/res/layout/settings_controller.xml +++ b/presentation/src/main/res/layout/settings_controller.xml @@ -22,7 +22,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?android:attr/windowBackground"> + android:layout_height="match_parent" + android:background="?android:attr/windowBackground">