Skip to content

Commit eef951b

Browse files
committed
fix: Make drawer close upon account selection if AutoExpandFolder is enabled
1 parent 6843b91 commit eef951b

File tree

7 files changed

+51
-1
lines changed

7 files changed

+51
-1
lines changed

feature/navigation/drawer/dropdown/src/debug/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/ui/FakeData.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ internal object FakeData {
5555
unreadMessageCount = 0,
5656
starredMessageCount = 0,
5757
hasError = false,
58+
hasAutoExpandFolder = false,
5859
)
5960

6061
val FOLDER = Folder(
@@ -162,6 +163,7 @@ internal object FakeData {
162163
unreadMessageCount = 2,
163164
starredMessageCount = 0,
164165
hasError = false,
166+
hasAutoExpandFolder = false,
165167
),
166168
MailDisplayAccount(
167169
id = "account2",
@@ -172,6 +174,7 @@ internal object FakeData {
172174
unreadMessageCount = 12,
173175
starredMessageCount = 0,
174176
hasError = false,
177+
hasAutoExpandFolder = false,
175178
),
176179
MailDisplayAccount(
177180
id = "account3",
@@ -182,6 +185,7 @@ internal object FakeData {
182185
unreadMessageCount = 0,
183186
starredMessageCount = 0,
184187
hasError = false,
188+
hasAutoExpandFolder = false,
185189
),
186190
)
187191
}

feature/navigation/drawer/dropdown/src/main/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/domain/entity/MailDisplayAccount.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ internal data class MailDisplayAccount(
88
val email: String,
99
val color: Int,
1010
val avatar: Avatar = Avatar.Monogram("?"),
11+
val hasAutoExpandFolder: Boolean,
1112
override val unreadMessageCount: Int,
1213
override val starredMessageCount: Int,
1314
override val hasError: Boolean,

feature/navigation/drawer/dropdown/src/main/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/domain/usecase/GetDisplayAccounts.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ internal class GetDisplayAccounts(
6161
unreadMessageCount = messageCounts.unread,
6262
starredMessageCount = messageCounts.starred,
6363
hasError = accountsMap[account] == true,
64+
hasAutoExpandFolder = account.autoExpandFolderId != null,
6465
)
6566
}
6667

feature/navigation/drawer/dropdown/src/main/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/ui/DrawerViewModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import net.thunderbird.feature.navigation.drawer.dropdown.domain.DomainContract.
1717
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.DisplayAccount
1818
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.DisplayFolder
1919
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.DisplayTreeFolder
20+
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.MailDisplayAccount
2021
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.MailDisplayFolder
2122
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.UnifiedDisplayFolder
2223
import net.thunderbird.feature.navigation.drawer.dropdown.ui.DrawerContract.Effect
@@ -219,6 +220,12 @@ internal class DrawerViewModel(
219220
private fun openAccount(account: DisplayAccount?) {
220221
if (account != null) {
221222
emitEffect(Effect.OpenAccount(account.id))
223+
if (account is MailDisplayAccount && account.hasAutoExpandFolder) {
224+
viewModelScope.launch {
225+
delay(DRAWER_CLOSE_DELAY)
226+
emitEffect(Effect.CloseDrawer)
227+
}
228+
}
222229
}
223230
}
224231

feature/navigation/drawer/dropdown/src/test/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/ui/DrawerViewModelTest.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,35 @@ internal class DrawerViewModelTest {
261261
}
262262
}
263263

264+
@Test
265+
fun `should emit CloseDrawer effect after emitting OpenAccount if AutoExpandFolder is Set`() = runMviTest {
266+
val displayAccounts = createDisplayAccountList(1) + createDisplayAccount(
267+
id = "uuid-1",
268+
hasAutoExpandFolder = true,
269+
)
270+
val getDisplayAccountsFlow = MutableStateFlow(displayAccounts)
271+
val testSubject = createTestSubject(
272+
displayAccountsFlow = getDisplayAccountsFlow,
273+
)
274+
val turbines = turbinesWithInitialStateCheck(
275+
testSubject,
276+
State(
277+
accounts = displayAccounts.toImmutableList(),
278+
selectedAccountId = displayAccounts.first().id,
279+
),
280+
)
281+
advanceUntilIdle()
282+
283+
testSubject.event(Event.OnAccountClick(displayAccounts[1]))
284+
285+
assertThat(turbines.awaitEffectItem()).isEqualTo(
286+
Effect.OpenAccount(displayAccounts[1].id),
287+
)
288+
turbines.assertThatAndEffectTurbineConsumed {
289+
isEqualTo(Effect.CloseDrawer)
290+
}
291+
}
292+
264293
@Test
265294
fun `should collect display folders for selected account`() = runTest {
266295
val displayAccounts = createDisplayAccountList(3)
@@ -458,6 +487,7 @@ internal class DrawerViewModelTest {
458487
email: String = "test@example.com",
459488
unreadCount: Int = 0,
460489
starredCount: Int = 0,
490+
hasAutoExpandFolder: Boolean = false,
461491
): MailDisplayAccount {
462492
return MailDisplayAccount(
463493
id = id,
@@ -467,6 +497,7 @@ internal class DrawerViewModelTest {
467497
unreadMessageCount = unreadCount,
468498
starredMessageCount = starredCount,
469499
hasError = false,
500+
hasAutoExpandFolder = hasAutoExpandFolder,
470501
)
471502
}
472503

feature/navigation/drawer/dropdown/src/test/kotlin/net/thunderbird/feature/navigation/drawer/dropdown/ui/common/DisplayAccountUtilsTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class DisplayAccountUtilsTest {
3838
unreadMessageCount = 5,
3939
starredMessageCount = 1,
4040
hasError = false,
41+
hasAutoExpandFolder = false,
4142
)
4243

4344
// Act

legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageHomeActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,12 @@ open class MessageHomeActivity :
756756
val search = LocalMessageSearch()
757757
search.addAllowedFolder(folderId)
758758
search.addAccountUuid(account.uuid)
759-
actionDisplaySearch(this, search, noThreading = false, newTask = false)
759+
if (folderId == account.autoExpandFolderId) {
760+
performSearch(search)
761+
} else {
762+
actionDisplaySearch(this, search, noThreading = false, newTask = false)
763+
initializeFolderDrawer()
764+
}
760765
}
761766
}
762767

0 commit comments

Comments
 (0)