Skip to content

Commit 36adb4d

Browse files
committed
update notif service to match changes
1 parent 37f0bc1 commit 36adb4d

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

src/commonMain/kotlin/io/rebble/libpebblecommon/packets/blobdb/Notification.kt

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.benasher44.uuid.uuidOf
66
import com.soywiz.klock.DateTime
77
import io.rebble.libpebblecommon.structmapper.SUInt
88
import io.rebble.libpebblecommon.structmapper.StructMapper
9+
import io.rebble.libpebblecommon.util.TimelineAttributeFactory
910
import kotlin.random.Random
1011

1112
private val notifsUUID = uuidFrom("B2CAE818-10F8-46DF-AD2B-98AD2254A3C1")
@@ -24,37 +25,20 @@ enum class NotificationSource(val id: UInt) { //TODO: There's likely more... (pr
2425
open class PushNotification(subject: String, sender: String? = null, message: String? = null, source: NotificationSource = NotificationSource.Generic, backgroundColor: UByte? = null): BlobCommand.InsertCommand(Random.nextInt(0, UShort.MAX_VALUE.toInt()).toUShort(),
2526
BlobDatabase.Notification, ubyteArrayOf(), ubyteArrayOf()) {
2627
init {
27-
val iconID = SUInt(StructMapper(), source.id or 0x80000000u).toBytes() //TODO: Work out why GB masks this, and why that makes it work
2828
val itemID = uuid4()
2929

3030
//TODO: Replies, open on phone, detect dismiss
3131
val attributes = mutableListOf(
32-
TimelineItem.Attribute(
33-
TimelineItem.Attribute.Timeline.Sender.id,
34-
sender?.encodeToByteArray()?.toUByteArray() ?: ubyteArrayOf()
35-
),
36-
TimelineItem.Attribute(
37-
TimelineItem.Attribute.Timeline.Icon.id,
38-
iconID,
39-
contentEndianness = '<'
40-
)
41-
)
42-
if (message != null) attributes += TimelineItem.Attribute(
43-
TimelineItem.Attribute.Timeline.Message.id,
44-
message.encodeToByteArray().toUByteArray()
45-
)
46-
attributes += TimelineItem.Attribute(
47-
TimelineItem.Attribute.Timeline.Subject.id,
48-
subject.encodeToByteArray().toUByteArray()
32+
TimelineAttributeFactory.sender(sender ?: ""),
33+
TimelineAttributeFactory.icon(TimelineIcon.fromId(source.id))
4934
)
35+
if (message != null) attributes += TimelineAttributeFactory.body(message)
36+
attributes += TimelineAttributeFactory.subtitle(subject)
5037

5138
if (backgroundColor != null) {
5239
// XXX: https://youtrack.jetbrains.com/issue/KT-49366
5340
val bgColTemp = backgroundColor.toUByte()
54-
attributes += TimelineItem.Attribute(
55-
TimelineItem.Attribute.Timeline.BackgroundCol.id,
56-
ubyteArrayOf(bgColTemp)
57-
)
41+
attributes += TimelineAttributeFactory.primaryColor(bgColTemp)
5842
}
5943

6044
val actions = mutableListOf(
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.rebble.libpebblecommon.util
22

3+
/**
4+
* Represents an ARGB8888 color, which is converted to an ARGB2222 color for the Pebble
5+
*/
36
data class PebbleColor(
47
val alpha: UByte,
58
val red: UByte,
@@ -8,7 +11,7 @@ data class PebbleColor(
811
)
912

1013
fun PebbleColor.toProtocolNumber() =
11-
((alpha / 85u) shl 6) or
14+
(((alpha / 85u) shl 6) or
1215
((red / 85u) shl 4) or
1316
((green / 85u) shl 2) or
14-
(blue / 85u)
17+
(blue / 85u)).toUByte()

src/commonMain/kotlin/io/rebble/libpebblecommon/util/TimelineAttributeFactory.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ object TimelineAttributeFactory {
3434
return createAttribute(type.id, content)
3535
}
3636

37-
fun title(text: String, ellipsis: Boolean = true): TimelineItem.Attribute {
37+
fun title(text: String): TimelineItem.Attribute {
3838
return createTextAttribute(TimelineAttribute.Title, text)
3939
}
4040

41-
fun subtitle(text: String, ellipsis: Boolean = true): TimelineItem.Attribute {
41+
fun subtitle(text: String): TimelineItem.Attribute {
4242
return createTextAttribute(TimelineAttribute.Subtitle, text)
4343
}
4444

45-
fun body(text: String, ellipsis: Boolean = true): TimelineItem.Attribute {
45+
fun body(text: String): TimelineItem.Attribute {
4646
return createTextAttribute(TimelineAttribute.Body, text)
4747
}
4848

@@ -150,15 +150,27 @@ object TimelineAttributeFactory {
150150
}
151151

152152
fun foregroundColor(color: PebbleColor): TimelineItem.Attribute {
153-
return createUIntAttribute(TimelineAttribute.ForegroundColor, color.toProtocolNumber())
153+
return createUByteAttribute(TimelineAttribute.ForegroundColor, color.toProtocolNumber())
154+
}
155+
156+
fun foregroundColor(rawPebbleColor: UByte): TimelineItem.Attribute {
157+
return createUByteAttribute(TimelineAttribute.ForegroundColor, rawPebbleColor)
154158
}
155159

156160
fun primaryColor(color: PebbleColor): TimelineItem.Attribute {
157-
return createUIntAttribute(TimelineAttribute.PrimaryColor, color.toProtocolNumber())
161+
return createUByteAttribute(TimelineAttribute.PrimaryColor, color.toProtocolNumber())
162+
}
163+
164+
fun primaryColor(rawPebbleColor: UByte): TimelineItem.Attribute {
165+
return createUByteAttribute(TimelineAttribute.PrimaryColor, rawPebbleColor)
158166
}
159167

160168
fun secondaryColor(color: PebbleColor): TimelineItem.Attribute {
161-
return createUIntAttribute(TimelineAttribute.SecondaryColor, color.toProtocolNumber())
169+
return createUByteAttribute(TimelineAttribute.SecondaryColor, color.toProtocolNumber())
170+
}
171+
172+
fun secondaryColor(rawPebbleColor: UInt): TimelineItem.Attribute {
173+
return createUIntAttribute(TimelineAttribute.SecondaryColor, rawPebbleColor)
162174
}
163175

164176
fun displayRecurring(recurring: Boolean): TimelineItem.Attribute {

0 commit comments

Comments
 (0)