Skip to content

Commit 5938fb8

Browse files
authored
Merge pull request thunderbird#8735 from shamim-emon/fix-issue-8709
Fixes New menu forgets its "Hide accounts" setting
2 parents 4a0a7a4 + 7c30959 commit 5938fb8

File tree

23 files changed

+267
-43
lines changed

23 files changed

+267
-43
lines changed

feature/navigation/drawer/src/debug/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContentPreview.kt

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.compose.ui.tooling.preview.Preview
88
import androidx.compose.ui.unit.dp
99
import app.k9mail.core.ui.compose.designsystem.PreviewWithTheme
1010
import app.k9mail.core.ui.compose.designsystem.atom.Surface
11+
import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract.DrawerConfig
1112
import app.k9mail.feature.navigation.drawer.ui.FakeData.DISPLAY_ACCOUNT
1213
import app.k9mail.feature.navigation.drawer.ui.FakeData.DISPLAY_FOLDER
1314
import app.k9mail.feature.navigation.drawer.ui.FakeData.UNIFIED_FOLDER
@@ -121,7 +122,11 @@ internal fun DrawerContentSingleAccountPreview() {
121122
selectedAccountId = DISPLAY_ACCOUNT.id,
122123
folders = displayFolders,
123124
selectedFolderId = displayFolders[0].id,
124-
showAccountSelector = false,
125+
config = DrawerConfig(
126+
showUnifiedFolders = false,
127+
showStarredCount = false,
128+
showAccountSelector = false,
129+
),
125130
),
126131
onEvent = {},
127132
)
@@ -142,7 +147,11 @@ internal fun DrawerContentSingleAccountWithAccountSelectionPreview() {
142147
selectedAccountId = DISPLAY_ACCOUNT.id,
143148
folders = displayFolders,
144149
selectedFolderId = displayFolders[0].id,
145-
showAccountSelector = true,
150+
config = DrawerConfig(
151+
showUnifiedFolders = false,
152+
showStarredCount = false,
153+
showAccountSelector = true,
154+
),
146155
),
147156
onEvent = {},
148157
)
@@ -162,7 +171,11 @@ internal fun DrawerContentMultipleAccountsAccountPreview() {
162171
selectedAccountId = accountList[0].id,
163172
folders = displayFolders,
164173
selectedFolderId = UNIFIED_FOLDER.id,
165-
showAccountSelector = false,
174+
config = DrawerConfig(
175+
showUnifiedFolders = false,
176+
showStarredCount = false,
177+
showAccountSelector = false,
178+
),
166179
),
167180
onEvent = {},
168181
)
@@ -181,7 +194,11 @@ internal fun DrawerContentMultipleAccountsWithAccountSelectionPreview() {
181194
selectedAccountId = accountList[1].id,
182195
folders = createDisplayFolderList(hasUnifiedFolder = true),
183196
selectedFolderId = UNIFIED_FOLDER.id,
184-
showAccountSelector = true,
197+
config = DrawerConfig(
198+
showUnifiedFolders = false,
199+
showStarredCount = false,
200+
showAccountSelector = true,
201+
),
185202
),
186203
onEvent = {},
187204
)
@@ -200,7 +217,11 @@ internal fun DrawerContentMultipleAccountsWithDifferentAccountSelectionPreview()
200217
selectedAccountId = accountList[2].id,
201218
folders = createDisplayFolderList(hasUnifiedFolder = true),
202219
selectedFolderId = UNIFIED_FOLDER.id,
203-
showAccountSelector = true,
220+
config = DrawerConfig(
221+
showUnifiedFolders = false,
222+
showStarredCount = false,
223+
showAccountSelector = true,
224+
),
204225
),
205226
onEvent = {},
206227
)
@@ -224,7 +245,11 @@ internal fun DrawerContentSmallScreenPreview() {
224245
selectedAccountId = accountList[2].id,
225246
folders = createDisplayFolderList(hasUnifiedFolder = true),
226247
selectedFolderId = UNIFIED_FOLDER.id,
227-
showAccountSelector = true,
248+
config = DrawerConfig(
249+
showUnifiedFolders = false,
250+
showStarredCount = false,
251+
showAccountSelector = true,
252+
),
228253
),
229254
onEvent = {},
230255
)
@@ -249,7 +274,11 @@ internal fun DrawerContentVerySmallScreenPreview() {
249274
selectedAccountId = accountList[2].id,
250275
folders = createDisplayFolderList(hasUnifiedFolder = true),
251276
selectedFolderId = UNIFIED_FOLDER.id,
252-
showAccountSelector = true,
277+
config = DrawerConfig(
278+
showUnifiedFolders = false,
279+
showStarredCount = false,
280+
showAccountSelector = true,
281+
),
253282
),
254283
onEvent = {},
255284
)
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package app.k9mail.feature.navigation.drawer
22

