Skip to content

Commit 8f59c9b

Browse files
committed
feat(account-setting): add profile indicator setting
1 parent ca77566 commit 8f59c9b

File tree

7 files changed

+94
-0
lines changed

7 files changed

+94
-0
lines changed

feature/account/settings/impl/src/main/kotlin/net/thunderbird/feature/account/settings/impl/domain/AccountSettingsDomainContract.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ internal interface AccountSettingsDomainContract {
4141
color: Int,
4242
): @Composable (Modifier) -> Unit
4343

44+
val profileIndicatorTitle: () -> String
45+
val profileIndicatorMonogram: () -> String
46+
val profileIndicatorImage: () -> String
47+
val profileIndicatorIcon: () -> String
48+
4449
val nameTitle: () -> String
4550
val nameDescription: () -> String?
4651
val nameIcon: () -> ImageVector?

feature/account/settings/impl/src/main/kotlin/net/thunderbird/feature/account/settings/impl/domain/entity/GeneralPreference.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package net.thunderbird.feature.account.settings.impl.domain.entity
22

33
import net.thunderbird.feature.account.AccountId
44

5+
/**
6+
* General preferences that can be set for an account.
7+
*/
58
internal enum class GeneralPreference {
69
PROFILE,
10+
PROFILE_INDICATOR,
711
NAME,
812
COLOR,
913
}

feature/account/settings/impl/src/main/kotlin/net/thunderbird/feature/account/settings/impl/domain/usecase/GetGeneralSettings.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package net.thunderbird.feature.account.settings.impl.domain.usecase
22

3+
import kotlinx.collections.immutable.ImmutableList
34
import kotlinx.collections.immutable.persistentListOf
45
import kotlinx.coroutines.flow.Flow
56
import kotlinx.coroutines.flow.map
67
import net.thunderbird.core.outcome.Outcome
78
import net.thunderbird.core.ui.setting.SettingDecoration
89
import net.thunderbird.core.ui.setting.SettingValue
10+
import net.thunderbird.core.ui.setting.SettingValue.CompactSelectSingleOption.CompactOption
911
import net.thunderbird.core.ui.setting.Settings
1012
import net.thunderbird.feature.account.AccountId
13+
import net.thunderbird.feature.account.profile.AccountAvatar
1114
import net.thunderbird.feature.account.profile.AccountProfile
1215
import net.thunderbird.feature.account.profile.AccountProfileRepository
1316
import net.thunderbird.feature.account.settings.impl.domain.AccountSettingsDomainContract.ResourceProvider
@@ -36,6 +39,8 @@ internal class GetGeneralSettings(
3639
}
3740

3841
private fun generateSettings(accountId: AccountId, profile: AccountProfile): Settings {
42+
val profileIndicatorOptions = generateProfileIndicatorOptions(profile.id)
43+
3944
return persistentListOf(
4045
SettingDecoration.Custom(
4146
id = GeneralPreference.PROFILE.generateId(accountId),
@@ -44,6 +49,12 @@ internal class GetGeneralSettings(
4449
color = profile.color,
4550
),
4651
),
52+
SettingValue.CompactSelectSingleOption(
53+
id = GeneralPreference.PROFILE_INDICATOR.generateId(accountId),
54+
title = resourceProvider.profileIndicatorTitle,
55+
value = selectProfileIndicatorOption(profile, profileIndicatorOptions),
56+
options = profileIndicatorOptions,
57+
),
4758
SettingValue.Text(
4859
id = GeneralPreference.NAME.generateId(accountId),
4960
title = resourceProvider.nameTitle,
@@ -61,4 +72,44 @@ internal class GetGeneralSettings(
6172
),
6273
)
6374
}
75+
76+
private fun selectProfileIndicatorOption(profile: AccountProfile, options: List<CompactOption>): CompactOption {
77+
return when (profile.avatar) {
78+
is AccountAvatar.Monogram -> options.first {
79+
it.id == generateMonogramId(profile.id.asRaw())
80+
}
81+
is AccountAvatar.Image -> options.first {
82+
it.id == generateImageId(profile.id.asRaw())
83+
}
84+
is AccountAvatar.Icon -> options.first {
85+
it.id == generateIconId(profile.id.asRaw())
86+
}
87+
}
88+
}
89+
90+
private fun generateProfileIndicatorOptions(accountId: AccountId): ImmutableList<CompactOption> {
91+
return persistentListOf(
92+
CompactOption(
93+
id = generateMonogramId(accountId.asRaw()),
94+
title = resourceProvider.profileIndicatorMonogram,
95+
),
96+
CompactOption(
97+
id = generateImageId(accountId.asRaw()),
98+
title = resourceProvider.profileIndicatorImage,
99+
),
100+
CompactOption(
101+
id = generateIconId(accountId.asRaw()),
102+
title = resourceProvider.profileIndicatorIcon,
103+
),
104+
)
105+
}
106+
107+
private fun generateMonogramId(accountId: String): String =
108+
"$accountId-profile-indicator-monogram"
109+
110+
private fun generateImageId(accountId: String): String =
111+
"$accountId-profile-indicator-image"
112+
113+
private fun generateIconId(accountId: String): String =
114+
"$accountId-profile-indicator-icon"
64115
}

