Skip to content

Commit 5e4f783

Browse files
committed
feat(in-app-styles): add NotificationPriority value type
1 parent 4c4025f commit 5e4f783

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/InAppNotificationStyle.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sealed interface InAppNotificationStyle {
2424
* @see InAppNotificationStyleBuilder.bannerGlobal
2525
*/
2626
data class BannerGlobalNotification(
27-
val priority: Int,
27+
val priority: NotificationPriority,
2828
) : InAppNotificationStyle
2929

3030
/**
@@ -42,6 +42,16 @@ sealed interface InAppNotificationStyle {
4242

4343
enum class SnackbarDuration { Short, Long, Indefinite }
4444

45+
@JvmInline
46+
value class NotificationPriority(val value: UInt) : Comparable<NotificationPriority> {
47+
override fun compareTo(other: NotificationPriority): Int = value.compareTo(other.value)
48+
49+
companion object {
50+
val Min = NotificationPriority(UInt.MIN_VALUE)
51+
val Max = NotificationPriority(UInt.MAX_VALUE)
52+
}
53+
}
54+
4555
/**
4656
* Configures the in-app notification style.
4757
*

feature/notification/api/src/commonMain/kotlin/net/thunderbird/feature/notification/api/ui/style/builder/InAppNotificationStyleBuilder.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import net.thunderbird.feature.notification.api.ui.style.InAppNotificationStyle.
55
import net.thunderbird.feature.notification.api.ui.style.InAppNotificationStyle.BannerInlineNotification
66
import net.thunderbird.feature.notification.api.ui.style.InAppNotificationStyle.DialogNotification
77
import net.thunderbird.feature.notification.api.ui.style.InAppNotificationStyle.SnackbarNotification
8+
import net.thunderbird.feature.notification.api.ui.style.NotificationPriority
89
import net.thunderbird.feature.notification.api.ui.style.NotificationStyleMarker
910
import net.thunderbird.feature.notification.api.ui.style.SnackbarDuration
1011

@@ -67,7 +68,7 @@ class InAppNotificationStyleBuilder internal constructor() {
6768
* a [DialogNotification] in these cases)
6869
*/
6970
@NotificationStyleMarker
70-
fun bannerGlobal(priority: Int = 0) {
71+
fun bannerGlobal(priority: NotificationPriority = NotificationPriority.Min) {
7172
checkSingleStyleEntry<BannerGlobalNotification>()
7273
style = BannerGlobalNotification(priority = priority)
7374
}

feature/notification/api/src/commonTest/kotlin/net/thunderbird/feature/notification/api/ui/style/InAppNotificationStyleTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class InAppNotificationStyleTest {
2424
@Test
2525
fun `inAppNotificationStyle dsl should create a banner global in-app notification style`() {
2626
// Arrange
27-
val expectedStyle = InAppNotificationStyle.BannerGlobalNotification(priority = 0)
27+
val priority = NotificationPriority(1u)
28+
val expectedStyle = InAppNotificationStyle.BannerGlobalNotification(priority = priority)
2829

2930
// Act
30-
val inAppStyle = inAppNotificationStyle { bannerGlobal() }
31+
val inAppStyle = inAppNotificationStyle { bannerGlobal(priority = priority) }
3132

3233
// Assert
3334
assertThat(inAppStyle).isEqualTo(expectedStyle)

0 commit comments

Comments
 (0)