Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 0cd0810c authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

feat(message-list): add composable message view holder

parent 93dc3273
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ dependencies {
    implementation(projects.core.ui.theme.api)
    implementation(projects.feature.launcher)
    implementation(projects.core.common)
    implementation(projects.core.ui.compose.designsystem)
    implementation(projects.feature.navigation.drawer.api)
    implementation(projects.feature.navigation.drawer.dropdown)
    implementation(projects.feature.navigation.drawer.siderail)
+79 −0
Original line number Diff line number Diff line
package com.fsck.k9.ui.messagelist.item

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.PreviewLightDark
import app.k9mail.core.ui.compose.designsystem.PreviewWithThemesLightDark
import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ConnectionSecurity
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.ui.messagelist.MessageListItem
import net.thunderbird.core.android.account.Identity
import net.thunderbird.core.android.account.LegacyAccount
import net.thunderbird.feature.account.AccountIdFactory
import net.thunderbird.feature.account.storage.profile.AvatarDto
import net.thunderbird.feature.account.storage.profile.AvatarTypeDto
import net.thunderbird.feature.account.storage.profile.ProfileDto

@Composable
@PreviewLightDark
internal fun MessageItemContentPreview() {
    PreviewWithThemesLightDark {
        MessageItemContent(
            item = fakeMessageListItem,
            isActive = true,
            isSelected = false,
        )
    }
}

private val accountId = AccountIdFactory.create()

private val serverSettings = ServerSettings(
    type = "imap",
    host = "imap.example.com",
    port = 993,
    connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED,
    authenticationType = AuthType.PLAIN,
    username = "username",
    password = "password",
    clientCertificateAlias = null,
)
private val fakeMessageListItem = MessageListItem(
    account = LegacyAccount(
        id = accountId,
        name = "Name",
        email = "test@example.com",
        profile = ProfileDto(
            id = accountId,
            name = "Name",
            color = 0xFF0000FF.toInt(),
            avatar = AvatarDto(
                avatarType = AvatarTypeDto.MONOGRAM,
                avatarMonogram = "AB",
                avatarImageUri = null,
                avatarIconName = null,
            ),
        ),
        incomingServerSettings = serverSettings,
        outgoingServerSettings = serverSettings,
        identities = listOf(Identity()),
    ),
    subject = "Subject",
    threadCount = 0,
    messageDate = 1234456789L,
    internalDate = 1234456789L,
    displayName = "Sender Name",
    displayAddress = null,
    previewText = "This is the preview text.",
    isMessageEncrypted = false,
    isRead = false,
    isStarred = false,
    isAnswered = false,
    isForwarded = false,
    hasAttachments = false,
    uniqueId = 42L,
    folderId = 123L,
    messageUid = "654321",
    databaseId = 1L,
    threadRoot = 1L,
)
+50 −0
Original line number Diff line number Diff line
package com.fsck.k9.ui.messagelist.item

import android.content.Context
import androidx.compose.ui.platform.ComposeView
import com.fsck.k9.ui.messagelist.MessageListItem
import net.thunderbird.core.ui.theme.api.FeatureThemeProvider

/**
 * A composable view holder for message list items.
 */
class ComposableMessageViewHolder(
    private val composeView: ComposeView,
    private val themeProvider: FeatureThemeProvider,
) : MessageListViewHolder(composeView) {

    var uniqueId: Long = -1L

    fun bind(item: MessageListItem, isActive: Boolean, isSelected: Boolean) {
        uniqueId = item.uniqueId

        composeView.setContent {
            themeProvider.WithTheme {
                MessageItemContent(
                    item = item,
                    isActive = isActive,
                    isSelected = isSelected,
                )
            }
        }
    }

    companion object {

        fun create(
            context: Context,
            themeProvider: FeatureThemeProvider,
        ): ComposableMessageViewHolder {
            val composeView = ComposeView(context)

            val holder = ComposableMessageViewHolder(
                composeView = composeView,
                themeProvider = themeProvider,
            )

            composeView.tag = holder

            return holder
        }
    }
}
+20 −0
Original line number Diff line number Diff line
package com.fsck.k9.ui.messagelist.item

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyMedium
import app.k9mail.core.ui.compose.theme2.MainTheme
import com.fsck.k9.ui.messagelist.MessageListItem

@Composable
internal fun MessageItemContent(item: MessageListItem, isActive: Boolean, isSelected: Boolean) {
    Column(
        modifier = Modifier
            .padding(MainTheme.spacings.default),
    ) {
        TextBodyMedium(text = "UniqueId: ${item.uniqueId}")
        TextBodyMedium(text = "Active: $isActive, Selected: $isSelected")
    }
}