summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-03-14 16:49:34 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-03-15 19:18:53 +0000
commitb291b4950fd906fd6f08d3af902d847918fd4d30 (patch)
treed7524278260954a272ddec4189f90a19101e5e14 /android/src
parent6e5eaddb65f88cd7d3d6c082893f96295f95bb82 (diff)
downloadmullvadvpn-b291b4950fd906fd6f08d3af902d847918fd4d30.tar.xz
mullvadvpn-b291b4950fd906fd6f08d3af902d847918fd4d30.zip
Refactor to create `HeaderBar` helper type
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt23
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/HeaderBar.kt30
2 files changed, 42 insertions, 11 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
index 96a4763408..2a45e986b0 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
@@ -11,12 +11,19 @@ import android.widget.TextView
class ConnectFragment : Fragment() {
private lateinit var actionButton: ConnectActionButton
private lateinit var connectingSpinner: View
- private lateinit var headerBar: View
+ private lateinit var headerBar: HeaderBar
private lateinit var notificationBanner: View
private lateinit var status: TextView
private lateinit var connectHandler: Handler
+ private var state = ConnectionState.Disconnected
+ set(value) {
+ actionButton.state = value
+ headerBar.state = value
+ field = value
+ }
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -30,8 +37,8 @@ class ConnectFragment : Fragment() {
): View {
val view = inflater.inflate(R.layout.connect, container, false)
+ headerBar = HeaderBar(view, context!!)
connectingSpinner = view.findViewById(R.id.connecting_spinner)
- headerBar = view.findViewById(R.id.header_bar)
notificationBanner = view.findViewById(R.id.notification_banner)
status = view.findViewById(R.id.connection_status)
@@ -44,13 +51,11 @@ class ConnectFragment : Fragment() {
}
private fun connect() {
- actionButton.state = ConnectionState.Connecting
+ state = ConnectionState.Connecting
connectingSpinner.visibility = View.VISIBLE
notificationBanner.visibility = View.VISIBLE
- headerBar.setBackgroundColor(context!!.getColor(R.color.green))
-
status.setTextColor(context!!.getColor(R.color.white))
status.setText(R.string.creating_secure_connection)
@@ -58,13 +63,11 @@ class ConnectFragment : Fragment() {
}
private fun disconnect() {
- actionButton.state = ConnectionState.Disconnected
+ state = ConnectionState.Disconnected
connectingSpinner.visibility = View.INVISIBLE
notificationBanner.visibility = View.GONE
- headerBar.setBackgroundColor(context!!.getColor(R.color.red))
-
status.setTextColor(context!!.getColor(R.color.red))
status.setText(R.string.unsecured_connection)
@@ -72,13 +75,11 @@ class ConnectFragment : Fragment() {
}
private fun connected() {
- actionButton.state = ConnectionState.Connected
+ state = ConnectionState.Connected
connectingSpinner.visibility = View.INVISIBLE
notificationBanner.visibility = View.GONE
- headerBar.setBackgroundColor(context!!.getColor(R.color.green))
-
status.setTextColor(context!!.getColor(R.color.green))
status.setText(R.string.secure_connection)
}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/HeaderBar.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/HeaderBar.kt
new file mode 100644
index 0000000000..4c46174f51
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/HeaderBar.kt
@@ -0,0 +1,30 @@
+package net.mullvad.mullvadvpn
+
+import android.content.Context
+import android.view.View
+
+class HeaderBar(val parentView: View, val context: Context) {
+ private val headerBar: View = parentView.findViewById(R.id.header_bar)
+
+ private val securedColor = context.getColor(R.color.green)
+ private val unsecuredColor = context.getColor(R.color.red)
+
+ var state = ConnectionState.Disconnected
+ set(value) {
+ when (value) {
+ ConnectionState.Disconnected -> unsecured()
+ ConnectionState.Connecting -> secured()
+ ConnectionState.Connected -> secured()
+ }
+
+ field = value
+ }
+
+ private fun unsecured() {
+ headerBar.setBackgroundColor(unsecuredColor)
+ }
+
+ private fun secured() {
+ headerBar.setBackgroundColor(securedColor)
+ }
+}