use MaterialContainerTransform for ActionButton animation (#1961)
* use MaterialContainerTransform for ActionButton animation * fix back button in TabPreferenceActivity
This commit is contained in:
parent
e572e653ee
commit
53bd081802
3 changed files with 35 additions and 15 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue