Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 156748d

Browse files
committed
Create PrivateContactInfo to contain all the info
1 parent ae9f2a4 commit 156748d

File tree

6 files changed

+68
-38
lines changed

6 files changed

+68
-38
lines changed

homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/home/share/ShareScreen.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ internal fun ShareScreen(uiState: ShareUiState, onEvent: (ShareEvent) -> Unit) {
4343
ShareHeader()
4444

4545
SharePrivateContactInfo(
46-
emailValue = uiState.emailValue,
46+
privateContactInfo = uiState.privateContactInfo,
4747
onEmailValueChange = { onEvent(ShareEvent.OnEmailValueChanged(it)) },
48-
emailSwitchChecked = uiState.isEmailShared,
4948
onEmailSwitchCheckedChange = { onEvent(ShareEvent.OnEmailSharingChanged(it)) },
50-
phoneValue = uiState.phoneValue,
5149
onPhoneValueChange = { onEvent(ShareEvent.OnPhoneValueChanged(it)) },
52-
phoneSwitchChecked = uiState.isPhoneShared,
5350
onPhoneSwitchCheckedChange = { onEvent(ShareEvent.OnPhoneSharingChanged(it)) },
5451
modifier = Modifier.padding(16.dp),
5552
)

homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/home/share/ShareUiState.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import com.gravatar.restapi.models.Profile
44

55
internal data class ShareUiState(
66
val profile: Profile? = null,
7+
val privateContactInfo: PrivateContactInfo = PrivateContactInfo()
8+
)
9+
10+
internal data class PrivateContactInfo(
711
val emailValue: String = "",
812
val isEmailShared: Boolean = false,
913
val phoneValue: String = "",

homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/home/share/ShareViewModel.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,40 @@ internal class ShareViewModel(
2424
fun onEvent(shareEvent: ShareEvent) {
2525
when (shareEvent) {
2626
is ShareEvent.OnEmailValueChanged -> {
27-
_uiState.update { it.copy(emailValue = shareEvent.value) }
27+
_uiState.update {
28+
it.copy(
29+
privateContactInfo = it.privateContactInfo.copy(
30+
emailValue = shareEvent.value
31+
)
32+
)
33+
}
2834
}
2935
is ShareEvent.OnEmailSharingChanged -> {
30-
_uiState.update { it.copy(isEmailShared = shareEvent.isShared) }
36+
_uiState.update {
37+
it.copy(
38+
privateContactInfo = it.privateContactInfo.copy(
39+
isEmailShared = shareEvent.isShared
40+
)
41+
)
42+
}
3143
}
3244
is ShareEvent.OnPhoneValueChanged -> {
33-
_uiState.update { it.copy(phoneValue = shareEvent.value) }
45+
_uiState.update {
46+
it.copy(
47+
privateContactInfo = it.privateContactInfo.copy(
48+
phoneValue = shareEvent.value
49+
)
50+
)
51+
}
3452
}
3553
is ShareEvent.OnPhoneSharingChanged -> {
36-
_uiState.update { it.copy(isPhoneShared = shareEvent.isShared) }
54+
_uiState.update {
55+
it.copy(
56+
privateContactInfo = it.privateContactInfo.copy(
57+
isPhoneShared = shareEvent.isShared
58+
)
59+
)
60+
}
3761
}
3862
}
3963
}

homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/home/share/components/SharePrivateContactInfo.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ import androidx.compose.ui.Modifier
88
import androidx.compose.ui.tooling.preview.Preview
99
import androidx.compose.ui.unit.dp
1010
import com.gravatar.app.homeUi.R
11+
import com.gravatar.app.homeUi.presentation.home.share.PrivateContactInfo
1112

1213
@Composable
1314
internal fun SharePrivateContactInfo(
14-
// Email state and callbacks
15-
emailValue: String,
15+
privateContactInfo: PrivateContactInfo,
1616
onEmailValueChange: (String) -> Unit,
17-
emailSwitchChecked: Boolean,
1817
onEmailSwitchCheckedChange: (Boolean) -> Unit,
19-
// Phone number state and callbacks
20-
phoneValue: String,
2118
onPhoneValueChange: (String) -> Unit,
22-
phoneSwitchChecked: Boolean,
2319
onPhoneSwitchCheckedChange: (Boolean) -> Unit,
2420
modifier: Modifier = Modifier
2521
) {
@@ -32,16 +28,16 @@ internal fun SharePrivateContactInfo(
3228
)
3329
ShareEditableField(
3430
placeholder = R.string.share_private_contact_email_placeholder,
35-
value = emailValue,
31+
value = privateContactInfo.emailValue,
3632
onValueChange = onEmailValueChange,
37-
switchChecked = emailSwitchChecked,
33+
switchChecked = privateContactInfo.isEmailShared,
3834
onSwitchCheckedChange = onEmailSwitchCheckedChange,
3935
)
4036
ShareEditableField(
4137
placeholder = R.string.share_private_contact_phone_number_placeholder,
42-
value = phoneValue,
38+
value = privateContactInfo.phoneValue,
4339
onValueChange = onPhoneValueChange,
44-
switchChecked = phoneSwitchChecked,
40+
switchChecked = privateContactInfo.isPhoneShared,
4541
onSwitchCheckedChange = onPhoneSwitchCheckedChange,
4642
)
4743
}
@@ -51,13 +47,15 @@ internal fun SharePrivateContactInfo(
5147
@Composable
5248
private fun SharePrivateContactInfoPreview() {
5349
SharePrivateContactInfo(
54-
emailValue = "example@email.com",
50+
privateContactInfo = PrivateContactInfo(
51+
emailValue = "example@email.com",
52+
isEmailShared = true,
53+
phoneValue = "123-456-7890",
54+
isPhoneShared = false
55+
),
5556
onEmailValueChange = {},
56-
emailSwitchChecked = true,
5757
onEmailSwitchCheckedChange = {},
58-
phoneValue = "123-456-7890",
5958
onPhoneValueChange = {},
60-
phoneSwitchChecked = false,
6159
onPhoneSwitchCheckedChange = {}
6260
)
6361
}

homeUi/src/test/kotlin/com/gravatar/app/homeUi/presentation/home/share/ShareViewModelTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ShareViewModelTest {
7070

7171
// Then
7272
viewModel.uiState.test {
73-
assertEquals(newEmailValue, awaitItem().emailValue)
73+
assertEquals(newEmailValue, awaitItem().privateContactInfo.emailValue)
7474
}
7575
}
7676

@@ -84,7 +84,7 @@ class ShareViewModelTest {
8484

8585
// Then
8686
viewModel.uiState.test {
87-
assertEquals(isShared, awaitItem().isEmailShared)
87+
assertEquals(isShared, awaitItem().privateContactInfo.isEmailShared)
8888
}
8989
}
9090

@@ -98,7 +98,7 @@ class ShareViewModelTest {
9898

9999
// Then
100100
viewModel.uiState.test {
101-
assertEquals(newPhoneValue, awaitItem().phoneValue)
101+
assertEquals(newPhoneValue, awaitItem().privateContactInfo.phoneValue)
102102
}
103103
}
104104

@@ -112,7 +112,7 @@ class ShareViewModelTest {
112112

113113
// Then
114114
viewModel.uiState.test {
115-
assertEquals(isShared, awaitItem().isPhoneShared)
115+
assertEquals(isShared, awaitItem().privateContactInfo.isPhoneShared)
116116
}
117117
}
118118

homeUi/src/test/kotlin/com/gravatar/app/homeUi/presentation/home/share/components/SharePrivateContactInfoTest.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.padding
55
import androidx.compose.ui.Modifier
66
import androidx.compose.ui.unit.dp
77
import com.gravatar.app.design.theme.GravatarAppTheme
8+
import com.gravatar.app.homeUi.presentation.home.share.PrivateContactInfo
89
import com.gravatar.app.testUtils.roborazzi.RoborazziTest
910
import org.junit.Test
1011

@@ -14,13 +15,15 @@ class SharePrivateContactInfoTest : RoborazziTest() {
1415
fun sharePrivateContactInfo_bothSwitchesOn() = screenshotTest {
1516
GravatarAppTheme {
1617
SharePrivateContactInfo(
17-
emailValue = "example@email.com",
18+
privateContactInfo = PrivateContactInfo(
19+
emailValue = "example@email.com",
20+
isEmailShared = true,
21+
phoneValue = "123-456-7890",
22+
isPhoneShared = true
23+
),
1824
onEmailValueChange = {},
19-
emailSwitchChecked = true,
2025
onEmailSwitchCheckedChange = {},
21-
phoneValue = "123-456-7890",
2226
onPhoneValueChange = {},
23-
phoneSwitchChecked = true,
2427
onPhoneSwitchCheckedChange = {},
2528
modifier = Modifier
2629
.fillMaxWidth()
@@ -33,13 +36,15 @@ class SharePrivateContactInfoTest : RoborazziTest() {
3336
fun sharePrivateContactInfo_bothSwitchesOff() = screenshotTest {
3437
GravatarAppTheme {
3538
SharePrivateContactInfo(
36-
emailValue = "example@email.com",
39+
privateContactInfo = PrivateContactInfo(
40+
emailValue = "example@email.com",
41+
isEmailShared = false,
42+
phoneValue = "123-456-7890",
43+
isPhoneShared = false
44+
),
3745
onEmailValueChange = {},
38-
emailSwitchChecked = false,
3946
onEmailSwitchCheckedChange = {},
40-
phoneValue = "123-456-7890",
4147
onPhoneValueChange = {},
42-
phoneSwitchChecked = false,
4348
onPhoneSwitchCheckedChange = {},
4449
modifier = Modifier
4550
.fillMaxWidth()
@@ -52,13 +57,15 @@ class SharePrivateContactInfoTest : RoborazziTest() {
5257
fun sharePrivateContactInfo_emptyValues() = screenshotTest {
5358
GravatarAppTheme {
5459
SharePrivateContactInfo(
55-
emailValue = "",
60+
privateContactInfo = PrivateContactInfo(
61+
emailValue = "",
62+
isEmailShared = true,
63+
phoneValue = "",
64+
isPhoneShared = true
65+
),
5666
onEmailValueChange = {},
57-
emailSwitchChecked = true,
5867
onEmailSwitchCheckedChange = {},
59-
phoneValue = "",
6068
onPhoneValueChange = {},
61-
phoneSwitchChecked = true,
6269
onPhoneSwitchCheckedChange = {},
6370
modifier = Modifier
6471
.fillMaxWidth()

0 commit comments

Comments
 (0)