diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-28 19:11:31 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-29 12:14:14 +0000 |
| commit | 6403534b1a16aacf0883a5e8c46812144c507b79 (patch) | |
| tree | 9529992589303696d2172dd08cb1d824435d72d8 /android/src | |
| parent | cdbef6f3d5d6087fd481d38d137b38f9e2ce586c (diff) | |
| download | mullvadvpn-6403534b1a16aacf0883a5e8c46812144c507b79.tar.xz mullvadvpn-6403534b1a16aacf0883a5e8c46812144c507b79.zip | |
Create `HeaderBar` widget
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/HeaderBar.kt | 70 | ||||
| -rw-r--r-- | android/src/main/res/layout/header_bar.xml | 25 |
2 files changed, 95 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/HeaderBar.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/HeaderBar.kt new file mode 100644 index 0000000000..dbe09ff34b --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/HeaderBar.kt @@ -0,0 +1,70 @@ +package net.mullvad.mullvadvpn.ui.widget + +import android.content.Context +import android.util.AttributeSet +import android.view.Gravity +import android.view.LayoutInflater +import android.view.View +import android.widget.LinearLayout +import kotlin.properties.Delegates.observable +import net.mullvad.mullvadvpn.R +import net.mullvad.mullvadvpn.model.TunnelState +import net.mullvad.mullvadvpn.ui.MainActivity + +class HeaderBar : LinearLayout { + private val container = + context.getSystemService(Context.LAYOUT_INFLATER_SERVICE).let { service -> + val inflater = service as LayoutInflater + + inflater.inflate(R.layout.header_bar, this) + } + + private val disabledColor = context.getColor(android.R.color.transparent) + private val securedColor = context.getColor(R.color.green) + private val unsecuredColor = context.getColor(R.color.red) + + var tunnelState by observable<TunnelState?>(null) { _, _, state -> + val backgroundColor = when (state) { + null -> disabledColor + is TunnelState.Disconnected -> unsecuredColor + is TunnelState.Connecting -> securedColor + is TunnelState.Connected -> securedColor + is TunnelState.Disconnecting -> securedColor + is TunnelState.Error -> { + if (state.errorState.isBlocking) { + securedColor + } else { + unsecuredColor + } + } + } + + container.setBackgroundColor(backgroundColor) + } + + constructor(context: Context) : super(context) {} + + constructor(context: Context, attributes: AttributeSet) : super(context, attributes) {} + + constructor( + context: Context, + attributes: AttributeSet, + defaultStyleAttribute: Int + ) : super(context, attributes, defaultStyleAttribute) {} + + constructor( + context: Context, + attributes: AttributeSet, + defaultStyleAttribute: Int, + defaultStyleResource: Int + ) : super(context, attributes, defaultStyleAttribute, defaultStyleResource) {} + + init { + gravity = Gravity.CENTER_VERTICAL + orientation = HORIZONTAL + + findViewById<View>(R.id.settings).setOnClickListener { + (context as? MainActivity)?.openSettings() + } + } +} diff --git a/android/src/main/res/layout/header_bar.xml b/android/src/main/res/layout/header_bar.xml new file mode 100644 index 0000000000..9963893abf --- /dev/null +++ b/android/src/main/res/layout/header_bar.xml @@ -0,0 +1,25 @@ +<merge xmlns:android="http://schemas.android.com/apk/res/android"> + <ImageView android:layout_width="50dp" + android:layout_height="50dp" + android:layout_marginLeft="12dp" + android:layout_marginVertical="12dp" + android:layout_weight="0" + android:src="@drawable/logo_icon" /> + <TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" + android:layout_marginVertical="12dp" + android:layout_weight="1" + android:textColor="@color/white80" + android:textSize="24sp" + android:textStyle="bold" + android:text="@string/app_name" + android:textAllCaps="true" /> + <ImageButton android:id="@+id/settings" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_weight="0" + android:paddingHorizontal="12dp" + android:background="?android:attr/selectableItemBackground" + android:src="@drawable/icon_settings" /> +</merge> |
