Skip to content

Commit e3d397b

Browse files
authored
uplift(beta): fix(ui): use selected account for manage folders (#11152) (#11221)
2 parents 24554b2 + 3671165 commit e3d397b

3 files changed

Lines changed: 77 additions & 14 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.fsck.k9.activity
2+
3+
import net.thunderbird.core.android.account.LegacyAccountDto
4+
import net.thunderbird.core.android.account.LegacyAccountDtoManager
5+
import net.thunderbird.feature.search.legacy.LocalMessageSearch
6+
7+
internal fun LocalMessageSearch.resolveAccount(
8+
currentAccount: LegacyAccountDto?,
9+
accountManager: LegacyAccountDtoManager,
10+
): LegacyAccountDto? {
11+
return if (searchAllAccounts()) {
12+
null
13+
} else {
14+
accountUuids.singleOrNull()
15+
?.let { accountManager.getAccount(it) }
16+
?: currentAccount
17+
}
18+
}

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,20 +1420,8 @@ open class MessageHomeActivity :
14201420
singleFolderMode = false
14211421

14221422
val folderIds = search.folderIds
1423-
if (search.searchAllAccounts()) {
1424-
val accountUuids = search.accountUuids
1425-
if (accountUuids.size == 1) {
1426-
account = accountManager.getAccount(accountUuids.elementAt(0))
1427-
singleFolderMode = folderIds.size == 1
1428-
} else {
1429-
account = null
1430-
}
1431-
} else {
1432-
if (account == null && search.accountUuids.size == 1) {
1433-
account = accountManager.getAccount(search.accountUuids.elementAt(0))
1434-
}
1435-
singleFolderMode = folderIds.size == 1
1436-
}
1423+
account = search.resolveAccount(currentAccount = account, accountManager = accountManager)
1424+
singleFolderMode = !search.searchAllAccounts() && folderIds.size == 1
14371425

14381426
configureDrawer()
14391427
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.fsck.k9.activity
2+
3+
import assertk.assertThat
4+
import assertk.assertions.isSameInstanceAs
5+
import kotlinx.coroutines.flow.Flow
6+
import net.thunderbird.core.android.account.AccountRemovedListener
7+
import net.thunderbird.core.android.account.AccountsChangeListener
8+
import net.thunderbird.core.android.account.LegacyAccountDto
9+
import net.thunderbird.core.android.account.LegacyAccountDtoManager
10+
import net.thunderbird.feature.search.legacy.LocalMessageSearch
11+
import org.junit.Test
12+
13+
class MessageHomeAccountSelectorTest {
14+
private val firstAccount = LegacyAccountDto("11111111-1111-1111-1111-111111111111")
15+
private val secondAccount = LegacyAccountDto("22222222-2222-2222-2222-222222222222")
16+
private val accountManager = FakeLegacyAccountDtoManager(firstAccount, secondAccount)
17+
18+
@Test
19+
fun `single-account search should replace current account`() {
20+
val search = LocalMessageSearch().apply {
21+
addAccountUuid(secondAccount.uuid)
22+
}
23+
24+
val account = search.resolveAccount(
25+
currentAccount = firstAccount,
26+
accountManager = accountManager,
27+
)
28+
29+
assertThat(account).isSameInstanceAs(secondAccount)
30+
}
31+
32+
private class FakeLegacyAccountDtoManager(
33+
vararg accounts: LegacyAccountDto,
34+
) : LegacyAccountDtoManager {
35+
private val accounts = accounts.associateBy { it.uuid }
36+
37+
override fun getAccounts(): List<LegacyAccountDto> = accounts.values.toList()
38+
39+
override fun getAccountsFlow(): Flow<List<LegacyAccountDto>> = error("Not implemented")
40+
41+
override fun getAccount(accountUuid: String): LegacyAccountDto? = accounts[accountUuid]
42+
43+
override fun getAccountFlow(accountUuid: String): Flow<LegacyAccountDto?> = error("Not implemented")
44+
45+
override fun addAccountRemovedListener(listener: AccountRemovedListener) = error("Not implemented")
46+
47+
override fun moveAccount(account: LegacyAccountDto, newPosition: Int) = error("Not implemented")
48+
49+
override fun addOnAccountsChangeListener(accountsChangeListener: AccountsChangeListener) =
50+
error("Not implemented")
51+
52+
override fun removeOnAccountsChangeListener(accountsChangeListener: AccountsChangeListener) =
53+
error("Not implemented")
54+
55+
override fun saveAccount(account: LegacyAccountDto) = error("Not implemented")
56+
}
57+
}

0 commit comments

Comments
 (0)