summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-02-07 23:32:14 +0100
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-02-08 10:50:58 +0100
commit8baf83c9ca8ffab6f7b103c001042dae1d701c9e (patch)
treea16cdb1503d15d901841aa9e4c58553c98eebca5
parenta63afba8c2f3912185fbc5ed17c351e0a3701dd3 (diff)
downloadmullvadvpn-8baf83c9ca8ffab6f7b103c001042dae1d701c9e.tar.xz
mullvadvpn-8baf83c9ca8ffab6f7b103c001042dae1d701c9e.zip
Support new relay list item in SelectLocationScreen
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt43
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt30
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt10
5 files changed, 49 insertions, 39 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt
index acd963fa61..d6adf33b83 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt
@@ -38,11 +38,7 @@ import net.mullvad.mullvadvpn.lib.theme.color.AlphaInvisible
import net.mullvad.mullvadvpn.lib.theme.color.AlphaVisible
import net.mullvad.mullvadvpn.lib.theme.color.selected
import net.mullvad.mullvadvpn.model.GeographicLocationConstraint
-import net.mullvad.mullvadvpn.relaylist.Relay
-import net.mullvad.mullvadvpn.relaylist.RelayCity
-import net.mullvad.mullvadvpn.relaylist.RelayCountry
import net.mullvad.mullvadvpn.relaylist.RelayItem
-import net.mullvad.mullvadvpn.relaylist.RelayItemType
@Composable
@Preview
@@ -50,20 +46,20 @@ private fun PreviewRelayLocationCell() {
AppTheme {
Column(Modifier.background(color = MaterialTheme.colorScheme.background)) {
val countryActive =
- RelayCountry(
+ RelayItem.Country(
name = "Relay country Active",
code = "RC1",
expanded = false,
cities =
listOf(
- RelayCity(
+ RelayItem.City(
name = "Relay city 1",
code = "RI1",
expanded = false,
location = GeographicLocationConstraint.City("RC1", "RI1"),
relays =
listOf(
- Relay(
+ RelayItem.Relay(
name = "Relay 1",
active = true,
locationName = "",
@@ -76,14 +72,14 @@ private fun PreviewRelayLocationCell() {
)
)
),
- RelayCity(
+ RelayItem.City(
name = "Relay city 2",
code = "RI2",
expanded = true,
location = GeographicLocationConstraint.City("RC1", "RI2"),
relays =
listOf(
- Relay(
+ RelayItem.Relay(
name = "Relay 2",
active = true,
locationName = "",
@@ -94,7 +90,7 @@ private fun PreviewRelayLocationCell() {
"NER"
)
),
- Relay(
+ RelayItem.Relay(
name = "Relay 3",
active = true,
locationName = "",
@@ -110,20 +106,20 @@ private fun PreviewRelayLocationCell() {
)
)
val countryNotActive =
- RelayCountry(
+ RelayItem.Country(
name = "Not Enabled Relay country",
code = "RC3",
expanded = true,
cities =
listOf(
- RelayCity(
+ RelayItem.City(
name = "Not Enabled city",
code = "RI3",
expanded = true,
location = GeographicLocationConstraint.City("RC3", "RI3"),
relays =
listOf(
- Relay(
+ RelayItem.Relay(
name = "Not Enabled Relay",
active = false,
locationName = "",
@@ -158,10 +154,11 @@ fun RelayLocationCell(
onSelectRelay: (item: RelayItem) -> Unit = {}
) {
val startPadding =
- when (relay.type) {
- RelayItemType.Country -> Dimens.countryRowPadding
- RelayItemType.City -> Dimens.cityRowPadding
- RelayItemType.Relay -> Dimens.relayRowPadding
+ when (relay) {
+ is RelayItem.Country,
+ is RelayItem.CustomList -> Dimens.countryRowPadding
+ is RelayItem.City -> Dimens.cityRowPadding
+ is RelayItem.Relay -> Dimens.relayRowPadding
}
val selected = selectedItem?.code == relay.code
val expanded =
@@ -169,12 +166,12 @@ fun RelayLocationCell(
val backgroundColor =
when {
selected -> MaterialTheme.colorScheme.inversePrimary
- relay.type == RelayItemType.Country -> MaterialTheme.colorScheme.primary
- relay.type == RelayItemType.City ->
+ relay is RelayItem.Country -> MaterialTheme.colorScheme.primary
+ relay is RelayItem.City ->
MaterialTheme.colorScheme.primary
.copy(alpha = Alpha40)
.compositeOver(MaterialTheme.colorScheme.background)
- relay.type == RelayItemType.Relay -> MaterialTheme.colorScheme.secondaryContainer
+ relay is RelayItem.Relay -> MaterialTheme.colorScheme.secondaryContainer
else -> MaterialTheme.colorScheme.primary
}
Column(
@@ -273,7 +270,7 @@ fun RelayLocationCell(
}
if (expanded.value) {
when (relay) {
- is RelayCountry -> {
+ is RelayItem.Country -> {
relay.cities.forEach { relayCity ->
RelayLocationCell(
relay = relayCity,
@@ -283,7 +280,7 @@ fun RelayLocationCell(
)
}
}
- is RelayCity -> {
+ is RelayItem.City -> {
relay.relays.forEach { relay ->
RelayLocationCell(
relay = relay,
@@ -293,6 +290,8 @@ fun RelayLocationCell(
)
}
}
+ is RelayItem.Relay,
+ is RelayItem.CustomList -> {}
}
}
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt
index cf5d4f02c7..e024ae3132 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt
@@ -53,7 +53,6 @@ import net.mullvad.mullvadvpn.compose.transitions.SelectLocationTransition
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.lib.theme.color.AlphaScrollbar
-import net.mullvad.mullvadvpn.relaylist.RelayCountry
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.viewmodel.SelectLocationSideEffect
import net.mullvad.mullvadvpn.viewmodel.SelectLocationViewModel
@@ -69,8 +68,9 @@ private fun PreviewSelectLocationScreen() {
selectedProvidersCount = 0,
relayListState =
RelayListState.RelayList(
- countries = listOf(RelayCountry("Country 1", "Code 1", false, emptyList())),
- selectedRelay = null,
+ countries =
+ listOf(RelayItem.Country("Country 1", "Code 1", false, emptyList())),
+ selectedItem = null,
)
)
AppTheme {
@@ -172,14 +172,10 @@ fun SelectLocationScreen(
if (
uiState is SelectLocationUiState.Data &&
uiState.relayListState is RelayListState.RelayList &&
- uiState.relayListState.selectedRelay != null
+ uiState.relayListState.selectedItem != null
) {
- LaunchedEffect(uiState.relayListState.selectedRelay) {
- val index =
- uiState.relayListState.countries.indexOfFirst { relayCountry ->
- relayCountry.location.location.country ==
- uiState.relayListState.selectedRelay.location.location.country
- }
+ LaunchedEffect(uiState.relayListState.selectedItem) {
+ val index = uiState.relayListState.indexOfSelectedRelayItem()
if (index >= 0) {
lazyListState.scrollToItem(index)
@@ -235,7 +231,7 @@ private fun LazyListScope.relayList(
val country = relayListState.countries[index]
RelayLocationCell(
relay = country,
- selectedItem = relayListState.selectedRelay,
+ selectedItem = relayListState.selectedItem,
onSelectRelay = onSelectRelay,
modifier = Modifier.animateContentSize()
)
@@ -279,6 +275,18 @@ private fun LazyListScope.relayList(
}
}
+private fun RelayListState.RelayList.indexOfSelectedRelayItem(): Int =
+ countries.indexOfFirst { relayCountry ->
+ relayCountry.location.location.country ==
+ when (selectedItem) {
+ is RelayItem.Country -> selectedItem.code
+ is RelayItem.City -> selectedItem.location.countryCode
+ is RelayItem.Relay -> selectedItem.location.countryCode
+ is RelayItem.CustomList,
+ null -> null
+ }
+ }
+
suspend fun LazyListState.animateScrollAndCentralizeItem(index: Int) {
val itemInfo = this.layoutInfo.visibleItemsInfo.firstOrNull { it.index == index }
if (itemInfo != null) {
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt
index 3152ed1a34..fd775fa1bb 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt
@@ -1,7 +1,6 @@
package net.mullvad.mullvadvpn.compose.state
import net.mullvad.mullvadvpn.model.Ownership
-import net.mullvad.mullvadvpn.relaylist.RelayCountry
import net.mullvad.mullvadvpn.relaylist.RelayItem
sealed interface SelectLocationUiState {
@@ -21,6 +20,6 @@ sealed interface SelectLocationUiState {
sealed interface RelayListState {
data object Empty : RelayListState
- data class RelayList(val countries: List<RelayCountry>, val selectedRelay: RelayItem?) :
+ data class RelayList(val countries: List<RelayItem.Country>, val selectedItem: RelayItem?) :
RelayListState
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt
index 5e51cc99d4..c62cf03851 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt
@@ -15,6 +15,7 @@ import net.mullvad.mullvadvpn.lib.ipc.MessageHandler
import net.mullvad.mullvadvpn.lib.payment.PaymentProvider
import net.mullvad.mullvadvpn.repository.AccountRepository
import net.mullvad.mullvadvpn.repository.ChangelogRepository
+import net.mullvad.mullvadvpn.repository.CustomListsRepository
import net.mullvad.mullvadvpn.repository.DeviceRepository
import net.mullvad.mullvadvpn.repository.InAppNotificationController
import net.mullvad.mullvadvpn.repository.PrivacyDisclaimerRepository
@@ -98,6 +99,7 @@ val uiModule = module {
}
single { SettingsRepository(get()) }
single { MullvadProblemReport(get()) }
+ single { CustomListsRepository(get()) }
single { AccountExpiryNotificationUseCase(get()) }
single { TunnelStateNotificationUseCase(get()) }
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt
index d3c5977e27..fc46441de1 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt
@@ -20,6 +20,7 @@ import net.mullvad.mullvadvpn.model.Ownership
import net.mullvad.mullvadvpn.relaylist.Provider
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
+import net.mullvad.mullvadvpn.relaylist.toLocationConstraint
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy
import net.mullvad.mullvadvpn.usecase.RelayListFilterUseCase
@@ -40,7 +41,7 @@ class SelectLocationViewModel(
relayListFilterUseCase.availableProviders(),
relayListFilterUseCase.selectedProviders()
) {
- (relayCountries, relayItem),
+ (customList, relayCountries, selectedItem),
searchTerm,
selectedOwnership,
allProviders,
@@ -54,7 +55,7 @@ class SelectLocationViewModel(
?.size
val filteredRelayCountries =
- relayCountries.filterOnSearchTerm(searchTerm, relayItem)
+ relayCountries.filterOnSearchTerm(searchTerm, selectedItem)
SelectLocationUiState.Data(
searchTerm = searchTerm,
@@ -64,7 +65,7 @@ class SelectLocationViewModel(
if (filteredRelayCountries.isNotEmpty()) {
RelayListState.RelayList(
countries = filteredRelayCountries,
- selectedRelay = relayItem
+ selectedItem = selectedItem
)
} else {
RelayListState.Empty
@@ -85,7 +86,8 @@ class SelectLocationViewModel(
}
fun selectRelay(relayItem: RelayItem) {
- relayListUseCase.updateSelectedRelayLocation(relayItem.location)
+ val locationConstraint = relayItem.toLocationConstraint()
+ relayListUseCase.updateSelectedRelayLocation(locationConstraint)
serviceConnectionManager.connectionProxy()?.connect()
viewModelScope.launch { _uiSideEffect.send(SelectLocationSideEffect.CloseScreen) }
}