From 58b14cc65019ca0efff4ef296f9d9eacadd9573d Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 8 Apr 2020 19:43:25 +0530 Subject: 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 --- .../wireguard/android/fragment/TunnelListFragment.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ui/src') diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt index f19c7c2c..a4980779 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt @@ -4,6 +4,7 @@ */ package com.wireguard.android.fragment +import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.app.Activity import android.content.Intent @@ -305,6 +306,7 @@ class TunnelListFragment : BaseFragment() { private inner class ActionModeListener : ActionMode.Callback { val checkedItems: MutableCollection = HashSet() private var resources: Resources? = null + private var initialFabTranslation = 0f fun getCheckedItems(): ArrayList { return ArrayList(checkedItems) @@ -314,6 +316,7 @@ class TunnelListFragment : BaseFragment() { return when (item.itemId) { R.id.menu_action_delete -> { val copyCheckedItems = HashSet(checkedItems) + binding?.createFab?.translationY = initialFabTranslation Application.getTunnelManager().tunnels.thenAccept { tunnels -> val tunnelsToDelete = ArrayList() for (position in copyCheckedItems) tunnelsToDelete.add(tunnels[position]) @@ -343,6 +346,13 @@ class TunnelListFragment : BaseFragment() { if (activity != null) { 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) binding?.tunnelList?.adapter?.notifyDataSetChanged() return true @@ -351,6 +361,15 @@ class TunnelListFragment : BaseFragment() { override fun onDestroyActionMode(mode: ActionMode) { actionMode = null resources = null + binding?.createFab?.let { + if (it.translationY != initialFabTranslation) { + ObjectAnimator.ofFloat(it, View.TRANSLATION_Y, initialFabTranslation).apply { + duration = 400 + start() + } + } + } + checkedItems.clear() binding!!.tunnelList.adapter!!.notifyDataSetChanged() } -- cgit v1.2.3