Skip to content

Commit d68f342

Browse files
committed
More fixes
1 parent a1e5666 commit d68f342

22 files changed

+59
-83
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/BaseCell.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ private fun PreviewBaseCell() {
3434
AppTheme {
3535
SpacedColumn {
3636
BaseCell(
37-
title = {
37+
headlineContent = {
3838
BaseCellTitle(
3939
title = "Header title",
4040
style = MaterialTheme.typography.titleMedium
4141
)
4242
}
4343
)
4444
BaseCell(
45-
title = {
45+
headlineContent = {
4646
BaseCellTitle(
4747
title = "Normal title",
4848
style = MaterialTheme.typography.labelLarge
@@ -57,7 +57,7 @@ private fun PreviewBaseCell() {
5757
internal fun BaseCell(
5858
modifier: Modifier = Modifier,
5959
iconView: @Composable RowScope.() -> Unit = {},
60-
title: @Composable RowScope.() -> Unit,
60+
headlineContent: @Composable RowScope.() -> Unit,
6161
bodyView: @Composable ColumnScope.() -> Unit = {},
6262
isRowEnabled: Boolean = true,
6363
onCellClicked: () -> Unit = {},
@@ -82,7 +82,7 @@ internal fun BaseCell(
8282
) {
8383
iconView()
8484

85-
title()
85+
headlineContent()
8686

8787
Column(modifier = Modifier.wrapContentWidth().wrapContentHeight()) { bodyView() }
8888
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/CustomListCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun CustomListCell(
1717
background: Color = MaterialTheme.colorScheme.primary,
1818
) {
1919
BaseCell(
20-
title = {
20+
headlineContent = {
2121
BaseCellTitle(
2222
title = customList.name,
2323
style = textStyle,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/DnsCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fun DnsCell(
3434
val startPadding = 54.dp
3535

3636
BaseCell(
37-
title = { DnsTitle(address = address, modifier = titleModifier) },
37+
headlineContent = { DnsTitle(address = address, modifier = titleModifier) },
3838
bodyView = {
3939
if (isUnreachableLocalDnsWarningVisible) {
4040
Icon(

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/DropdownMenuCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fun DropdownMenuCell(
4848
) {
4949
var showMenu by remember { mutableStateOf(false) }
5050
BaseCell(
51-
title = {
51+
headlineContent = {
5252
BaseCellTitle(
5353
title = text,
5454
style = textStyle,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/ExpandableComposeCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fun ExpandableComposeCell(
5353
val bodyViewModifier = Modifier
5454

5555
BaseCell(
56-
title = {
56+
headlineContent = {
5757
BaseCellTitle(
5858
title = title,
5959
style = MaterialTheme.typography.titleMedium,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/HeaderCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fun HeaderCell(
1515
background: Color = MaterialTheme.colorScheme.primary,
1616
) {
1717
BaseCell(
18-
title = {
18+
headlineContent = {
1919
BaseCellTitle(
2020
title = text,
2121
style = textStyle,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/InformationComposeCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fun InformationComposeCell(
4545
val bodyViewModifier = Modifier
4646

4747
BaseCell(
48-
title = {
48+
headlineContent = {
4949
BaseCellTitle(
5050
title = title,
5151
style = MaterialTheme.typography.titleMedium,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/MtuComposeCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fun MtuComposeCell(
2828
val titleModifier = Modifier
2929

3030
BaseCell(
31-
title = { MtuTitle(modifier = titleModifier.weight(1f, true)) },
31+
headlineContent = { MtuTitle(modifier = titleModifier.weight(1f, true)) },
3232
bodyView = { MtuBodyView(mtuValue = mtuValue, modifier = titleModifier) },
3333
onCellClicked = { onEditMtu.invoke() }
3434
)

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/NavigationComposeCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fun NavigationComposeCell(
7070
) {
7171
BaseCell(
7272
onCellClicked = onClick,
73-
title = {
73+
headlineContent = {
7474
NavigationTitleView(
7575
title = title,
7676
modifier = modifier.weight(1f, true),

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,11 @@ private fun RelayLocationCell(
347347
rememberSaveable(key = relay.expanded.toString()) { mutableStateOf(relay.expanded) }
348348
Column(
349349
modifier =
350-
modifier.then(
351-
Modifier.fillMaxWidth()
352-
.padding(top = Dimens.listItemDivider)
353-
.wrapContentHeight()
354-
.fillMaxWidth()
355-
)
350+
modifier
351+
.fillMaxWidth()
352+
.padding(top = Dimens.listItemDivider)
353+
.wrapContentHeight()
354+
.fillMaxWidth()
356355
) {
357356
Row(
358357
modifier =

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SelectableCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fun SelectableCell(
5656
) {
5757
BaseCell(
5858
onCellClicked = onCellClicked,
59-
title = { BaseCellTitle(title = title, style = titleStyle) },
59+
headlineContent = { BaseCellTitle(title = title, style = titleStyle) },
6060
background =
6161
if (isSelected) {
6262
selectedColor

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SplitTunnelingCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fun SplitTunnelingCell(
8989
Modifier.align(Alignment.CenterVertically).size(size = Dimens.listIconSize)
9090
)
9191
},
92-
title = {
92+
headlineContent = {
9393
Text(
9494
text = title,
9595
style = MaterialTheme.typography.listItemText,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SwitchComposeCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private fun SwitchComposeCell(
119119
) {
120120
BaseCell(
121121
modifier = modifier,
122-
title = titleView,
122+
headlineContent = titleView,
123123
isRowEnabled = isEnabled,
124124
bodyView = {
125125
SwitchCellView(

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/TwoRowCell.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fun TwoRowCell(
2727
background: Color = MaterialTheme.colorScheme.primary
2828
) {
2929
BaseCell(
30-
title = {
30+
headlineContent = {
3131
Column(modifier = Modifier.weight(1f)) {
3232
Text(
3333
modifier = Modifier.fillMaxWidth(),

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private fun DeviceListItem(
349349
) {
350350
BaseCell(
351351
isRowEnabled = false,
352-
title = {
352+
headlineContent = {
353353
Column(modifier = Modifier.weight(1f)) {
354354
Text(
355355
modifier = Modifier.fillMaxWidth(),

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ fun VpnSettingsScreen(
450450
itemWithDivider {
451451
BaseCell(
452452
onCellClicked = { navigateToDns(null, null) },
453-
title = {
453+
headlineContent = {
454454
Text(
455455
text = stringResource(id = R.string.add_a_server),
456456
color = Color.White,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
2626
import net.mullvad.mullvadvpn.ui.serviceconnection.SplitTunneling
2727
import net.mullvad.mullvadvpn.usecase.AccountExpiryNotificationUseCase
2828
import net.mullvad.mullvadvpn.usecase.ConnectivityUseCase
29-
import net.mullvad.mullvadvpn.usecase.CustomListUseCase
3029
import net.mullvad.mullvadvpn.usecase.EmptyPaymentUseCase
3130
import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
3231
import net.mullvad.mullvadvpn.usecase.OutOfTimeUseCase
@@ -105,7 +104,7 @@ val uiModule = module {
105104
}
106105
single { SettingsRepository(get()) }
107106
single { MullvadProblemReport(get()) }
108-
single { CustomListsRepository(get()) }
107+
single { CustomListsRepository(get(), get()) }
109108

110109
single { AccountExpiryNotificationUseCase(get()) }
111110
single { TunnelStateNotificationUseCase(get()) }
@@ -116,7 +115,6 @@ val uiModule = module {
116115
single { OutOfTimeUseCase(get(), get()) }
117116
single { ConnectivityUseCase(get()) }
118117
single { SystemVpnSettingsUseCase(androidContext()) }
119-
single { CustomListUseCase(get(), get()) }
120118

121119
single { InAppNotificationController(get(), get(), get(), get(), MainScope()) }
122120

android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.mullvad.mullvadvpn.repository
22

33
import kotlinx.coroutines.flow.first
4+
import kotlinx.coroutines.flow.firstOrNull
45
import net.mullvad.mullvadvpn.lib.ipc.Event
56
import net.mullvad.mullvadvpn.lib.ipc.MessageHandler
67
import net.mullvad.mullvadvpn.lib.ipc.Request
@@ -9,8 +10,13 @@ import net.mullvad.mullvadvpn.model.CreateCustomListResult
910
import net.mullvad.mullvadvpn.model.CustomList
1011
import net.mullvad.mullvadvpn.model.CustomListsError
1112
import net.mullvad.mullvadvpn.model.UpdateCustomListResult
13+
import net.mullvad.mullvadvpn.relaylist.RelayItem
14+
import net.mullvad.mullvadvpn.relaylist.toGeographicLocationConstraints
1215

13-
class CustomListsRepository(private val messageHandler: MessageHandler) {
16+
class CustomListsRepository(
17+
private val messageHandler: MessageHandler,
18+
private val settingsRepository: SettingsRepository
19+
) {
1420
suspend fun createCustomList(name: String): CreateCustomListResult {
1521
val result = messageHandler.trySendRequest(Request.CreateCustomList(name))
1622

@@ -34,4 +40,23 @@ class CustomListsRepository(private val messageHandler: MessageHandler) {
3440
UpdateCustomListResult.Error(CustomListsError.OtherError)
3541
}
3642
}
43+
44+
suspend fun updateCustomListLocations(
45+
id: String,
46+
locations: List<RelayItem>
47+
): UpdateCustomListResult {
48+
return getCustomListById(id)?.let {
49+
updateCustomList(it.copy(locations = locations.toGeographicLocationConstraints()))
50+
} ?: UpdateCustomListResult.Error(CustomListsError.OtherError)
51+
}
52+
53+
suspend fun updateCustomListName(id: String, name: String): UpdateCustomListResult {
54+
return getCustomListById(id)?.let { updateCustomList(it.copy(name = name)) }
55+
?: UpdateCustomListResult.Error(CustomListsError.OtherError)
56+
}
57+
58+
private suspend fun getCustomListById(id: String): CustomList? =
59+
settingsRepository.settingsUpdates.firstOrNull()?.customLists?.customLists?.find {
60+
it.id == id
61+
}
3762
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/CustomListUseCase.kt

-46
This file was deleted.

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import kotlinx.coroutines.launch
1414
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
1515
import net.mullvad.mullvadvpn.relaylist.RelayItem
1616
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
17-
import net.mullvad.mullvadvpn.usecase.CustomListUseCase
17+
import net.mullvad.mullvadvpn.repository.CustomListsRepository
1818
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
1919

2020
class CustomListLocationsViewModel(
2121
private val customListId: String,
2222
private val newList: Boolean,
2323
relayListUseCase: RelayListUseCase,
24-
private val customListUseCase: CustomListUseCase
24+
private val customListsRepository: CustomListsRepository
2525
) : ViewModel() {
2626
private var customListName: String = ""
2727

@@ -78,7 +78,7 @@ class CustomListLocationsViewModel(
7878
fun save() {
7979
viewModelScope.launch {
8080
_selectedLocations.value?.let { selectedLocations ->
81-
customListUseCase.updateCustomListLocations(
81+
customListsRepository.updateCustomListLocations(
8282
id = customListId,
8383
locations = selectedLocations.calculateLocationsToSave()
8484
)

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import kotlinx.coroutines.launch
1313
import net.mullvad.mullvadvpn.compose.state.UpdateCustomListUiState
1414
import net.mullvad.mullvadvpn.model.CustomListsError
1515
import net.mullvad.mullvadvpn.model.UpdateCustomListResult
16-
import net.mullvad.mullvadvpn.usecase.CustomListUseCase
16+
import net.mullvad.mullvadvpn.repository.CustomListsRepository
1717

1818
class EditCustomListNameDialogViewModel(
1919
private val id: String,
20-
private val customListUseCase: CustomListUseCase
20+
private val customListsRepository: CustomListsRepository
2121
) : ViewModel() {
2222

2323
private val _uiSideEffect =
@@ -33,7 +33,7 @@ class EditCustomListNameDialogViewModel(
3333

3434
fun updateCustomListName(name: String) {
3535
viewModelScope.launch {
36-
when (val result = customListUseCase.updateCustomListName(id, name)) {
36+
when (val result = customListsRepository.updateCustomListName(id, name)) {
3737
UpdateCustomListResult.Ok -> {
3838
_uiSideEffect.send(EditCustomListNameDialogSideEffect.CloseScreen)
3939
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListViewModel.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import kotlinx.coroutines.flow.receiveAsFlow
1010
import kotlinx.coroutines.flow.stateIn
1111
import kotlinx.coroutines.launch
1212
import net.mullvad.mullvadvpn.compose.state.EditCustomListState
13-
import net.mullvad.mullvadvpn.usecase.CustomListUseCase
13+
import net.mullvad.mullvadvpn.repository.CustomListsRepository
1414
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
1515

1616
class EditCustomListViewModel(
1717
private val customListId: String,
1818
relayListUseCase: RelayListUseCase,
19-
private val customListUseCase: CustomListUseCase
19+
private val customListsRepository: CustomListsRepository
2020
) : ViewModel() {
2121

2222
private val _uiSideEffect = Channel<EditCustomListSideEffect>(1, BufferOverflow.DROP_OLDEST)
@@ -40,7 +40,7 @@ class EditCustomListViewModel(
4040

4141
fun deleteList() {
4242
viewModelScope.launch {
43-
customListUseCase.deleteCustomList(customListId)
43+
customListsRepository.deleteCustomList(customListId)
4444
_uiSideEffect.send(EditCustomListSideEffect.CloseScreen)
4545
}
4646
}

0 commit comments

Comments
 (0)