diff options
Diffstat (limited to 'android/app/src')
9 files changed, 52 insertions, 27 deletions
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt index 3b259154a4..e03786aef3 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt @@ -123,7 +123,8 @@ class SelectLocationScreenTest { filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ) ) @@ -157,7 +158,8 @@ class SelectLocationScreenTest { filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ) ) @@ -188,7 +190,8 @@ class SelectLocationScreenTest { filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ), onSelectRelay = mockedOnSelectRelay, @@ -221,11 +224,11 @@ class SelectLocationScreenTest { state = Lc.Content( SelectLocationUiState( - // searchTerm = "", filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ), onSelectRelay = mockedOnSelectRelay, @@ -260,7 +263,8 @@ class SelectLocationScreenTest { filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ), onSelectRelay = mockedOnSelectRelay, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectLocationsUiStatePreviewParameterProvider.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectLocationsUiStatePreviewParameterProvider.kt index 99bb6993ef..5b4028e6ca 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectLocationsUiStatePreviewParameterProvider.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectLocationsUiStatePreviewParameterProvider.kt @@ -17,7 +17,8 @@ class SelectLocationsUiStatePreviewParameterProvider : filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ), Lc.Content( @@ -29,7 +30,8 @@ class SelectLocationsUiStatePreviewParameterProvider : ), multihopEnabled = false, relayListType = RelayListType.EXIT, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ), Lc.Content( @@ -37,7 +39,8 @@ class SelectLocationsUiStatePreviewParameterProvider : filterChips = emptyList(), multihopEnabled = true, relayListType = RelayListType.ENTRY, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ), Lc.Content( @@ -49,7 +52,8 @@ class SelectLocationsUiStatePreviewParameterProvider : ), multihopEnabled = true, relayListType = RelayListType.ENTRY, - isTopBarActionsEnabled = true, + isSearchButtonEnabled = true, + isFilterButtonEnabled = true, ) ), ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt index 797f460de2..ec8c25207b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreen.kt @@ -264,9 +264,9 @@ fun SelectLocationScreen( modifier = Modifier.testTag(SELECT_LOCATION_SCREEN_TEST_TAG), snackbarHostState = snackbarHostState, actions = { - val isTopBarActionsEnabled = state.contentOrNull()?.isTopBarActionsEnabled == true + val isSearchButtonEnabled = state.contentOrNull()?.isSearchButtonEnabled == true IconButton( - enabled = isTopBarActionsEnabled, + enabled = isSearchButtonEnabled, onClick = { state.contentOrNull()?.let { onSearchClick(it.relayListType) } }, ) { Icon( @@ -274,17 +274,18 @@ fun SelectLocationScreen( contentDescription = stringResource(id = R.string.search), tint = MaterialTheme.colorScheme.onSurface.copy( - alpha = if (isTopBarActionsEnabled) AlphaVisible else AlphaDisabled + alpha = if (isSearchButtonEnabled) AlphaVisible else AlphaDisabled ), ) } - IconButton(enabled = isTopBarActionsEnabled, onClick = onFilterClick) { + val isFilterButtonEnabled = state.contentOrNull()?.isFilterButtonEnabled == true + IconButton(enabled = isFilterButtonEnabled, onClick = onFilterClick) { Icon( imageVector = Icons.Default.FilterList, contentDescription = stringResource(id = R.string.filter), tint = MaterialTheme.colorScheme.onSurface.copy( - alpha = if (isTopBarActionsEnabled) AlphaVisible else AlphaDisabled + alpha = if (isFilterButtonEnabled) AlphaVisible else AlphaDisabled ), ) } 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 6f986f2916..d6014647ea 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 @@ -6,5 +6,6 @@ data class SelectLocationUiState( val filterChips: List<FilterChip>, val multihopEnabled: Boolean, val relayListType: RelayListType, - val isTopBarActionsEnabled: Boolean, + val isSearchButtonEnabled: Boolean, + val isFilterButtonEnabled: Boolean, ) 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 c9c1f1e78a..cd071746c7 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 @@ -232,7 +232,7 @@ val uiModule = module { viewModel { WireguardCustomPortDialogViewModel(get()) } viewModel { LoginViewModel(get(), get(), get()) } viewModel { PrivacyDisclaimerViewModel(get(), IS_PLAY_BUILD) } - viewModel { SelectLocationViewModel(get(), get(), get(), get(), get(), get()) } + viewModel { SelectLocationViewModel(get(), get(), get(), get(), get(), get(), get()) } viewModel { SettingsViewModel(get(), get(), get(), get(), IS_PLAY_BUILD) } viewModel { SplashViewModel(get(), get(), get(), get()) } viewModel { VoucherDialogViewModel(get()) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModel.kt index 846a56cdaf..fc01b69ea6 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModel.kt @@ -12,7 +12,6 @@ import net.mullvad.mullvadvpn.compose.state.SelectLocationListUiState import net.mullvad.mullvadvpn.lib.model.CustomListId import net.mullvad.mullvadvpn.lib.model.GeoLocationId import net.mullvad.mullvadvpn.lib.model.RelayItemId -import net.mullvad.mullvadvpn.lib.model.Settings import net.mullvad.mullvadvpn.repository.RelayListRepository import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository @@ -114,11 +113,4 @@ class SelectLocationListViewModel( wireguardConstraintsRepository.wireguardConstraints.value?.entryLocation RelayListType.EXIT -> relayListRepository.selectedLocation.value }?.getOrNull() - - // If Daita is enabled without direct only, it is not possible to manually select the entry - // location. - private fun Settings.entryBlocked() = - tunnelOptions.wireguard.daitaSettings.enabled && - !tunnelOptions.wireguard.daitaSettings.directOnly && - relaySettings.relayConstraints.wireguardConstraints.isMultihopEnabled } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModel.kt index f1a9240187..c9cca74602 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModel.kt @@ -21,6 +21,7 @@ import net.mullvad.mullvadvpn.lib.model.RelayItem import net.mullvad.mullvadvpn.repository.CustomListsRepository import net.mullvad.mullvadvpn.repository.RelayListFilterRepository import net.mullvad.mullvadvpn.repository.RelayListRepository +import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository import net.mullvad.mullvadvpn.usecase.FilterChipUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase @@ -35,6 +36,7 @@ class SelectLocationViewModel( private val relayListRepository: RelayListRepository, private val wireguardConstraintsRepository: WireguardConstraintsRepository, private val filterChipUseCase: FilterChipUseCase, + private val settingsRepository: SettingsRepository, ) : ViewModel() { private val _relayListType: MutableStateFlow<RelayListType> = MutableStateFlow(RelayListType.EXIT) @@ -45,13 +47,18 @@ class SelectLocationViewModel( wireguardConstraintsRepository.wireguardConstraints, _relayListType, relayListRepository.relayList, - ) { filterChips, wireguardConstraints, relayListSelection, relayList -> + settingsRepository.settingsUpdates, + ) { filterChips, wireguardConstraints, relayListSelection, relayList, settings -> Lc.Content( SelectLocationUiState( filterChips = filterChips, multihopEnabled = wireguardConstraints?.isMultihopEnabled == true, relayListType = relayListSelection, - isTopBarActionsEnabled = relayList.isNotEmpty(), + isSearchButtonEnabled = + relayList.isNotEmpty() && + (relayListSelection == RelayListType.EXIT || + settings?.entryBlocked() != true), + isFilterButtonEnabled = relayList.isNotEmpty(), ) ) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SettingsUtil.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SettingsUtil.kt new file mode 100644 index 0000000000..05245f2503 --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SettingsUtil.kt @@ -0,0 +1,10 @@ +package net.mullvad.mullvadvpn.viewmodel.location + +import net.mullvad.mullvadvpn.lib.model.Settings + +// If Daita is enabled without direct only, it is not possible to manually select the entry +// location. +internal fun Settings.entryBlocked() = + tunnelOptions.wireguard.daitaSettings.enabled && + !tunnelOptions.wireguard.daitaSettings.directOnly && + relaySettings.relayConstraints.wireguardConstraints.isMultihopEnabled diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt index a7ecbe17f9..304b664dc6 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt @@ -29,11 +29,13 @@ import net.mullvad.mullvadvpn.lib.model.Ownership import net.mullvad.mullvadvpn.lib.model.Providers import net.mullvad.mullvadvpn.lib.model.RelayItem import net.mullvad.mullvadvpn.lib.model.RelayItemId +import net.mullvad.mullvadvpn.lib.model.Settings import net.mullvad.mullvadvpn.lib.model.WireguardConstraints import net.mullvad.mullvadvpn.relaylist.descendants import net.mullvad.mullvadvpn.repository.CustomListsRepository import net.mullvad.mullvadvpn.repository.RelayListFilterRepository import net.mullvad.mullvadvpn.repository.RelayListRepository +import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository import net.mullvad.mullvadvpn.usecase.FilterChip import net.mullvad.mullvadvpn.usecase.FilterChipUseCase @@ -53,6 +55,7 @@ class SelectLocationViewModelTest { private val mockCustomListsRepository: CustomListsRepository = mockk() private val mockWireguardConstraintsRepository: WireguardConstraintsRepository = mockk() private val mockFilterChipUseCase: FilterChipUseCase = mockk() + private val mockSettingsRepository: SettingsRepository = mockk() private lateinit var viewModel: SelectLocationViewModel @@ -60,6 +63,7 @@ class SelectLocationViewModelTest { private val wireguardConstraints = MutableStateFlow<WireguardConstraints>(mockk(relaxed = true)) private val filterChips = MutableStateFlow<List<FilterChip>>(emptyList()) private val relayList = MutableStateFlow<List<RelayItem.Location.Country>>(emptyList()) + private val settings = MutableStateFlow<Settings>(mockk(relaxed = true)) @BeforeEach fun setup() { @@ -69,6 +73,7 @@ class SelectLocationViewModelTest { wireguardConstraints every { mockFilterChipUseCase(any()) } returns filterChips every { mockRelayListRepository.relayList } returns relayList + every { mockSettingsRepository.settingsUpdates } returns settings mockkStatic(RELAY_LIST_EXTENSIONS) mockkStatic(RELAY_ITEM_EXTENSIONS) @@ -81,6 +86,7 @@ class SelectLocationViewModelTest { customListsRepository = mockCustomListsRepository, filterChipUseCase = mockFilterChipUseCase, wireguardConstraintsRepository = mockWireguardConstraintsRepository, + settingsRepository = mockSettingsRepository, ) } |
