Skip to content

Commit 1a66288

Browse files
authored
Merge pull request #9864 from shamim-emon/fix-issue-9463
Fix: Unified Account is still displayed on TB application even if there is only one account
2 parents 9cf083f + 85b2a12 commit 1a66288

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

legacy/core/src/main/java/com/fsck/k9/preferences/UnifiedInboxConfigurator.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,31 @@ import net.thunderbird.core.preference.GeneralSettingsManager
55
import net.thunderbird.core.preference.update
66

77
/**
8-
* Configures the unified inbox after an account has been added.
8+
* Configures the unified inbox based on the number of accounts:
9+
* - If there is exactly 1 account → unified inbox is disabled.
10+
* - If there are exactly 2 accounts → unified inbox is enabled.
11+
* - For all other cases → no change is made.
912
*/
1013
class UnifiedInboxConfigurator(
1114
private val accountManager: LegacyAccountDtoManager,
1215
private val generalSettingsManager: GeneralSettingsManager,
1316
) {
1417
fun configureUnifiedInbox() {
15-
if (accountManager.getAccounts().size == 2) {
16-
generalSettingsManager.update { settings ->
17-
settings.copy(
18-
display = settings.display.copy(
19-
inboxSettings = settings.display.inboxSettings.copy(
20-
isShowUnifiedInbox = true,
21-
),
18+
when (accountManager.getAccounts().size) {
19+
1 -> updateUnifiedInbox(false)
20+
2 -> updateUnifiedInbox(true)
21+
else -> Unit
22+
}
23+
}
24+
private fun updateUnifiedInbox(isShowUnifiedInbox: Boolean) {
25+
generalSettingsManager.update { settings ->
26+
settings.copy(
27+
display = settings.display.copy(
28+
inboxSettings = settings.display.inboxSettings.copy(
29+
isShowUnifiedInbox = isShowUnifiedInbox,
2230
),
23-
)
24-
}
31+
),
32+
)
2533
}
2634
}
2735
}

legacy/core/src/test/java/com/fsck/k9/UnifiedInboxConfiguratorTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ class UnifiedInboxConfiguratorTest {
6767
assertThat(generalSettingsManager.getConfig().display.inboxSettings.isShowUnifiedInbox).isEqualTo(true)
6868
}
6969

70+
@Test
71+
fun `configureUnifiedInbox should disable unified inbox when there is only one account`() {
72+
// Given
73+
`when`(accountManager.getAccounts()).thenReturn(listOf(mock()))
74+
75+
// When
76+
configurator.configureUnifiedInbox()
77+
78+
// Then
79+
assertThat(generalSettingsManager.getConfig().display.inboxSettings.isShowUnifiedInbox).isEqualTo(false)
80+
}
81+
7082
@Test
7183
fun `configureUnifiedInbox should not enable unified inbox when there are less than two accounts`() {
7284
// Given

legacy/ui/legacy/src/main/java/com/fsck/k9/account/AccountRemover.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.fsck.k9.Preferences
66
import com.fsck.k9.backend.BackendManager
77
import com.fsck.k9.controller.MessagingController
88
import com.fsck.k9.mailstore.LocalStoreProvider
9+
import com.fsck.k9.preferences.UnifiedInboxConfigurator
910
import net.thunderbird.core.android.account.LegacyAccountDto
1011
import net.thunderbird.core.logging.legacy.Log
1112

@@ -18,6 +19,7 @@ class AccountRemover(
1819
private val backendManager: BackendManager,
1920
private val localKeyStoreManager: LocalKeyStoreManager,
2021
private val preferences: Preferences,
22+
private val unifiedInboxConfigurator: UnifiedInboxConfigurator,
2123
) {
2224

2325
fun removeAccount(accountUuid: String) {
@@ -38,6 +40,7 @@ class AccountRemover(
3840

3941
removeCertificates(account)
4042
Core.setServicesEnabled()
43+
unifiedInboxConfigurator.configureUnifiedInbox()
4144

4245
Log.v("Finished removing account '%s'.", accountName)
4346
}

legacy/ui/legacy/src/main/java/com/fsck/k9/account/KoinModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ val accountModule = module {
1111
backendManager = get(),
1212
localKeyStoreManager = get(),
1313
preferences = get(),
14+
unifiedInboxConfigurator = get(),
1415
)
1516
}
1617
factory { BackgroundAccountRemover(get()) }

0 commit comments

Comments
 (0)