Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ interface NavigationDrawerExternalContract {
data class DrawerConfig(
val showUnifiedFolders: Boolean,
val showStarredCount: Boolean,
val showAccountSelector: Boolean,
val expandAllFolder: Boolean,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ internal fun DrawerContentSingleAccountPreview() {
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = false,
expandAllFolder = false,
),
showAccountSelector = false,
),
onEvent = {},
)
Expand All @@ -151,9 +151,9 @@ internal fun DrawerContentSingleAccountWithAccountSelectionPreview() {
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = true,
expandAllFolder = false,
),
showAccountSelector = true,
),
onEvent = {},
)
Expand All @@ -176,9 +176,9 @@ internal fun DrawerContentMultipleAccountsAccountPreview() {
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = false,
expandAllFolder = false,
),
showAccountSelector = false,
),
onEvent = {},
)
Expand All @@ -200,9 +200,9 @@ internal fun DrawerContentMultipleAccountsWithAccountSelectionPreview() {
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = true,
expandAllFolder = false,
),
showAccountSelector = true,
),
onEvent = {},
)
Expand All @@ -224,9 +224,9 @@ internal fun DrawerContentMultipleAccountsWithDifferentAccountSelectionPreview()
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = true,
expandAllFolder = false,
),
showAccountSelector = true,
),
onEvent = {},
)
Expand All @@ -253,9 +253,9 @@ internal fun DrawerContentSmallScreenPreview() {
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = true,
expandAllFolder = false,
),
showAccountSelector = true,
),
onEvent = {},
)
Expand Down Expand Up @@ -283,9 +283,9 @@ internal fun DrawerContentVerySmallScreenPreview() {
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = true,
expandAllFolder = false,
),
showAccountSelector = true,
),
onEvent = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ val navigationDropDownDrawerModule: Module = module {
viewModel {
DrawerViewModel(
getDrawerConfig = get(),
saveDrawerConfig = get(),
getDisplayAccounts = get(),
getDisplayFoldersForAccount = get(),
getDisplayTreeFolder = get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ internal interface DrawerContract {
val config: DrawerConfig = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = true,
expandAllFolder = false,
),
val showAccountSelector: Boolean = true,
val accounts: ImmutableList<DisplayAccount> = persistentListOf(),
val selectedAccountId: String? = null,
val rootFolder: DisplayTreeFolder = DisplayTreeFolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import net.thunderbird.feature.navigation.drawer.dropdown.domain.DomainContract.UseCase
Expand All @@ -35,7 +34,6 @@ private const val ACCOUNT_CLOSE_DELAY = 150L
@Suppress("MagicNumber", "TooManyFunctions")
internal class DrawerViewModel(
private val getDrawerConfig: UseCase.GetDrawerConfig,
private val saveDrawerConfig: UseCase.SaveDrawerConfig,
private val getDisplayAccounts: UseCase.GetDisplayAccounts,
private val getDisplayFoldersForAccount: UseCase.GetDisplayFoldersForAccount,
private val getDisplayTreeFolder: UseCase.GetDisplayTreeFolder,
Expand Down Expand Up @@ -166,12 +164,12 @@ internal class DrawerViewModel(

Event.OnAccountSelectorClick -> {
viewModelScope.launch {
saveDrawerConfig(
state.value.config.copy(showAccountSelector = state.value.config.showAccountSelector.not()),
).launchIn(viewModelScope)
delay(ACCOUNT_CLOSE_DELAY)
updateState {
it.copy(showAccountSelection = it.showAccountSelection.not())
it.copy(
showAccountSelection = it.showAccountSelection.not(),
showAccountSelector = it.showAccountSelector.not(),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ internal class GetDrawerConfigTest {
val drawerConfig = DrawerConfig(
showUnifiedFolders = true,
showStarredCount = true,
showAccountSelector = true,
expandAllFolder = false,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ internal class DrawerStateTest {
config = DrawerConfig(
showUnifiedFolders = false,
showStarredCount = false,
showAccountSelector = true,
expandAllFolder = false,
),
showAccountSelector = true,
accounts = persistentListOf(),
selectedAccountId = null,
rootFolder = DisplayTreeFolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import net.thunderbird.core.testing.coroutines.MainDispatcherRule
import net.thunderbird.feature.mail.folder.api.Folder
import net.thunderbird.feature.mail.folder.api.FolderType
import net.thunderbird.feature.navigation.drawer.api.NavigationDrawerExternalContract.DrawerConfig
import net.thunderbird.feature.navigation.drawer.dropdown.domain.DomainContract.UseCase
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.DisplayFolder
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.DisplayTreeFolder
import net.thunderbird.feature.navigation.drawer.dropdown.domain.entity.MailDisplayAccount
Expand All @@ -34,12 +32,6 @@ import net.thunderbird.feature.navigation.drawer.dropdown.ui.DrawerContract.Even
import net.thunderbird.feature.navigation.drawer.dropdown.ui.DrawerContract.State
import net.thunderbird.feature.navigation.drawer.dropdown.ui.FakeData.MAIL_DISPLAY_ACCOUNT
import org.junit.Rule
import org.mockito.Mockito.mock
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.whenever

@OptIn(ExperimentalCoroutinesApi::class)
internal class DrawerViewModelTest {
Expand Down Expand Up @@ -382,64 +374,6 @@ internal class DrawerViewModelTest {
}
}

@Suppress("MaxLineLength")
@Test
fun `when initial state has drawerConfigWithAccountSelectorDisabled saveDrawerConfig should receive drawerConfigWithAccountSelectorEnabled when OnAccountSelectorClick event is received`() =
runTest {
val drawerConfigWithAccountSelectorEnabled = createDrawerConfig(showAccountSelector = true)
val drawerConfigWithAccountSelectorDisabled = createDrawerConfig(showAccountSelector = false)

val saveDrawerConfig: UseCase.SaveDrawerConfig = mock()
whenever(
saveDrawerConfig.invoke(any<DrawerConfig>()),
).thenReturn(flowOf(Unit))

val testSubject = createTestSubject(
initialState = State(config = drawerConfigWithAccountSelectorDisabled, showAccountSelection = false),
saveDrawerConfig = saveDrawerConfig,
drawerConfigFlow = flowOf(drawerConfigWithAccountSelectorDisabled),
)

val captor = argumentCaptor<DrawerConfig>()

testSubject.event(Event.OnAccountSelectorClick)
advanceUntilIdle()
verify(saveDrawerConfig, times(1)).invoke(captor.capture())
assertThat(captor.firstValue).isEqualTo(drawerConfigWithAccountSelectorEnabled)

// Verify that showAccountSelection is toggled after the delay
assertThat(testSubject.state.value.showAccountSelection).isEqualTo(true)
}

@Suppress("MaxLineLength")
@Test
fun `when initial state has drawerConfigWithAccountSelectorEnabled saveDrawerConfig should receive drawerConfigWithAccountSelectorDisabled when OnAccountSelectorClick event is received`() =
runTest {
val drawerConfigWithAccountSelectorEnabled = createDrawerConfig(showAccountSelector = true)
val drawerConfigWithAccountSelectorDisabled = createDrawerConfig(showAccountSelector = false)

val saveDrawerConfig: UseCase.SaveDrawerConfig = mock()
whenever(
saveDrawerConfig.invoke(any<DrawerConfig>()),
).thenReturn(flowOf(Unit))

val testSubject = createTestSubject(
initialState = State(config = drawerConfigWithAccountSelectorEnabled, showAccountSelection = false),
saveDrawerConfig = saveDrawerConfig,
drawerConfigFlow = flowOf(drawerConfigWithAccountSelectorEnabled),
)

val captor = argumentCaptor<DrawerConfig>()

testSubject.event(Event.OnAccountSelectorClick)
advanceUntilIdle()
verify(saveDrawerConfig, times(1)).invoke(captor.capture())
assertThat(captor.firstValue).isEqualTo(drawerConfigWithAccountSelectorDisabled)

// Verify that showAccountSelection is toggled after the delay
assertThat(testSubject.state.value.showAccountSelection).isEqualTo(true)
}

@Test
fun `should emit OpenManageFolders effect when OnManageFoldersClick event is received`() = runMviTest {
val testSubject = createTestSubject()
Expand Down Expand Up @@ -478,7 +412,6 @@ internal class DrawerViewModelTest {
),
syncAccountFlow: Flow<Result<Unit>> = flow { emit(Result.success(Unit)) },
syncAllAccounts: Flow<Result<Unit>> = flow { emit(Result.success(Unit)) },
saveDrawerConfig: UseCase.SaveDrawerConfig = mock(),
): DrawerViewModel {
return DrawerViewModel(
initialState = initialState,
Expand All @@ -492,20 +425,17 @@ internal class DrawerViewModelTest {
},
syncAccount = { syncAccountFlow },
syncAllAccounts = { syncAllAccounts },
saveDrawerConfig = saveDrawerConfig,
)
}

private fun createDrawerConfig(
showUnifiedInbox: Boolean = false,
showStarredCount: Boolean = false,
showAccountSelector: Boolean = true,
expandAllFolder: Boolean = false,
): DrawerConfig {
return DrawerConfig(
showUnifiedFolders = showUnifiedInbox,
showStarredCount = showStarredCount,
showAccountSelector = showAccountSelector,
expandAllFolder = expandAllFolder,
)
}
Expand Down
5 changes: 0 additions & 5 deletions legacy/core/src/main/java/com/fsck/k9/K9.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ object K9 : KoinComponent {
var messageViewPostMarkAsUnreadNavigation: PostMarkAsUnreadNavigation =
PostMarkAsUnreadNavigation.ReturnToMessageList

@JvmStatic
var isShowAccountSelector = true

@get:Synchronized
@set:Synchronized
@JvmStatic
Expand Down Expand Up @@ -193,7 +190,6 @@ object K9 : KoinComponent {
@JvmStatic
@Suppress("LongMethod")
fun loadPrefs(storage: Storage) {
isShowAccountSelector = storage.getBoolean("showAccountSelector", true)
messageViewPostMarkAsUnreadNavigation =
storage.getEnum("messageViewPostMarkAsUnreadAction", PostMarkAsUnreadNavigation.ReturnToMessageList)

Expand Down Expand Up @@ -231,7 +227,6 @@ object K9 : KoinComponent {

@Suppress("LongMethod")
internal fun save(editor: StorageEditor) {
editor.putBoolean("showAccountSelector", isShowAccountSelector)
editor.putEnum("messageViewPostMarkAsUnreadAction", messageViewPostMarkAsUnreadNavigation)

editor.putEnum("sortTypeEnum", sortType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
package com.fsck.k9.preferences

import com.fsck.k9.K9
import com.fsck.k9.Preferences
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import net.thunderbird.core.preference.display.inboxSettings.DisplayInboxSettingsPreferenceManager
import net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingsPreferenceManager
import net.thunderbird.core.preference.update
import net.thunderbird.feature.navigation.drawer.api.NavigationDrawerExternalContract.DrawerConfig

internal class DefaultDrawerConfigManager(
private val preferences: Preferences,
coroutineScope: CoroutineScope,
private val displayInboxSettingsPreferenceManager: DisplayInboxSettingsPreferenceManager,
private val displayVisualSettingsPreferenceManager: DisplayVisualSettingsPreferenceManager,
) : DrawerConfigManager {
private val showAccountSelector = MutableStateFlow(K9.isShowAccountSelector)
private val drawerConfig: StateFlow<DrawerConfig> = showAccountSelector
.combine(
displayInboxSettingsPreferenceManager.getConfigFlow(),
) { showAccSelector, displayInboxSettings ->
Pair(showAccSelector, displayInboxSettings)
}
.combine(
displayVisualSettingsPreferenceManager.getConfigFlow(),
) { (showAccSelector, displayInboxSettings), displayVisualSettings ->
private val drawerConfig: StateFlow<DrawerConfig> = flow {
emit(
DrawerConfig(
showAccountSelector = showAccSelector,
showStarredCount = displayInboxSettings.isShowStarredCount,
showUnifiedFolders = displayInboxSettings.isShowUnifiedInbox,
expandAllFolder = displayVisualSettings.drawerExpandAllFolder,
)
}
showStarredCount = displayInboxSettingsPreferenceManager.getConfig().isShowStarredCount,
showUnifiedFolders = displayInboxSettingsPreferenceManager.getConfig().isShowUnifiedInbox,
expandAllFolder = displayVisualSettingsPreferenceManager.getConfig().drawerExpandAllFolder,
),
)
}
.stateIn(
scope = coroutineScope,
started = SharingStarted.WhileSubscribed(),
initialValue = DrawerConfig(
showAccountSelector = false,
showStarredCount = false,
showUnifiedFolders = false,
expandAllFolder = false,
Expand All @@ -56,12 +42,9 @@ internal class DefaultDrawerConfigManager(
isShowUnifiedInbox = config.showUnifiedFolders,
)
}

val editor = preferences.createStorageEditor()
K9.save(editor)
editor.putBoolean("showAccountSelector", config.showAccountSelector)
editor.commit()
showAccountSelector.update { config.showAccountSelector }
displayVisualSettingsPreferenceManager.update {
it.copy(drawerExpandAllFolder = config.expandAllFolder)
}
}

@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ val preferencesModule = module {
} bind GeneralSettingsManager::class
single {
DefaultDrawerConfigManager(
preferences = get(),
coroutineScope = get(named("AppCoroutineScope")),
displayInboxSettingsPreferenceManager = get(),
displayVisualSettingsPreferenceManager = get(),
Expand Down
Loading