diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-06-03 15:01:02 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-06-03 16:26:08 +0000 |
| commit | 1d9dcd986f1abb840cbb1dc7920d9e50f6e8a98c (patch) | |
| tree | daacb23737a8e2e7c8da8a764270b40d17379d16 /android | |
| parent | 8361386fc2a99ee4d7496c8ccddc24a472cd9690 (diff) | |
| download | mullvadvpn-1d9dcd986f1abb840cbb1dc7920d9e50f6e8a98c.tar.xz mullvadvpn-1d9dcd986f1abb840cbb1dc7920d9e50f6e8a98c.zip | |
Add `NotificationBanner.onHeightChange` callback
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/NotificationBanner.kt | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/NotificationBanner.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/NotificationBanner.kt index 3965344f7a..447837fefd 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/NotificationBanner.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/NotificationBanner.kt @@ -5,8 +5,10 @@ import android.content.Intent import android.graphics.drawable.Drawable import android.net.Uri import android.view.View +import android.view.View.MeasureSpec import android.widget.ImageView import android.widget.TextView +import kotlin.properties.Delegates.observable import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job @@ -43,6 +45,12 @@ class NotificationBanner( private val message: TextView = parentView.findViewById(R.id.notification_message) private val icon: View = parentView.findViewById(R.id.notification_icon) + private var height: Int by observable(0) { _, oldValue, newValue -> + if (oldValue != newValue) { + onHeightChange?.invoke(newValue) + } + } + private var updateJob: Job? = null private var externalLink: ExternalLink? = null @@ -70,6 +78,10 @@ class NotificationBanner( } ) + var onHeightChange by observable<((Int) -> Unit)?>(null) { _, _, newListener -> + newListener?.invoke(height) + } + var keyState: KeygenEvent? = null set(value) { field = value @@ -242,6 +254,8 @@ class NotificationBanner( banner.setClickable(true) icon.visibility = View.VISIBLE } + + height = recalculateHeight() } private fun hide() { @@ -253,6 +267,17 @@ class NotificationBanner( } } + private fun recalculateHeight(): Int { + banner.apply { + val widthSpec = MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.AT_MOST) + val heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) + + measure(widthSpec, heightSpec) + + return measuredHeight + } + } + private fun onClick() { val externalLink = this.externalLink |
