ui: animate fab position in tunnel deletion flow

When tunnel deletion is triggered we don't bother with animation theatrics
because the resulting Snackbar needs this fab to be its anchor, which it can't
do if its outside the screen or busy animating.

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-04-08 19:43:25 +05:30
parent 3fa8e09545
commit 58b14cc650
No known key found for this signature in database
GPG Key ID: 366D7BBAD1031E80

View File

@ -4,6 +4,7 @@
*/ */
package com.wireguard.android.fragment package com.wireguard.android.fragment
import android.animation.ObjectAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
@ -305,6 +306,7 @@ class TunnelListFragment : BaseFragment() {
private inner class ActionModeListener : ActionMode.Callback { private inner class ActionModeListener : ActionMode.Callback {
val checkedItems: MutableCollection<Int> = HashSet() val checkedItems: MutableCollection<Int> = HashSet()
private var resources: Resources? = null private var resources: Resources? = null
private var initialFabTranslation = 0f
fun getCheckedItems(): ArrayList<Int> { fun getCheckedItems(): ArrayList<Int> {
return ArrayList(checkedItems) return ArrayList(checkedItems)
@ -314,6 +316,7 @@ class TunnelListFragment : BaseFragment() {
return when (item.itemId) { return when (item.itemId) {
R.id.menu_action_delete -> { R.id.menu_action_delete -> {
val copyCheckedItems = HashSet(checkedItems) val copyCheckedItems = HashSet(checkedItems)
binding?.createFab?.translationY = initialFabTranslation
Application.getTunnelManager().tunnels.thenAccept { tunnels -> Application.getTunnelManager().tunnels.thenAccept { tunnels ->
val tunnelsToDelete = ArrayList<ObservableTunnel>() val tunnelsToDelete = ArrayList<ObservableTunnel>()
for (position in copyCheckedItems) tunnelsToDelete.add(tunnels[position]) for (position in copyCheckedItems) tunnelsToDelete.add(tunnels[position])
@ -343,6 +346,13 @@ class TunnelListFragment : BaseFragment() {
if (activity != null) { if (activity != null) {
resources = activity!!.resources resources = activity!!.resources
} }
binding?.createFab?.let {
initialFabTranslation = it.translationY
ObjectAnimator.ofFloat(it, View.TRANSLATION_Y, 400f).apply {
duration = 400
start()
}
}
mode.menuInflater.inflate(R.menu.tunnel_list_action_mode, menu) mode.menuInflater.inflate(R.menu.tunnel_list_action_mode, menu)
binding?.tunnelList?.adapter?.notifyDataSetChanged() binding?.tunnelList?.adapter?.notifyDataSetChanged()
return true return true
@ -351,6 +361,15 @@ class TunnelListFragment : BaseFragment() {
override fun onDestroyActionMode(mode: ActionMode) { override fun onDestroyActionMode(mode: ActionMode) {
actionMode = null actionMode = null
resources = null resources = null
binding?.createFab?.let {
if (it.translationY != initialFabTranslation) {
ObjectAnimator.ofFloat(it, View.TRANSLATION_Y, initialFabTranslation).apply {
duration = 400
start()
}
}
}
checkedItems.clear() checkedItems.clear()
binding!!.tunnelList.adapter!!.notifyDataSetChanged() binding!!.tunnelList.adapter!!.notifyDataSetChanged()
} }