From 53bd08180236ab4f90cb88872fb89b1df7696487 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Mon, 19 Oct 2020 14:57:55 +0200 Subject: [PATCH] use MaterialContainerTransform for ActionButton animation (#1961) * use MaterialContainerTransform for ActionButton animation * fix back button in TabPreferenceActivity --- app/build.gradle | 2 +- .../tusky/TabPreferenceActivity.kt | 36 ++++++++++++++----- .../res/layout/activity_tab_preference.xml | 12 +++---- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 012b3ddbd..97b87fe39 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -130,7 +130,7 @@ dependencies { implementation "androidx.room:room-rxjava2:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion" - implementation "com.google.android.material:material:1.2.0" + implementation "com.google.android.material:material:1.2.1" implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" diff --git a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt index 66c053617..6b1aaef9e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt @@ -15,19 +15,25 @@ package com.keylesspalace.tusky +import android.graphics.Color import android.os.Bundle import android.util.Log import android.view.MenuItem +import android.view.View import android.widget.FrameLayout import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.AppCompatEditText +import androidx.core.view.isVisible import androidx.core.view.updatePadding import androidx.lifecycle.Lifecycle import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import androidx.transition.TransitionManager import at.connyduck.sparkbutton.helpers.Utils +import com.google.android.material.transition.MaterialArcMotion +import com.google.android.material.transition.MaterialContainerTransform import com.keylesspalace.tusky.adapter.ItemInteractionListener import com.keylesspalace.tusky.adapter.ListSelectionAdapter import com.keylesspalace.tusky.adapter.TabAdapter @@ -129,19 +135,17 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene touchHelper.attachToRecyclerView(currentTabsRecyclerView) - actionButton.setOnClickListener { - actionButton.isExpanded = true + toggleFab(true) } scrim.setOnClickListener { - actionButton.isExpanded = false + toggleFab(false) } maxTabsInfo.text = getString(R.string.max_tab_number_reached, MAX_TAB_COUNT) updateAvailableTabs() - } override fun onTabAdded(tab: TabData) { @@ -150,7 +154,7 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene return } - actionButton.isExpanded = false + toggleFab(false) if (tab.id == HASHTAG) { showAddHashtagDialog() @@ -188,6 +192,22 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene currentTabsAdapter.notifyItemChanged(tabPosition) } + private fun toggleFab(expand: Boolean) { + val transition = MaterialContainerTransform().apply { + startView = if (expand) actionButton else sheet + val endView: View = if (expand) sheet else actionButton + this.endView = endView + addTarget(endView) + scrimColor = Color.TRANSPARENT + setPathMotion(MaterialArcMotion()) + } + + TransitionManager.beginDelayedTransition(tabPreferenceContainer, transition) + actionButton.visible(!expand) + sheet.visible(expand) + scrim.visible(expand) + } + private fun showAddHashtagDialog(tab: TabData? = null, tabPosition: Int = 0) { val frameLayout = FrameLayout(this) @@ -318,10 +338,10 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene } override fun onBackPressed() { - if (actionButton.isExpanded) { - actionButton.isExpanded = false - } else { + if (actionButton.isVisible) { super.onBackPressed() + } else { + toggleFab(false) } } diff --git a/app/src/main/res/layout/activity_tab_preference.xml b/app/src/main/res/layout/activity_tab_preference.xml index 9bc8d6d17..476b7cbda 100644 --- a/app/src/main/res/layout/activity_tab_preference.xml +++ b/app/src/main/res/layout/activity_tab_preference.xml @@ -2,6 +2,7 @@ @@ -19,8 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/scrimBackground" - android:visibility="invisible" - app:layout_behavior="@string/fab_transformation_scrim_behavior" /> + android:visibility="invisible" /> - + app:cardElevation="2dp"> - + + \ No newline at end of file