Skip to content

Commit

Permalink
update notif service to match changes
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Jul 10, 2024
1 parent 37f0bc1 commit 36adb4d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.benasher44.uuid.uuidOf
import com.soywiz.klock.DateTime
import io.rebble.libpebblecommon.structmapper.SUInt
import io.rebble.libpebblecommon.structmapper.StructMapper
import io.rebble.libpebblecommon.util.TimelineAttributeFactory
import kotlin.random.Random

private val notifsUUID = uuidFrom("B2CAE818-10F8-46DF-AD2B-98AD2254A3C1")
Expand All @@ -24,37 +25,20 @@ enum class NotificationSource(val id: UInt) { //TODO: There's likely more... (pr
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(),
BlobDatabase.Notification, ubyteArrayOf(), ubyteArrayOf()) {
init {
val iconID = SUInt(StructMapper(), source.id or 0x80000000u).toBytes() //TODO: Work out why GB masks this, and why that makes it work
val itemID = uuid4()

//TODO: Replies, open on phone, detect dismiss
val attributes = mutableListOf(
TimelineItem.Attribute(
TimelineItem.Attribute.Timeline.Sender.id,
sender?.encodeToByteArray()?.toUByteArray() ?: ubyteArrayOf()
),
TimelineItem.Attribute(
TimelineItem.Attribute.Timeline.Icon.id,
iconID,
contentEndianness = '<'
)
)
if (message != null) attributes += TimelineItem.Attribute(
TimelineItem.Attribute.Timeline.Message.id,
message.encodeToByteArray().toUByteArray()
)
attributes += TimelineItem.Attribute(
TimelineItem.Attribute.Timeline.Subject.id,
subject.encodeToByteArray().toUByteArray()
TimelineAttributeFactory.sender(sender ?: ""),
TimelineAttributeFactory.icon(TimelineIcon.fromId(source.id))
)
if (message != null) attributes += TimelineAttributeFactory.body(message)
attributes += TimelineAttributeFactory.subtitle(subject)

if (backgroundColor != null) {
// XXX: https://youtrack.jetbrains.com/issue/KT-49366
val bgColTemp = backgroundColor.toUByte()
attributes += TimelineItem.Attribute(
TimelineItem.Attribute.Timeline.BackgroundCol.id,
ubyteArrayOf(bgColTemp)
)
attributes += TimelineAttributeFactory.primaryColor(bgColTemp)
}

val actions = mutableListOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.rebble.libpebblecommon.util

/**
* Represents an ARGB8888 color, which is converted to an ARGB2222 color for the Pebble
*/
data class PebbleColor(
val alpha: UByte,
val red: UByte,
Expand All @@ -8,7 +11,7 @@ data class PebbleColor(
)

fun PebbleColor.toProtocolNumber() =
((alpha / 85u) shl 6) or
(((alpha / 85u) shl 6) or
((red / 85u) shl 4) or
((green / 85u) shl 2) or
(blue / 85u)
(blue / 85u)).toUByte()
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ object TimelineAttributeFactory {
return createAttribute(type.id, content)
}

fun title(text: String, ellipsis: Boolean = true): TimelineItem.Attribute {
fun title(text: String): TimelineItem.Attribute {
return createTextAttribute(TimelineAttribute.Title, text)
}

fun subtitle(text: String, ellipsis: Boolean = true): TimelineItem.Attribute {
fun subtitle(text: String): TimelineItem.Attribute {
return createTextAttribute(TimelineAttribute.Subtitle, text)
}

fun body(text: String, ellipsis: Boolean = true): TimelineItem.Attribute {
fun body(text: String): TimelineItem.Attribute {
return createTextAttribute(TimelineAttribute.Body, text)
}

Expand Down Expand Up @@ -150,15 +150,27 @@ object TimelineAttributeFactory {
}

fun foregroundColor(color: PebbleColor): TimelineItem.Attribute {
return createUIntAttribute(TimelineAttribute.ForegroundColor, color.toProtocolNumber())
return createUByteAttribute(TimelineAttribute.ForegroundColor, color.toProtocolNumber())
}

fun foregroundColor(rawPebbleColor: UByte): TimelineItem.Attribute {
return createUByteAttribute(TimelineAttribute.ForegroundColor, rawPebbleColor)
}

fun primaryColor(color: PebbleColor): TimelineItem.Attribute {
return createUIntAttribute(TimelineAttribute.PrimaryColor, color.toProtocolNumber())
return createUByteAttribute(TimelineAttribute.PrimaryColor, color.toProtocolNumber())
}

fun primaryColor(rawPebbleColor: UByte): TimelineItem.Attribute {
return createUByteAttribute(TimelineAttribute.PrimaryColor, rawPebbleColor)
}

fun secondaryColor(color: PebbleColor): TimelineItem.Attribute {
return createUIntAttribute(TimelineAttribute.SecondaryColor, color.toProtocolNumber())
return createUByteAttribute(TimelineAttribute.SecondaryColor, color.toProtocolNumber())
}

fun secondaryColor(rawPebbleColor: UInt): TimelineItem.Attribute {
return createUIntAttribute(TimelineAttribute.SecondaryColor, rawPebbleColor)
}

fun displayRecurring(recurring: Boolean): TimelineItem.Attribute {
Expand Down

0 comments on commit 36adb4d

Please sign in to comment.