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

Commit 4b78b23

Browse files
committed
Create PrivateContactInfo to contain all the info
1 parent aa73bd7 commit 4b78b23

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
@@ -50,13 +50,10 @@ internal fun ShareScreen(uiState: ShareUiState, onEvent: (ShareEvent) -> Unit) {
5050
)
5151

5252
SharePrivateContactInfo(
53-
emailValue = uiState.emailValue,
53+
privateContactInfo = uiState.privateContactInfo,
5454
onEmailValueChange = { onEvent(ShareEvent.OnEmailValueChanged(it)) },
55-
emailSwitchChecked = uiState.isEmailShared,
5655
onEmailSwitchCheckedChange = { onEvent(ShareEvent.OnEmailSharingChanged(it)) },
57-
phoneValue = uiState.phoneValue,
5856
onPhoneValueChange = { onEvent(ShareEvent.OnPhoneValueChanged(it)) },
59-
phoneSwitchChecked = uiState.isPhoneShared,
6057
onPhoneSwitchCheckedChange = { onEvent(ShareEvent.OnPhoneSharingChanged(it)) },
6158
modifier = Modifier.padding(16.dp),
6259
)

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
@@ -5,6 +5,10 @@ import com.gravatar.restapi.models.Profile
55
internal data class ShareUiState(
66
val profile: Profile? = null,
77
val avatarUrl: String? = null,
8+
val privateContactInfo: PrivateContactInfo = PrivateContactInfo()
9+
)
10+
11+
internal data class PrivateContactInfo(
812
val emailValue: String = "",
913
val isEmailShared: Boolean = false,
1014
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
@@ -27,16 +27,40 @@ internal class ShareViewModel(
2727
fun onEvent(shareEvent: ShareEvent) {
2828
when (shareEvent) {
2929
is ShareEvent.OnEmailValueChanged -> {
30-
_uiState.update { it.copy(emailValue = shareEvent.value) }
30+
_uiState.update {
31+
it.copy(
32+
privateContactInfo = it.privateContactInfo.copy(
33+
emailValue = shareEvent.value
34+
)
35+
)
36+
}
3137
}
3238
is ShareEvent.OnEmailSharingChanged -> {
33-
_uiState.update { it.copy(isEmailShared = shareEvent.isShared) }
39+
_uiState.update {
40+
it.copy(
41+
privateContactInfo = it.privateContactInfo.copy(
42+
isEmailShared = shareEvent.isShared
43+
)
44+
)
45+
}
3446
}
3547
is ShareEvent.OnPhoneValueChanged -> {
36-
_uiState.update { it.copy(phoneValue = shareEvent.value) }
48+
_uiState.update {
49+
it.copy(
50+
privateContactInfo = it.privateContactInfo.copy(
51+
phoneValue = shareEvent.value
52+
)
53+
)
54+
}
3755
}
3856
is ShareEvent.OnPhoneSharingChanged -> {
39-
_uiState.update { it.copy(isPhoneShared = shareEvent.isShared) }
57+
_uiState.update {
58+
it.copy(
59+
privateContactInfo = it.privateContactInfo.copy(
60+
isPhoneShared = shareEvent.isShared
61+
)
62+
)
63+
}
4064
}
4165
}
4266
}

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_tab_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_tab_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)