3+
import kotlinx.coroutines.flow.Flow
4+
35
interface NavigationDrawerExternalContract {
46

57
data class DrawerConfig(
68
val showUnifiedFolders: Boolean,
79
val showStarredCount: Boolean,
10+
val showAccountSelector: Boolean,
811
)
912

1013
fun interface DrawerConfigLoader {
11-
fun loadDrawerConfig(): DrawerConfig
14+
fun loadDrawerConfigFlow(): Flow<DrawerConfig>
15+
}
16+
17+
fun interface DrawerConfigWriter {
18+
fun writeDrawerConfig(drawerConfig: DrawerConfig)
1219
}
1320
}

feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/NavigationDrawerModule.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase
44
import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayAccounts
55
import app.k9mail.feature.navigation.drawer.domain.usecase.GetDisplayFoldersForAccount
66
import app.k9mail.feature.navigation.drawer.domain.usecase.GetDrawerConfig
7+
import app.k9mail.feature.navigation.drawer.domain.usecase.SaveDrawerConfig
78
import app.k9mail.feature.navigation.drawer.domain.usecase.SyncAccount
89
import app.k9mail.feature.navigation.drawer.domain.usecase.SyncAllAccounts
910
import app.k9mail.feature.navigation.drawer.ui.DrawerViewModel
@@ -18,6 +19,11 @@ val navigationDrawerModule: Module = module {
1819
configProver = get(),
1920
)
2021
}
22+
single<UseCase.SaveDrawerConfig> {
23+
SaveDrawerConfig(
24+
drawerConfigWriter = get(),
25+
)
26+
}
2127

