Loading feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/content/AppNotification.kt +15 −2 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ import net.thunderbird.feature.notification.api.NotificationGroup import net.thunderbird.feature.notification.api.NotificationSeverity import net.thunderbird.feature.notification.api.ui.action.NotificationAction import net.thunderbird.feature.notification.api.ui.icon.NotificationIcon import net.thunderbird.feature.notification.api.ui.style.InAppNotificationStyle import net.thunderbird.feature.notification.api.ui.style.SystemNotificationStyle /** * Represents a notification that can be displayed to the user. Loading Loading @@ -62,12 +64,17 @@ sealed class AppNotification : Notification { * @property subText Additional text displayed below the content text, can be null. * @property channel The notification channel to which this notification belongs. * @property group The notification group to which this notification belongs, can be null. * @property systemNotificationStyle The style of the system notification. * Defaults to [SystemNotificationStyle.Undefined]. * @see LockscreenNotificationAppearance * @see SystemNotificationStyle * @see net.thunderbird.feature.notification.api.ui.style.systemNotificationStyle */ sealed interface SystemNotification : Notification { val subText: String? get() = null val channel: NotificationChannel val group: NotificationGroup? get() = null val systemNotificationStyle: SystemNotificationStyle get() = SystemNotificationStyle.Undefined /** * Converts this notification to a [LockscreenNotification]. Loading Loading @@ -95,10 +102,16 @@ sealed interface SystemNotification : Notification { } /** * * Represents a notification displayed within the application. * * In-app notifications are typically less intrusive than system notifications and **do not require** * system notification permissions to be displayed. * * @property inAppNotificationStyle The style of the in-app notification. * Defaults to [InAppNotificationStyle.Undefined]. * @see InAppNotificationStyle * @see net.thunderbird.feature.notification.api.ui.style.inAppNotificationStyle */ sealed interface InAppNotification : Notification sealed interface InAppNotification : Notification { val inAppNotificationStyle: InAppNotificationStyle get() = InAppNotificationStyle.Undefined } feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/content/MailNotification.kt +6 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ import net.thunderbird.feature.notification.api.ui.icon.NewMailSingleMail import net.thunderbird.feature.notification.api.ui.icon.NewMailSummaryMail import net.thunderbird.feature.notification.api.ui.icon.NotificationIcon import net.thunderbird.feature.notification.api.ui.icon.NotificationIcons import net.thunderbird.feature.notification.api.ui.style.SystemNotificationStyle import net.thunderbird.feature.notification.api.ui.style.systemNotificationStyle import net.thunderbird.feature.notification.resources.api.Res import net.thunderbird.feature.notification.resources.api.notification_additional_messages import net.thunderbird.feature.notification.resources.api.notification_bg_send_ticker Loading Loading @@ -126,6 +128,7 @@ sealed class MailNotification : AppNotification(), SystemNotification { SystemNotification.LockscreenNotification( notification = copy(contentText = null), ) override val actions: Set<NotificationAction> = setOf(NotificationAction.Retry) companion object { Loading Loading @@ -188,6 +191,9 @@ sealed class MailNotification : AppNotification(), SystemNotification { NotificationAction.Archive, NotificationAction.MarkAsSpam, ) override val systemNotificationStyle: SystemNotificationStyle = systemNotificationStyle { bigText(preview) } } /** Loading feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/InAppNotificationStyle.kt 0 → 100644 +78 −0 Original line number Diff line number Diff line package net.thunderbird.feature.notification.api.ui.style import net.thunderbird.feature.notification.api.ui.style.builder.InAppNotificationStyleBuilder /** * Represents the style of an in-app notification. * * In-app notifications are displayed within the application itself to provide immediate * feedback or information. * * TODO(#9312): The subtypes of [InAppNotificationStyle] Style might change after designer's feedback. */ enum class InAppNotificationStyle { /** * Represents an undefined in-app notification style. * This can be used as a default or placeholder when no specific style is applicable. */ Undefined, /** * Represents a fatal error notification that cannot be dismissed by the user. * * This type of notification typically indicates a fatal issue that requires user attention * and prevents normal operation of the application. */ Fatal, /** * Represents a critical in-app notification style. * * This style is used for important messages that require user attention but do not * necessarily halt the application's functionality like a [Fatal] error. */ Critical, /** * Represents a temporary in-app notification style. * * This style is typically used for notifications that are displayed briefly and then dismissed * automatically or by user interaction. */ Temporary, /** * Represents a general warning notification. */ Warning, /** * Represents an in-app notification that displays general information. * * This style is typically used for notifications that convey important updates or messages * that don't fit into more specific categories like errors or successes. */ Information, } /** * Configures the in-app notification style. * * @param builder A lambda function with [InAppNotificationStyleBuilder] as its receiver, * used to configure the system notification style. * * Example: * ``` * inAppNotificationStyle { * severity(NotificationSeverity.Fatal) * } * ``` * * TODO(#9312): The subtypes of [InAppNotificationStyle] Style might change after designer's feedback. */ @NotificationStyleMarker fun inAppNotificationStyle( builder: @NotificationStyleMarker InAppNotificationStyleBuilder.() -> Unit, ): InAppNotificationStyle { return InAppNotificationStyleBuilder().apply(builder).build() } feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/NotificationStyleMarker.kt 0 → 100644 +29 −0 Original line number Diff line number Diff line package net.thunderbird.feature.notification.api.ui.style /** * A DSL marker for building notification styles. * * This annotation is used to restrict the scope of lambda receivers, ensuring that * methods belonging to an outer scope cannot be called from an inner scope. * This helps in creating a more structured and type-safe DSL for constructing * different notification styles. * * Example: * ``` * // OK: * val systemStyle = systemNotificationStyle { * bigText("This is a big text notification.") * } * * // Compile error: * val systemStyle = systemNotificationStyle { * inbox { * // bigText must be called within systemNotificationStyle and not within inbox configuration. * bigText("This is a big text notification.") * } * } * ``` */ @DslMarker @Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION) internal annotation class NotificationStyleMarker feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/SystemNotificationStyle.kt 0 → 100644 +61 −0 Original line number Diff line number Diff line package net.thunderbird.feature.notification.api.ui.style import net.thunderbird.feature.notification.api.ui.style.builder.SystemNotificationStyleBuilder import org.jetbrains.annotations.VisibleForTesting /** * Represents the style of a system notification. */ sealed interface SystemNotificationStyle { /** * Represents an undefined notification style. * This can be used as a default or placeholder when no specific style is applicable. */ data object Undefined : SystemNotificationStyle /** * Style for large-format notifications that include a lot of text. * * @property text The main text content of the notification. */ data class BigTextStyle @VisibleForTesting constructor( val text: String, ) : SystemNotificationStyle /** * Style for large-format notifications that include a list of (up to 5) strings. * * @property bigContentTitle Overrides the title of the notification. * @property summary Overrides the summary of the notification. * @property lines List of strings to display in the notification. */ data class InboxStyle @VisibleForTesting constructor( val bigContentTitle: String, val summary: String, val lines: List<CharSequence>, ) : SystemNotificationStyle } /** * Configures the system notification style. * * @param builder A lambda function with [SystemNotificationStyleBuilder] as its receiver, * used to configure the system notification style. * * Example: * ``` * systemNotificationStyle { * bigText("This is a big text notification.") * // or * inbox { * // Add more inbox style configurations here * } * } * ``` */ @NotificationStyleMarker fun systemNotificationStyle( builder: @NotificationStyleMarker SystemNotificationStyleBuilder.() -> Unit, ): SystemNotificationStyle { return SystemNotificationStyleBuilder().apply(builder).build() } Loading
feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/content/AppNotification.kt +15 −2 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ import net.thunderbird.feature.notification.api.NotificationGroup import net.thunderbird.feature.notification.api.NotificationSeverity import net.thunderbird.feature.notification.api.ui.action.NotificationAction import net.thunderbird.feature.notification.api.ui.icon.NotificationIcon import net.thunderbird.feature.notification.api.ui.style.InAppNotificationStyle import net.thunderbird.feature.notification.api.ui.style.SystemNotificationStyle /** * Represents a notification that can be displayed to the user. Loading Loading @@ -62,12 +64,17 @@ sealed class AppNotification : Notification { * @property subText Additional text displayed below the content text, can be null. * @property channel The notification channel to which this notification belongs. * @property group The notification group to which this notification belongs, can be null. * @property systemNotificationStyle The style of the system notification. * Defaults to [SystemNotificationStyle.Undefined]. * @see LockscreenNotificationAppearance * @see SystemNotificationStyle * @see net.thunderbird.feature.notification.api.ui.style.systemNotificationStyle */ sealed interface SystemNotification : Notification { val subText: String? get() = null val channel: NotificationChannel val group: NotificationGroup? get() = null val systemNotificationStyle: SystemNotificationStyle get() = SystemNotificationStyle.Undefined /** * Converts this notification to a [LockscreenNotification]. Loading Loading @@ -95,10 +102,16 @@ sealed interface SystemNotification : Notification { } /** * * Represents a notification displayed within the application. * * In-app notifications are typically less intrusive than system notifications and **do not require** * system notification permissions to be displayed. * * @property inAppNotificationStyle The style of the in-app notification. * Defaults to [InAppNotificationStyle.Undefined]. * @see InAppNotificationStyle * @see net.thunderbird.feature.notification.api.ui.style.inAppNotificationStyle */ sealed interface InAppNotification : Notification sealed interface InAppNotification : Notification { val inAppNotificationStyle: InAppNotificationStyle get() = InAppNotificationStyle.Undefined }
feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/content/MailNotification.kt +6 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ import net.thunderbird.feature.notification.api.ui.icon.NewMailSingleMail import net.thunderbird.feature.notification.api.ui.icon.NewMailSummaryMail import net.thunderbird.feature.notification.api.ui.icon.NotificationIcon import net.thunderbird.feature.notification.api.ui.icon.NotificationIcons import net.thunderbird.feature.notification.api.ui.style.SystemNotificationStyle import net.thunderbird.feature.notification.api.ui.style.systemNotificationStyle import net.thunderbird.feature.notification.resources.api.Res import net.thunderbird.feature.notification.resources.api.notification_additional_messages import net.thunderbird.feature.notification.resources.api.notification_bg_send_ticker Loading Loading @@ -126,6 +128,7 @@ sealed class MailNotification : AppNotification(), SystemNotification { SystemNotification.LockscreenNotification( notification = copy(contentText = null), ) override val actions: Set<NotificationAction> = setOf(NotificationAction.Retry) companion object { Loading Loading @@ -188,6 +191,9 @@ sealed class MailNotification : AppNotification(), SystemNotification { NotificationAction.Archive, NotificationAction.MarkAsSpam, ) override val systemNotificationStyle: SystemNotificationStyle = systemNotificationStyle { bigText(preview) } } /** Loading
feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/InAppNotificationStyle.kt 0 → 100644 +78 −0 Original line number Diff line number Diff line package net.thunderbird.feature.notification.api.ui.style import net.thunderbird.feature.notification.api.ui.style.builder.InAppNotificationStyleBuilder /** * Represents the style of an in-app notification. * * In-app notifications are displayed within the application itself to provide immediate * feedback or information. * * TODO(#9312): The subtypes of [InAppNotificationStyle] Style might change after designer's feedback. */ enum class InAppNotificationStyle { /** * Represents an undefined in-app notification style. * This can be used as a default or placeholder when no specific style is applicable. */ Undefined, /** * Represents a fatal error notification that cannot be dismissed by the user. * * This type of notification typically indicates a fatal issue that requires user attention * and prevents normal operation of the application. */ Fatal, /** * Represents a critical in-app notification style. * * This style is used for important messages that require user attention but do not * necessarily halt the application's functionality like a [Fatal] error. */ Critical, /** * Represents a temporary in-app notification style. * * This style is typically used for notifications that are displayed briefly and then dismissed * automatically or by user interaction. */ Temporary, /** * Represents a general warning notification. */ Warning, /** * Represents an in-app notification that displays general information. * * This style is typically used for notifications that convey important updates or messages * that don't fit into more specific categories like errors or successes. */ Information, } /** * Configures the in-app notification style. * * @param builder A lambda function with [InAppNotificationStyleBuilder] as its receiver, * used to configure the system notification style. * * Example: * ``` * inAppNotificationStyle { * severity(NotificationSeverity.Fatal) * } * ``` * * TODO(#9312): The subtypes of [InAppNotificationStyle] Style might change after designer's feedback. */ @NotificationStyleMarker fun inAppNotificationStyle( builder: @NotificationStyleMarker InAppNotificationStyleBuilder.() -> Unit, ): InAppNotificationStyle { return InAppNotificationStyleBuilder().apply(builder).build() }
feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/NotificationStyleMarker.kt 0 → 100644 +29 −0 Original line number Diff line number Diff line package net.thunderbird.feature.notification.api.ui.style /** * A DSL marker for building notification styles. * * This annotation is used to restrict the scope of lambda receivers, ensuring that * methods belonging to an outer scope cannot be called from an inner scope. * This helps in creating a more structured and type-safe DSL for constructing * different notification styles. * * Example: * ``` * // OK: * val systemStyle = systemNotificationStyle { * bigText("This is a big text notification.") * } * * // Compile error: * val systemStyle = systemNotificationStyle { * inbox { * // bigText must be called within systemNotificationStyle and not within inbox configuration. * bigText("This is a big text notification.") * } * } * ``` */ @DslMarker @Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION) internal annotation class NotificationStyleMarker
feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/SystemNotificationStyle.kt 0 → 100644 +61 −0 Original line number Diff line number Diff line package net.thunderbird.feature.notification.api.ui.style import net.thunderbird.feature.notification.api.ui.style.builder.SystemNotificationStyleBuilder import org.jetbrains.annotations.VisibleForTesting /** * Represents the style of a system notification. */ sealed interface SystemNotificationStyle { /** * Represents an undefined notification style. * This can be used as a default or placeholder when no specific style is applicable. */ data object Undefined : SystemNotificationStyle /** * Style for large-format notifications that include a lot of text. * * @property text The main text content of the notification. */ data class BigTextStyle @VisibleForTesting constructor( val text: String, ) : SystemNotificationStyle /** * Style for large-format notifications that include a list of (up to 5) strings. * * @property bigContentTitle Overrides the title of the notification. * @property summary Overrides the summary of the notification. * @property lines List of strings to display in the notification. */ data class InboxStyle @VisibleForTesting constructor( val bigContentTitle: String, val summary: String, val lines: List<CharSequence>, ) : SystemNotificationStyle } /** * Configures the system notification style. * * @param builder A lambda function with [SystemNotificationStyleBuilder] as its receiver, * used to configure the system notification style. * * Example: * ``` * systemNotificationStyle { * bigText("This is a big text notification.") * // or * inbox { * // Add more inbox style configurations here * } * } * ``` */ @NotificationStyleMarker fun systemNotificationStyle( builder: @NotificationStyleMarker SystemNotificationStyleBuilder.() -> Unit, ): SystemNotificationStyle { return SystemNotificationStyleBuilder().apply(builder).build() }