diff options
Diffstat (limited to 'android')
3 files changed, 169 insertions, 119 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt index 2a9d54f59e..36cf498e40 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt @@ -16,6 +16,7 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) { private lateinit var actionButton: ConnectActionButton private lateinit var switchLocationButton: SwitchLocationButton private lateinit var headerBar: HeaderBar + private lateinit var body: View private lateinit var notificationBanner: NotificationBanner private lateinit var status: ConnectionStatus private lateinit var locationInfo: LocationInfo @@ -42,7 +43,12 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) { } headerBar = HeaderBar(view, resources) + + body = view.findViewById(R.id.body) + notificationBanner = NotificationBanner(view, parentActivity, appVersionInfoCache, daemon) + notificationBanner.onHeightChange = { newHeight -> updateBodyPaddingTop(newHeight) } + status = ConnectionStatus(view, resources) locationInfo = LocationInfo(view, context!!) @@ -121,6 +127,14 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) { state.putBoolean(KEY_IS_TUNNEL_INFO_EXPANDED, isTunnelInfoExpanded) } + private fun updateBodyPaddingTop(newPaddingTop: Int) { + body.apply { + if (paddingTop != newPaddingTop) { + setPadding(paddingLeft, newPaddingTop, paddingRight, paddingBottom) + } + } + } + private fun updateTunnelState(uiState: TunnelState, realState: TunnelState) { notificationBanner.tunnelState = realState locationInfo.state = realState 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 diff --git a/android/src/main/res/layout/connect.xml b/android/src/main/res/layout/connect.xml index f7615d5929..46b4283157 100644 --- a/android/src/main/res/layout/connect.xml +++ b/android/src/main/res/layout/connect.xml @@ -1,12 +1,11 @@ -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/main_fragment" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/main_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent"> <LinearLayout android:id="@+id/header_bar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_weight="0" + android:layout_alignParentTop="true" android:orientation="horizontal" android:gravity="center_vertical" android:background="@color/red" @@ -38,9 +37,11 @@ <FrameLayout android:id="@+id/notification_banner" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_below="@id/header_bar" android:background="@color/darkBlue" android:visibility="invisible" - android:clickable="false"> + android:clickable="false" + android:elevation="0.25dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingVertical="8dp" @@ -91,125 +92,135 @@ android:visibility="gone" /> </RelativeLayout> </FrameLayout> - <Space android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="1" /> - <ProgressBar android:id="@+id/connecting_spinner" - android:layout_width="60dp" - android:layout_height="60dp" - android:layout_gravity="center" - android:layout_marginBottom="14dp" - android:indeterminate="true" - android:indeterminateOnly="true" - android:indeterminateDuration="600" - android:indeterminateDrawable="@drawable/icon_spinner" - android:visibility="invisible" /> - <LinearLayout android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_weight="0" - android:orientation="vertical" - android:gravity="start"> - <TextView android:id="@+id/connection_status" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginBottom="4dp" - android:layout_marginHorizontal="24dp" - android:textColor="@color/red" - android:textSize="16sp" - android:textStyle="bold" - android:text="@string/unsecured_connection" - android:textAllCaps="true" /> - <TextView android:id="@+id/city" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginHorizontal="24dp" - android:textColor="@color/white" - android:textSize="34sp" - android:textStyle="bold" - android:text="" /> - <TextView android:id="@+id/country" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginHorizontal="24dp" - android:textColor="@color/white" - android:textSize="34sp" - android:textStyle="bold" - android:text="" /> - <LinearLayout android:id="@+id/tunnel_info" + <ScrollView android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/header_bar" + android:layout_alignParentBottom="true" + android:fillViewport="true"> + <LinearLayout android:id="@+id/body" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_weight="0" + android:layout_height="match_parent" android:orientation="vertical" - android:paddingHorizontal="24dp" - android:gravity="start" - android:clickable="true" - android:background="?android:attr/selectableItemBackground"> - <LinearLayout android:layout_width="wrap_content" + android:gravity="bottom"> + <ProgressBar android:id="@+id/connecting_spinner" + android:layout_width="60dp" + android:layout_height="60dp" + android:layout_gravity="center" + android:layout_marginBottom="7dp" + android:indeterminate="true" + android:indeterminateOnly="true" + android:indeterminateDuration="600" + android:indeterminateDrawable="@drawable/icon_spinner" + android:visibility="invisible" /> + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> - <TextView android:id="@+id/hostname" + android:layout_weight="0" + android:layout_marginTop="7dp" + android:orientation="vertical" + android:gravity="start"> + <TextView android:id="@+id/connection_status" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textColor="@color/white" + android:layout_marginBottom="4dp" + android:layout_marginHorizontal="24dp" + android:textColor="@color/red" android:textSize="16sp" android:textStyle="bold" + android:text="@string/unsecured_connection" + android:textAllCaps="true" /> + <TextView android:id="@+id/city" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="24dp" + android:textColor="@color/white" + android:textSize="34sp" + android:textStyle="bold" android:text="" /> - <ImageView android:id="@+id/chevron" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginHorizontal="5dp" - android:alpha="0.4" - android:src="@drawable/icon_chevron_expand" /> + <TextView android:id="@+id/country" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="24dp" + android:textColor="@color/white" + android:textSize="34sp" + android:textStyle="bold" + android:text="" /> + <LinearLayout android:id="@+id/tunnel_info" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="0" + android:orientation="vertical" + android:paddingHorizontal="24dp" + android:gravity="start" + android:clickable="true" + android:background="?android:attr/selectableItemBackground"> + <LinearLayout android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal"> + <TextView android:id="@+id/hostname" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="@color/white" + android:textSize="16sp" + android:textStyle="bold" + android:text="" /> + <ImageView android:id="@+id/chevron" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="5dp" + android:alpha="0.4" + android:src="@drawable/icon_chevron_expand" /> + </LinearLayout> + <TextView android:id="@+id/tunnel_protocol" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="4dp" + android:textColor="@color/white" + android:textSize="13sp" + android:text="" /> + <TextView android:id="@+id/in_address" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="@color/white" + android:textSize="13sp" + android:text="" /> + <TextView android:id="@+id/out_address" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="@color/white" + android:textSize="13sp" + android:text="" /> + </LinearLayout> + </LinearLayout> + <LinearLayout android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="0" + android:orientation="vertical" + android:padding="24dp"> + <Button android:id="@+id/switch_location" + android:layout_marginTop="20dp" + android:layout_marginBottom="16dp" + android:paddingHorizontal="8dp" + android:text="@string/switch_location" + android:drawableRight="@drawable/icon_chevron" + style="@style/White20Button" /> + <LinearLayout android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + <Button android:id="@+id/action_button" + android:layout_weight="1" + android:text="@string/connect" + style="@style/GreenButton" /> + <ImageButton android:id="@+id/reconnect_button" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_weight="0" + android:layout_marginLeft="1dp" + android:paddingHorizontal="10dp" + android:background="@drawable/transparent_red_right_half_button_background" + android:visibility="gone" + android:src="@drawable/icon_reload" /> + </LinearLayout> </LinearLayout> - <TextView android:id="@+id/tunnel_protocol" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="4dp" - android:textColor="@color/white" - android:textSize="13sp" - android:text="" /> - <TextView android:id="@+id/in_address" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:textColor="@color/white" - android:textSize="13sp" - android:text="" /> - <TextView android:id="@+id/out_address" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:textColor="@color/white" - android:textSize="13sp" - android:text="" /> - </LinearLayout> - </LinearLayout> - <LinearLayout android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_weight="0" - android:orientation="vertical" - android:padding="24dp"> - <Button android:id="@+id/switch_location" - android:layout_marginTop="20dp" - android:layout_marginBottom="16dp" - android:paddingHorizontal="8dp" - android:text="@string/switch_location" - android:drawableRight="@drawable/icon_chevron" - style="@style/White20Button" /> - <LinearLayout android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal"> - <Button android:id="@+id/action_button" - android:layout_weight="1" - android:text="@string/connect" - style="@style/GreenButton" /> - <ImageButton android:id="@+id/reconnect_button" - android:layout_width="wrap_content" - android:layout_height="match_parent" - android:layout_weight="0" - android:layout_marginLeft="1dp" - android:paddingHorizontal="10dp" - android:background="@drawable/transparent_red_right_half_button_background" - android:visibility="gone" - android:src="@drawable/icon_reload" /> </LinearLayout> - </LinearLayout> -</LinearLayout> + </ScrollView> +</RelativeLayout> |