2228
single<UseCase.GetDisplayAccounts> {
2329
GetDisplayAccounts(
@@ -50,6 +56,7 @@ val navigationDrawerModule: Module = module {
5056
viewModel {
5157
DrawerViewModel(
5258
getDrawerConfig = get(),
59+
saveDrawerConfig = get(),
5360
getDisplayAccounts = get(),
5461
getDisplayFoldersForAccount = get(),
5562
syncAccount = get(),

feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/DomainContract.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ internal interface DomainContract {
1212
operator fun invoke(): Flow<DrawerConfig>
1313
}
1414

15+
fun interface SaveDrawerConfig {
16+
operator fun invoke(drawerConfig: DrawerConfig): Flow<Unit>
17+
}
18+
1519
fun interface GetDisplayAccounts {
1620
operator fun invoke(): Flow<List<DisplayAccount>>
1721
}

feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/domain/usecase/GetDrawerConfig.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract.Dra
44
import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract.DrawerConfigLoader
55
import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase
66
import kotlinx.coroutines.flow.Flow
7-
import kotlinx.coroutines.flow.flow
87

98
internal class GetDrawerConfig(
109
private val configProver: DrawerConfigLoader,
1110
) : UseCase.GetDrawerConfig {
1211
override operator fun invoke(): Flow<DrawerConfig> {
13-
// TODO This needs to be updated when the config changes
14-
return flow {
15-
emit(configProver.loadDrawerConfig())
16-
}
12+
return configProver.loadDrawerConfigFlow()
1713
}
1814
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package app.k9mail.feature.navigation.drawer.domain.usecase
2+
3+
import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract
4+
import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract.DrawerConfigWriter
5+
import app.k9mail.feature.navigation.drawer.domain.DomainContract.UseCase
6+
import kotlinx.coroutines.flow.Flow
7+
import kotlinx.coroutines.flow.flow
8+
9+
internal class SaveDrawerConfig(
10+
private val drawerConfigWriter: DrawerConfigWriter,
11+
) : UseCase.SaveDrawerConfig {
12+
override fun invoke(drawerConfig: NavigationDrawerExternalContract.DrawerConfig): Flow<Unit> {
13+
return flow {
14+
emit(drawerConfigWriter.writeDrawerConfig(drawerConfig))
15+
}
16+
}
17+
}

feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContent.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ internal fun DrawerContent(
4141
AccountView(
4242
account = selectedAccount,
4343
onClick = { onEvent(Event.OnAccountViewClick(selectedAccount)) },
44-
showAvatar = state.showAccountSelector,
44+
showAvatar = state.config.showAccountSelector,
4545
)
4646

4747
DividerHorizontal()
4848
}
4949
Row {
5050
AnimatedVisibility(
51-
visible = state.showAccountSelector,
51+
visible = state.config.showAccountSelector,
5252
) {
5353
AccountList(
5454
accounts = state.accounts,
@@ -76,7 +76,7 @@ internal fun DrawerContent(
7676
SettingList(
7777
onAccountSelectorClick = { onEvent(Event.OnAccountSelectorClick) },
7878
onManageFoldersClick = { onEvent(Event.OnManageFoldersClick) },
79-
showAccountSelector = state.showAccountSelector,
79+
showAccountSelector = state.config.showAccountSelector,
8080
)
8181
}
8282
}

feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerContract.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ internal interface DrawerContract {
1717
val config: DrawerConfig = DrawerConfig(
1818
showUnifiedFolders = false,
1919
showStarredCount = false,
20+
showAccountSelector = true,
2021
),
2122
val accounts: ImmutableList<DisplayAccount> = persistentListOf(),
2223
val selectedAccountId: String? = null,
2324
val folders: ImmutableList<DisplayFolder> = persistentListOf(),
2425
val selectedFolderId: String? = null,
25-
val showAccountSelector: Boolean = true,
2626
val isLoading: Boolean = false,
2727
)
2828

feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModel.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import kotlinx.coroutines.flow.collectLatest
2020
import kotlinx.coroutines.flow.distinctUntilChanged
2121
import kotlinx.coroutines.flow.filterNotNull
2222
import kotlinx.coroutines.flow.flatMapLatest
23+
import kotlinx.coroutines.flow.launchIn
2324
import kotlinx.coroutines.flow.map
2425
import kotlinx.coroutines.launch
2526

2627
@Suppress("MagicNumber", "TooManyFunctions")
2728
internal class DrawerViewModel(
2829
private val getDrawerConfig: UseCase.GetDrawerConfig,
30+
private val saveDrawerConfig: UseCase.SaveDrawerConfig,
2931
private val getDisplayAccounts: UseCase.GetDisplayAccounts,
3032
private val getDisplayFoldersForAccount: UseCase.GetDisplayFoldersForAccount,
3133
private val syncAccount: UseCase.SyncAccount,
@@ -113,7 +115,11 @@ internal class DrawerViewModel(
113115
)
114116
}
115117

116-
Event.OnAccountSelectorClick -> updateState { it.copy(showAccountSelector = it.showAccountSelector.not()) }
118+
Event.OnAccountSelectorClick -> {
119+
saveDrawerConfig(
120+
state.value.config.copy(showAccountSelector = state.value.config.showAccountSelector.not()),
121+
).launchIn(viewModelScope)
122+
}
117123
Event.OnManageFoldersClick -> emitEffect(Effect.OpenManageFolders)
118124
Event.OnSettingsClick -> emitEffect(Effect.OpenSettings)
119125
Event.OnSyncAccount -> onSyncAccount()
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
package app.k9mail.feature.navigation.drawer.domain.usecase
22

33
import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract.DrawerConfig
4+
import app.k9mail.feature.navigation.drawer.NavigationDrawerExternalContract.DrawerConfigLoader
45
import assertk.assertThat
56
import assertk.assertions.isEqualTo
67
import kotlin.test.Test
78
import kotlinx.coroutines.flow.first
9+
import kotlinx.coroutines.flow.flowOf
810
import kotlinx.coroutines.test.runTest
11+
import org.mockito.Mockito.mock
12+
import org.mockito.kotlin.whenever
913

1014
internal class GetDrawerConfigTest {
1115

1216
@Test
1317
fun `should get drawer config`() = runTest {
18+
val configProver: DrawerConfigLoader = mock()
1419
val drawerConfig = DrawerConfig(
1520
showUnifiedFolders = true,
1621
showStarredCount = true,
22+
showAccountSelector = true,
1723
)
1824

19-
val testSubject = GetDrawerConfig(
20-
configProver = { drawerConfig },
21-
)
25+
val testSubject = GetDrawerConfig(configProver = configProver)
26+
whenever(configProver.loadDrawerConfigFlow()).thenReturn(flowOf(drawerConfig))
2227

2328
val result = testSubject().first()
2429

25-
assertThat(result).isEqualTo(
26-
DrawerConfig(
27-
showUnifiedFolders = true,
28-
showStarredCount = true,
29-
),
30-
)
30+
assertThat(result).isEqualTo(drawerConfig)
3131
}
3232
}

0 commit comments

Comments
 (0)