Skip to content

Commit

Permalink
Merge pull request #8776 from wmontwe/add-drawer-previews
Browse files Browse the repository at this point in the history
Add more drawer previews for corner cases
  • Loading branch information
wmontwe authored Jan 27, 2025
2 parents 364d0cc + c943c77 commit bd57afd
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package app.k9mail.feature.navigation.drawer.ui

import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import app.k9mail.core.ui.compose.designsystem.PreviewWithTheme
import app.k9mail.core.ui.compose.designsystem.atom.Surface
import app.k9mail.feature.navigation.drawer.ui.FakeData.DISPLAY_ACCOUNT
import app.k9mail.feature.navigation.drawer.ui.FakeData.DISPLAY_FOLDER
import app.k9mail.feature.navigation.drawer.ui.FakeData.UNIFIED_FOLDER
import app.k9mail.feature.navigation.drawer.ui.FakeData.createAccountList
import app.k9mail.feature.navigation.drawer.ui.FakeData.createDisplayFolderList
import kotlinx.collections.immutable.persistentListOf

@Composable
Expand Down Expand Up @@ -99,3 +106,153 @@ internal fun DrawerContentWithSelectedUnifiedFolderPreview() {
)
}
}

@Composable
@Preview(showBackground = true)
internal fun DrawerContentSingleAccountPreview() {
val displayFolders = createDisplayFolderList(hasUnifiedFolder = false)

PreviewWithTheme {
DrawerContent(
state = DrawerContract.State(
accounts = persistentListOf(
DISPLAY_ACCOUNT,
),
selectedAccountId = DISPLAY_ACCOUNT.id,
folders = displayFolders,
selectedFolderId = displayFolders[0].id,
showAccountSelector = false,
),
onEvent = {},
)
}
}

@Composable
@Preview(showBackground = true)
internal fun DrawerContentSingleAccountWithAccountSelectionPreview() {
val displayFolders = createDisplayFolderList(hasUnifiedFolder = false)

PreviewWithTheme {
DrawerContent(
state = DrawerContract.State(
accounts = persistentListOf(
DISPLAY_ACCOUNT,
),
selectedAccountId = DISPLAY_ACCOUNT.id,
folders = displayFolders,
selectedFolderId = displayFolders[0].id,
showAccountSelector = true,
),
onEvent = {},
)
}
}

@Composable
@Preview(showBackground = true)
internal fun DrawerContentMultipleAccountsAccountPreview() {
val accountList = createAccountList()
val displayFolders = createDisplayFolderList(hasUnifiedFolder = true)

PreviewWithTheme {
DrawerContent(
state = DrawerContract.State(
accounts = accountList,
selectedAccountId = accountList[0].id,
folders = displayFolders,
selectedFolderId = UNIFIED_FOLDER.id,
showAccountSelector = false,
),
onEvent = {},
)
}
}

@Composable
@Preview(showBackground = true)
internal fun DrawerContentMultipleAccountsWithAccountSelectionPreview() {
val accountList = createAccountList()

PreviewWithTheme {
DrawerContent(
state = DrawerContract.State(
accounts = accountList,
selectedAccountId = accountList[1].id,
folders = createDisplayFolderList(hasUnifiedFolder = true),
selectedFolderId = UNIFIED_FOLDER.id,
showAccountSelector = true,
),
onEvent = {},
)
}
}

@Composable
@Preview(showBackground = true)
internal fun DrawerContentMultipleAccountsWithDifferentAccountSelectionPreview() {
val accountList = createAccountList()

PreviewWithTheme {
DrawerContent(
state = DrawerContract.State(
accounts = accountList,
selectedAccountId = accountList[2].id,
folders = createDisplayFolderList(hasUnifiedFolder = true),
selectedFolderId = UNIFIED_FOLDER.id,
showAccountSelector = true,
),
onEvent = {},
)
}
}

@Composable
@Preview(showBackground = true)
internal fun DrawerContentSmallScreenPreview() {
val accountList = createAccountList()

PreviewWithTheme {
Surface(
modifier = Modifier
.width(320.dp)
.height(480.dp),
) {
DrawerContent(
state = DrawerContract.State(
accounts = accountList,
selectedAccountId = accountList[2].id,
folders = createDisplayFolderList(hasUnifiedFolder = true),
selectedFolderId = UNIFIED_FOLDER.id,
showAccountSelector = true,
),
onEvent = {},
)
}
}
}

@Composable
@Preview(showBackground = true)
internal fun DrawerContentVerySmallScreenPreview() {
val accountList = createAccountList()

PreviewWithTheme {
Surface(
modifier = Modifier
.width(240.dp)
.height(320.dp),
) {
DrawerContent(
state = DrawerContract.State(
accounts = accountList,
selectedAccountId = accountList[2].id,
folders = createDisplayFolderList(hasUnifiedFolder = true),
selectedFolderId = UNIFIED_FOLDER.id,
showAccountSelector = true,
),
onEvent = {},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import app.k9mail.core.mail.folder.api.Folder
import app.k9mail.core.mail.folder.api.FolderType
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccount
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayAccountFolder
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayFolder
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayUnifiedFolder
import app.k9mail.feature.navigation.drawer.domain.entity.DisplayUnifiedFolderType
import app.k9mail.legacy.account.Account
import app.k9mail.legacy.account.Identity
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList

internal object FakeData {

Expand Down Expand Up @@ -66,4 +70,92 @@ internal object FakeData {
unreadMessageCount = 123,
starredMessageCount = 567,
)

fun createAccountList(): PersistentList<DisplayAccount> {
return persistentListOf(
DisplayAccount(
id = "account1",
name = "[email protected]",
email = "[email protected]",
color = Color.Green.toArgb(),
unreadMessageCount = 2,
starredMessageCount = 0,
),
DisplayAccount(
id = "account2",
name = "Jodie Doe",
email = "[email protected]",
color = Color.Red.toArgb(),
unreadMessageCount = 12,
starredMessageCount = 0,
),
DisplayAccount(
id = "account3",
name = "John Doe",
email = "[email protected]",
color = Color.Cyan.toArgb(),
unreadMessageCount = 0,
starredMessageCount = 0,
),
)
}

fun createDisplayFolderList(hasUnifiedFolder: Boolean): PersistentList<DisplayFolder> {
val folders = mutableListOf<DisplayFolder>()

if (hasUnifiedFolder) {
folders.add(UNIFIED_FOLDER)
}

folders.addAll(
listOf(
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 2, name = "Inbox", type = FolderType.INBOX),
unreadMessageCount = 12,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 3, name = "Outbox", type = FolderType.OUTBOX),
unreadMessageCount = 0,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 4, name = "Drafts", type = FolderType.DRAFTS),
unreadMessageCount = 0,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 5, name = "Sent", type = FolderType.SENT),
unreadMessageCount = 0,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 6, name = "Spam", type = FolderType.SPAM),
unreadMessageCount = 5,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 7, name = "Trash", type = FolderType.TRASH),
unreadMessageCount = 0,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 8, name = "Archive", type = FolderType.ARCHIVE),
unreadMessageCount = 0,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 9, name = "Work", type = FolderType.REGULAR),
unreadMessageCount = 3,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 10, name = "Personal", type = FolderType.REGULAR),
unreadMessageCount = 4,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 11, name = "Important", type = FolderType.REGULAR),
unreadMessageCount = 0,
),
DISPLAY_FOLDER.copy(
folder = FOLDER.copy(id = 12, name = "Later", type = FolderType.REGULAR),
unreadMessageCount = 0,
),
),
)

return folders.toPersistentList()
}
}

0 comments on commit bd57afd

Please sign in to comment.