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 @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import app.k9mail.core.ui.compose.theme2.MainTheme
Expand All @@ -17,6 +18,7 @@ fun TextBodyMedium(
textAlign: TextAlign? = null,
overflow: TextOverflow = TextOverflow.Clip,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {},
) {
Material3Text(
text = text,
Expand All @@ -26,6 +28,7 @@ fun TextBodyMedium(
overflow = overflow,
maxLines = maxLines,
style = MainTheme.typography.bodyMedium,
onTextLayout = onTextLayout,
)
}

Expand All @@ -37,6 +40,7 @@ fun TextBodyMedium(
textAlign: TextAlign? = null,
overflow: TextOverflow = TextOverflow.Clip,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {},
) {
Material3Text(
text = text,
Expand All @@ -46,5 +50,6 @@ fun TextBodyMedium(
overflow = overflow,
maxLines = maxLines,
style = MainTheme.typography.bodyMedium,
onTextLayout = onTextLayout,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.style.TextOverflow
import app.k9mail.core.ui.compose.designsystem.atom.card.CardColors
import app.k9mail.core.ui.compose.designsystem.atom.card.CardOutlined
Expand Down Expand Up @@ -54,6 +55,7 @@ internal fun BannerInlineNotificationCard(
border: BorderStroke = BannerNotificationCardDefaults.errorCardBorder(),
shape: Shape = BannerNotificationCardDefaults.bannerInlineShape,
behaviour: BannerInlineNotificationCardBehaviour = BannerNotificationCardDefaults.bannerInlineBehaviour,
onSupportingTextOverflow: (hasVisualOverflow: Boolean) -> Unit = {},
) {
val maxLines = when (behaviour) {
BannerInlineNotificationCardBehaviour.Clipped -> 2
Expand All @@ -74,6 +76,11 @@ internal fun BannerInlineNotificationCard(
supportingText = supportingText,
behaviour = behaviour,
maxLines = maxLines,
onTextOverflow = { hasVisualOverflow ->
if (behaviour == BannerInlineNotificationCardBehaviour.Clipped) {
onSupportingTextOverflow(hasVisualOverflow)
}
},
)
},
actions = actions,
Expand Down Expand Up @@ -186,11 +193,12 @@ private fun BannerInlineNotificationTitle(
}

@Composable
fun BannerInlineNotificationSupportingText(
private fun BannerInlineNotificationSupportingText(
supportingText: CharSequence,
behaviour: BannerInlineNotificationCardBehaviour,
maxLines: Int,
modifier: Modifier = Modifier,
onTextOverflow: (hasVisualOverflow: Boolean) -> Unit = {},
) {
val clippedSupportingText = remember(supportingText, behaviour) {
when (behaviour) {
Expand All @@ -200,26 +208,32 @@ fun BannerInlineNotificationSupportingText(
else -> supportingText
}
}
val onTextLayout = remember<(TextLayoutResult) -> Unit>(onTextOverflow) {
{ textLayoutResult -> onTextOverflow(textLayoutResult.hasVisualOverflow) }
}
when (clippedSupportingText) {
is String -> TextBodyMedium(
text = clippedSupportingText,
maxLines = maxLines,
overflow = TextOverflow.Ellipsis,
modifier = modifier,
onTextLayout = onTextLayout,
)

is AnnotatedString -> TextBodyMedium(
text = clippedSupportingText,
maxLines = maxLines,
overflow = TextOverflow.Ellipsis,
modifier = modifier,
onTextLayout = onTextLayout,
)

else -> TextBodyMedium(
text = clippedSupportingText.toString(),
maxLines = maxLines,
overflow = TextOverflow.Ellipsis,
modifier = modifier,
onTextLayout = onTextLayout,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun ErrorBannerInlineNotificationCard(
actions: @Composable RowScope.() -> Unit,
modifier: Modifier = Modifier,
behaviour: BannerInlineNotificationCardBehaviour = BannerNotificationCardDefaults.bannerInlineBehaviour,
onSupportingTextOverflow: (hasVisualOverflow: Boolean) -> Unit = {},
) {
BannerInlineNotificationCard(
icon = { Icon(imageVector = Icons.Outlined.Report) },
Expand All @@ -35,5 +36,6 @@ fun ErrorBannerInlineNotificationCard(
behaviour = behaviour,
colors = BannerNotificationCardDefaults.errorCardColors(),
border = BannerNotificationCardDefaults.errorCardBorder(),
onSupportingTextOverflow = onSupportingTextOverflow,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun InfoBannerInlineNotificationCard(
actions: @Composable RowScope.() -> Unit,
modifier: Modifier = Modifier,
behaviour: BannerInlineNotificationCardBehaviour = BannerNotificationCardDefaults.bannerInlineBehaviour,
onSupportingTextOverflow: (hasVisualOverflow: Boolean) -> Unit = {},
) {
BannerInlineNotificationCard(
icon = { Icon(imageVector = Icons.Outlined.Info) },
Expand All @@ -35,5 +36,6 @@ fun InfoBannerInlineNotificationCard(
behaviour = behaviour,
colors = BannerNotificationCardDefaults.infoCardColors(),
border = BannerNotificationCardDefaults.infoCardBorder(),
onSupportingTextOverflow = onSupportingTextOverflow,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun SuccessBannerInlineNotificationCard(
actions: @Composable RowScope.() -> Unit,
modifier: Modifier = Modifier,
behaviour: BannerInlineNotificationCardBehaviour = BannerNotificationCardDefaults.bannerInlineBehaviour,
onSupportingTextOverflow: (hasVisualOverflow: Boolean) -> Unit = {},
) {
BannerInlineNotificationCard(
icon = { Icon(imageVector = Icons.Outlined.CheckCircle) },
Expand All @@ -35,5 +36,6 @@ fun SuccessBannerInlineNotificationCard(
behaviour = behaviour,
colors = BannerNotificationCardDefaults.successCardColors(),
border = BannerNotificationCardDefaults.successCardBorder(),
onSupportingTextOverflow = onSupportingTextOverflow,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun WarningBannerInlineNotificationCard(
actions: @Composable RowScope.() -> Unit,
modifier: Modifier = Modifier,
behaviour: BannerInlineNotificationCardBehaviour = BannerNotificationCardDefaults.bannerInlineBehaviour,
onSupportingTextOverflow: (hasVisualOverflow: Boolean) -> Unit = {},
) {
BannerInlineNotificationCard(
icon = { Icon(imageVector = Icons.Outlined.Warning) },
Expand All @@ -36,5 +37,6 @@ fun WarningBannerInlineNotificationCard(
behaviour = behaviour,
colors = BannerNotificationCardDefaults.warningCardColors(),
border = BannerNotificationCardDefaults.warningCardBorder(),
onSupportingTextOverflow = onSupportingTextOverflow,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import app.k9mail.core.ui.compose.designsystem.molecule.notification.NotificationActionButton
import app.k9mail.core.ui.compose.designsystem.organism.banner.inline.BannerInlineNotificationCardBehaviour
Expand All @@ -21,13 +23,15 @@ import net.thunderbird.feature.notification.api.ui.BannerInlineNotificationListH
import net.thunderbird.feature.notification.api.ui.BannerInlineNotificationListHostDefaults.TEST_TAG_CHECK_ERROR_NOTIFICATIONS
import net.thunderbird.feature.notification.api.ui.BannerInlineNotificationListHostDefaults.TEST_TAG_CHECK_ERROR_NOTIFICATIONS_ACTION
import net.thunderbird.feature.notification.api.ui.BannerInlineNotificationListHostDefaults.TEST_TAG_HOST_PARENT
import net.thunderbird.feature.notification.api.ui.BannerInlineNotificationListHostDefaults.TEST_TAG_LEARN_MORE_ACTION
import net.thunderbird.feature.notification.api.ui.action.NotificationAction
import net.thunderbird.feature.notification.api.ui.action.ResolvedNotificationActionButton
import net.thunderbird.feature.notification.api.ui.animation.bannerSlideInSlideOutAnimationSpec
import net.thunderbird.feature.notification.api.ui.host.InAppNotificationHostStateHolder
import net.thunderbird.feature.notification.api.ui.host.visual.BannerInlineVisual
import net.thunderbird.feature.notification.resources.api.Res
import net.thunderbird.feature.notification.resources.api.banner_inline_notification_check_error_notifications
import net.thunderbird.feature.notification.resources.api.banner_inline_notification_learn_more
import net.thunderbird.feature.notification.resources.api.banner_inline_notification_open_notifications
import net.thunderbird.feature.notification.resources.api.banner_inline_notification_some_messages_need_attention
import org.jetbrains.compose.resources.stringResource
Expand Down Expand Up @@ -105,25 +109,11 @@ private fun BannerInlineNotificationListHostLayout(
verticalArrangement = Arrangement.spacedBy(MainTheme.spacings.half),
) {
displayableNotifications.forEachIndexed { index, banner ->
ErrorBannerInlineNotificationCard(
title = banner.title,
supportingText = banner.supportingText,
actions = {
banner.actions.forEachIndexed { actionIndex, action ->
ResolvedNotificationActionButton(
action = action,
onActionClick = onActionClick,
modifier = Modifier.testTagAsResourceId(
tag = BannerInlineNotificationListHostDefaults.testTagBannerInlineListItemAction(
index = index,
actionIndex = actionIndex,
),
),
)
}
},
behaviour = BannerInlineNotificationCardBehaviour.Clipped,
modifier = Modifier.animateContentSize(),
BannerInlineItem(
index = index,
banner = banner,
onActionClick = onActionClick,
onOpenErrorNotificationsClick = onOpenErrorNotificationsClick,
)
}

Expand All @@ -150,11 +140,53 @@ private fun BannerInlineNotificationListHostLayout(
}
}

@Composable
private fun BannerInlineItem(
index: Int,
banner: BannerInlineVisual,
onActionClick: (NotificationAction) -> Unit,
onOpenErrorNotificationsClick: () -> Unit,
modifier: Modifier = Modifier,
) {
var hasSupportingTextOverflowed by remember { mutableStateOf(false) }
ErrorBannerInlineNotificationCard(
title = banner.title,
supportingText = banner.supportingText,
actions = {
if (hasSupportingTextOverflowed) {
NotificationActionButton(
text = stringResource(
resource = Res.string.banner_inline_notification_learn_more,
),
onClick = onOpenErrorNotificationsClick,
modifier = Modifier.testTagAsResourceId(TEST_TAG_LEARN_MORE_ACTION),
)
}
banner.actions.forEachIndexed { actionIndex, action ->
ResolvedNotificationActionButton(
action = action,
onActionClick = onActionClick,
modifier = Modifier.testTagAsResourceId(
tag = BannerInlineNotificationListHostDefaults.testTagBannerInlineListItemAction(
index = index,
actionIndex = actionIndex,
),
),
)
}
},
behaviour = BannerInlineNotificationCardBehaviour.Clipped,
modifier = modifier.animateContentSize(),
onSupportingTextOverflow = { hasSupportingTextOverflowed = it },
)
}

object BannerInlineNotificationListHostDefaults {
internal const val TEST_TAG_HOST_PARENT = "banner_inline_notification_host"
internal const val TEST_TAG_BANNER_INLINE_LIST = "banner_inline_notification_list"
internal const val TEST_TAG_CHECK_ERROR_NOTIFICATIONS = "check_notifications_composable"
internal const val TEST_TAG_CHECK_ERROR_NOTIFICATIONS_ACTION = "check_notifications_action"
internal const val TEST_TAG_LEARN_MORE_ACTION = "learn_more_action"

internal fun testTagBannerInlineListItemAction(index: Int, actionIndex: Int) =
"banner_inline_notification_list_item_action_${index}_$actionIndex"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
<string name="banner_inline_notification_check_error_notifications">Check Error Notifications</string>
<string name="banner_inline_notification_some_messages_need_attention">Some messages need your attention.</string>
<string name="banner_inline_notification_open_notifications">Open notifications</string>
<string name="banner_inline_notification_learn_more">Learn more</string>
<string name="banner_inline_notification_view_support_article">View support article</string>
</resources>
Loading