diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-06-29 21:35:53 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-01 22:59:29 +0000 |
| commit | 09577326d4996ebea710a10688570599b11acee4 (patch) | |
| tree | fc910da4cae6588c69953065b7e0ab131add59d9 /android/src | |
| parent | 088b0e99985c166c44dfe79f60f9bbb9607070a6 (diff) | |
| download | mullvadvpn-09577326d4996ebea710a10688570599b11acee4.tar.xz mullvadvpn-09577326d4996ebea710a10688570599b11acee4.zip | |
Animate notification change transition
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/NotificationBanner.kt | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/NotificationBanner.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/NotificationBanner.kt index 17d8fd3e20..dd5de3a532 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/NotificationBanner.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/NotificationBanner.kt @@ -30,7 +30,16 @@ class NotificationBanner : FrameLayout { override fun onAnimationEnd(animation: Animator) { if (reversedAnimation) { // Banner is now hidden + val notification = notifications.current + visibility = View.INVISIBLE + + if (notification != null) { + // Notification changed, restart animation + update(notification) + reversedAnimation = false + animation.start() + } } } } @@ -60,11 +69,7 @@ class NotificationBanner : FrameLayout { private var reversedAnimation = false - val notifications = InAppNotificationController { notification -> - if (notification != null) { - update(notification) - } - + val notifications = InAppNotificationController { _ -> animateChange() } @@ -87,6 +92,8 @@ class NotificationBanner : FrameLayout { setOnClickListener { jobTracker.newUiJob("click") { onClick() } } + + visibility = View.INVISIBLE } fun onResume() { @@ -148,12 +155,17 @@ class NotificationBanner : FrameLayout { val notification = notifications.current if (notification != null && visibility == View.INVISIBLE) { + // Banner is not currently shown but must be shown reversedAnimation = false update(notification) animation.start() - } else if (!shouldShow && visibility == View.VISIBLE) { + } else if (visibility == View.VISIBLE && (!animation.isRunning() || !reversedAnimation)) { + // Either the banner is shown or it is in the process of being shown, but the + // notification must be hidden or replaced reversedAnimation = true animation.reverse() } + // If the banner is animating to be hidden, it will automatically start showing when the + // hide animation ends } } |
