Skip to content

Commit

Permalink
Merge branch 'feature-indicators-sometimes-flash-droid-1447'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Oct 21, 2024
2 parents de12dc2 + fa120ef commit 837da62
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.mullvad.mullvadvpn.compose.component.connectioninfo

import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -14,26 +15,28 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.screen.ConnectionDetails
import net.mullvad.mullvadvpn.compose.test.LOCATION_INFO_CONNECTION_OUT_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.TransportProtocol
import net.mullvad.mullvadvpn.lib.model.TunnelEndpoint
import net.mullvad.mullvadvpn.lib.model.TunnelState
import net.mullvad.mullvadvpn.lib.theme.Dimens

@Composable
fun ConnectionDetailPanel(tunnelState: TunnelState.Connected) {
fun ConnectionDetailPanel(connectionDetails: ConnectionDetails) {

ConnectionInfoHeader(
stringResource(R.string.connect_panel_connection_details),
Modifier.fillMaxWidth().padding(bottom = Dimens.smallPadding),
)

ConnectionDetails(
tunnelState.endpoint.toInAddress(),
tunnelState.location()?.ipv4?.hostAddress,
tunnelState.location()?.ipv6?.hostAddress,
modifier = Modifier.padding(bottom = Dimens.smallPadding),
)
AnimatedContent(connectionDetails, label = "ConnectionDetails") {
ConnectionDetails(
it.inAddress,
it.outIpv4Address,
it.outIpv6Address,
modifier = Modifier.padding(bottom = Dimens.smallPadding),
)
}
}

@Suppress("LongMethod")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ fun FeatureIndicators(
MullvadFeatureChip(text = features[index].text())
}

// Spacing are added to compensate for when the
// Spacing are added to compensate for when there are no feature indicators, since each feature
// indicator has built-in padding. Padding looks the same towards Switch Location button with or
// without feature indicators.
if (features.isEmpty() && !expanded) {
Spacer(Modifier.height(Dimens.smallSpacer))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.ramcosta.composedestinations.generated.destinations.SettingsDestinati
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.result.ResultRecipient
import kotlinx.coroutines.launch
import mullvad_daemon.management_interface.tunnelState
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.button.ConnectionButton
import net.mullvad.mullvadvpn.compose.button.SwitchLocationButton
Expand All @@ -70,6 +71,7 @@ import net.mullvad.mullvadvpn.compose.component.MullvadCircularProgressIndicator
import net.mullvad.mullvadvpn.compose.component.ScaffoldWithTopBarAndDeviceName
import net.mullvad.mullvadvpn.compose.component.connectioninfo.ConnectionDetailPanel
import net.mullvad.mullvadvpn.compose.component.connectioninfo.FeatureIndicatorsPanel
import net.mullvad.mullvadvpn.compose.component.connectioninfo.toInAddress
import net.mullvad.mullvadvpn.compose.component.drawVerticalScrollbar
import net.mullvad.mullvadvpn.compose.component.notificationbanner.NotificationBanner
import net.mullvad.mullvadvpn.compose.extensions.createOpenAccountPageHook
Expand All @@ -93,6 +95,7 @@ import net.mullvad.mullvadvpn.lib.map.AnimatedMap
import net.mullvad.mullvadvpn.lib.map.data.GlobeColors
import net.mullvad.mullvadvpn.lib.map.data.LocationMarkerColors
import net.mullvad.mullvadvpn.lib.map.data.Marker
import net.mullvad.mullvadvpn.lib.model.FeatureIndicator
import net.mullvad.mullvadvpn.lib.model.GeoIpLocation
import net.mullvad.mullvadvpn.lib.model.LatLong
import net.mullvad.mullvadvpn.lib.model.Latitude
Expand Down Expand Up @@ -343,15 +346,17 @@ private fun ConnectionCard(
) {
ConnectionCardHeader(state, state.location, expanded) { expanded = !expanded }

Logger.d("Tunnelstate: ${state.tunnelState}, expanded: $expanded")
AnimatedContent(
state.tunnelState as? TunnelState.Connected to expanded,
(state.tunnelState as? TunnelState.Connected)?.featureIndicators,
modifier = Modifier.weight(1f, fill = false),
label = "connection_card_connection_details",
) { (connectedState, isExpanded) ->
if (connectedState != null) {
) { featureIndicators ->
if (featureIndicators != null) {
ConnectionInfo(
connectedState,
isExpanded,
featureIndicators,
(state.tunnelState as? TunnelState.Connected)?.toConnectionsDetails(),
expanded,
onToggleExpand = { expanded = !expanded },
)
} else {
Expand Down Expand Up @@ -436,7 +441,8 @@ private fun GeoIpLocation?.asString(): String {

@Composable
private fun ConnectionInfo(
tunnelState: TunnelState.Connected,
featureIndicators: List<FeatureIndicator>,
connectionDetails: ConnectionDetails?,
expanded: Boolean,
onToggleExpand: () -> Unit,
) {
Expand All @@ -457,15 +463,29 @@ private fun ConnectionInfo(
)
.verticalScroll(scrollState)
) {
FeatureIndicatorsPanel(tunnelState.featureIndicators, expanded, onToggleExpand)
FeatureIndicatorsPanel(featureIndicators, expanded, onToggleExpand)

if (expanded) {
ConnectionDetailPanel(tunnelState)
if (expanded && connectionDetails != null) {
ConnectionDetailPanel(connectionDetails)
}
}
}
}

data class ConnectionDetails(
val inAddress: String,
val outIpv4Address: String?,
val outIpv6Address: String?,
)

@Composable
fun TunnelState.Connected.toConnectionsDetails(): ConnectionDetails =
ConnectionDetails(
endpoint.toInAddress(),
location()?.ipv4?.hostAddress,
location()?.ipv6?.hostAddress,
)

@Composable
private fun ButtonPanel(
state: ConnectUiState,
Expand Down

0 comments on commit 837da62

Please sign in to comment.