diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-03-14 17:30:49 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-03-15 19:18:53 +0000 |
| commit | 9f79c2e3a35ad0c44b300ca50a27feb19464e8d0 (patch) | |
| tree | e8f04bee0b72b46d99ba238b33e08a82d0e0836f /android | |
| parent | 3671bf59dca9fe5a0797f1e906e3a428a683db00 (diff) | |
| download | mullvadvpn-9f79c2e3a35ad0c44b300ca50a27feb19464e8d0.tar.xz mullvadvpn-9f79c2e3a35ad0c44b300ca50a27feb19464e8d0.zip | |
Refactor to create `NotificationBanner` helper
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt | 13 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt | 18 |
2 files changed, 22 insertions, 9 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt index 766c3137fb..c38321dfc9 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt @@ -10,7 +10,7 @@ import android.view.ViewGroup class ConnectFragment : Fragment() { private lateinit var actionButton: ConnectActionButton private lateinit var headerBar: HeaderBar - private lateinit var notificationBanner: View + private lateinit var notificationBanner: NotificationBanner private lateinit var status: ConnectionStatus private lateinit var connectHandler: Handler @@ -19,7 +19,9 @@ class ConnectFragment : Fragment() { set(value) { actionButton.state = value headerBar.state = value + notificationBanner.state = value status.state = value + field = value } @@ -36,9 +38,8 @@ class ConnectFragment : Fragment() { ): View { val view = inflater.inflate(R.layout.connect, container, false) - notificationBanner = view.findViewById(R.id.notification_banner) - headerBar = HeaderBar(view, context!!) + notificationBanner = NotificationBanner(view) status = ConnectionStatus(view, context!!) actionButton = ConnectActionButton(view) @@ -54,22 +55,16 @@ class ConnectFragment : Fragment() { private fun connect() { state = ConnectionState.Connecting - notificationBanner.visibility = View.VISIBLE - connectHandler.postDelayed(Runnable { connected() }, 1000) } private fun disconnect() { state = ConnectionState.Disconnected - notificationBanner.visibility = View.GONE - connectHandler.removeCallbacksAndMessages(null) } private fun connected() { state = ConnectionState.Connected - - notificationBanner.visibility = View.GONE } } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt new file mode 100644 index 0000000000..445df2d914 --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt @@ -0,0 +1,18 @@ +package net.mullvad.mullvadvpn + +import android.view.View + +class NotificationBanner(val parentView: View) { + private val banner: View = parentView.findViewById(R.id.notification_banner) + + var state = ConnectionState.Disconnected + set(value) { + when (value) { + ConnectionState.Disconnected -> banner.visibility = View.GONE + ConnectionState.Connecting -> banner.visibility = View.VISIBLE + ConnectionState.Connected -> banner.visibility = View.GONE + } + + field = value + } +} |