feature/account/settings/impl/src/main/kotlin/net/thunderbird/feature/account/settings/impl/domain/usecase/UpdateGeneralSettings.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import kotlinx.coroutines.flow.firstOrNull
44
import net.thunderbird.core.outcome.Outcome
55
import net.thunderbird.core.ui.setting.SettingValue
66
import net.thunderbird.feature.account.AccountId
7+
import net.thunderbird.feature.account.profile.AccountAvatar
78
import net.thunderbird.feature.account.profile.AccountProfile
89
import net.thunderbird.feature.account.profile.AccountProfileRepository
910
import net.thunderbird.feature.account.settings.impl.domain.AccountSettingsDomainContract.SettingsError
@@ -19,6 +20,13 @@ internal class UpdateGeneralSettings(
1920
setting: SettingValue<*>,
2021
): Outcome<Unit, SettingsError> {
2122
return when (setting.id) {
23+
GeneralPreference.PROFILE_INDICATOR.generateId(accountId) -> {
24+
val avatar = setting.value as AccountAvatar
25+
updateAccountProfile(accountId) {
26+
copy(avatar = avatar)
27+
}
28+
}
29+
2230
GeneralPreference.NAME.generateId(accountId) -> {
2331
updateAccountProfile(accountId) {
2432
copy(name = setting.value as String)

feature/account/settings/impl/src/main/kotlin/net/thunderbird/feature/account/settings/impl/ui/general/GeneralResourceProvider.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ internal class GeneralResourceProvider(
2828
)
2929
}
3030

31+
override val profileIndicatorTitle: () -> String = {
32+
context.getString(R.string.account_settings_general_profile_indicator_title)
33+
}
34+
35+
override val profileIndicatorMonogram: () -> String = {
36+
context.getString(R.string.account_settings_general_profile_indicator_monogram)
37+
}
38+
39+
override val profileIndicatorImage: () -> String = {
40+
context.getString(R.string.account_settings_general_profile_indicator_image)
41+
}
42+
43+
override val profileIndicatorIcon: () -> String = {
44+
context.getString(R.string.account_settings_general_profile_indicator_icon)
45+
}
46+
3147
override val nameTitle: () -> String = {
3248
context.getString(R.string.account_settings_general_name_title)
3349
}

feature/account/settings/impl/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
<string name="account_settings_general_title">General Settings</string>
55

6+
<string name="account_settings_general_profile_indicator_title">Profile Indicator</string>
7+
<string name="account_settings_general_profile_indicator_monogram">Monogram</string>
8+
<string name="account_settings_general_profile_indicator_image">Image</string>
9+
<string name="account_settings_general_profile_indicator_icon">Icon</string>
10+
611
<string name="account_settings_general_name_title">Account name</string>
712
<string name="account_settings_general_name_description">The name associated with your account.</string>
813

feature/account/settings/impl/src/test/kotlin/net/thunderbird/feature/account/settings/impl/domain/usecase/FakeGeneralResourceProvider.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ internal class FakeGeneralResourceProvider : ResourceProvider.GeneralResourcePro
2121
override val colorDescription: () -> String? = { null }
2222
override val colorIcon: () -> ImageVector? = { null }
2323
override val colors: ImmutableList<Int> = persistentListOf(0xFF0000, 0x00FF00, 0x0000FF)
24+
25+
override val profileIndicatorIcon: () -> String = { "ProfileIndicatorIcon" }
26+
override val profileIndicatorImage: () -> String = { "ProfileIndicatorImage" }
27+
override val profileIndicatorMonogram: () -> String = { "ProfileIndicatorMonogram" }
28+
override val profileIndicatorTitle: () -> String = { "Profile Indicator" }
2429
}

0 commit comments

Comments
 (0)