summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-04-19 12:48:40 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-04-19 14:11:18 +0530
commiteb5a30c3a9f1474e452d28032c238cc3738eb3d8 (patch)
treef368ef9fab91f5e09eafb96ad532b2aef1f856bd /app/src/main/java
parente5d178ea3ca29367593bfc92e8f95e17dcaba459 (diff)
PasswordFragment: animate FAB in action mode
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt29
1 files changed, 27 insertions, 2 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
index eb97f1b8..5e12697d 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.kt
@@ -13,6 +13,8 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
+import android.view.animation.Animation
+import android.view.animation.AnimationUtils
import androidx.appcompat.view.ActionMode
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@@ -156,7 +158,7 @@ class PasswordFragment : Fragment() {
// Inflate a menu resource providing context menu items
mode.menuInflater.inflate(R.menu.context_pass, menu)
// hide the fab
- binding.fab.visibility = View.GONE
+ animateFab(false)
return true
}
@@ -202,7 +204,30 @@ class PasswordFragment : Fragment() {
recyclerAdapter.requireSelectionTracker().clearSelection()
actionMode = null
// show the fab
- binding.fab.visibility = View.VISIBLE
+ animateFab(true)
+ }
+
+ private fun animateFab(show: Boolean) = with(binding.fab) {
+ val animation = AnimationUtils.loadAnimation(
+ context, if (show) R.anim.scale_up else R.anim.scale_down
+ )
+ animation.setAnimationListener(object : Animation.AnimationListener {
+ override fun onAnimationRepeat(animation: Animation?) {
+ }
+
+ override fun onAnimationEnd(animation: Animation?) {
+ if (!show) visibility = View.GONE
+ }
+
+ override fun onAnimationStart(animation: Animation?) {
+ if (show) visibility = View.VISIBLE
+ }
+ })
+ animate().rotationBy(if (show) -90f else 90f)
+ .setStartDelay(if (show) 100 else 0)
+ .setDuration(100)
+ .start()
+ startAnimation(animation)
}
}