File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
src/commonMain/kotlin/io/rebble/libpebblecommon Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1+ package io.rebble.libpebblecommon.services.blobdb
2+
3+ import io.rebble.libpebblecommon.ProtocolHandler
4+ import io.rebble.libpebblecommon.packets.blobdb.TimelineAction
5+ import io.rebble.libpebblecommon.packets.blobdb.TimelineItem
6+ import io.rebble.libpebblecommon.protocolhelpers.PebblePacket
7+ import io.rebble.libpebblecommon.protocolhelpers.ProtocolEndpoint
8+ import io.rebble.libpebblecommon.services.ProtocolService
9+
10+ /* *
11+ * Singleton that handles receiving of timeline actions.
12+ *
13+ * Consumer must set [actionHandler] that will then be called whenever user triggers timeline pin
14+ * action.
15+ */
16+ class TimelineService (private val protocolHandler : ProtocolHandler ) : ProtocolService {
17+ var actionHandler: (suspend (TimelineAction .InvokeAction ) -> ActionResponse )? = null
18+
19+ init {
20+ protocolHandler.registerReceiveCallback(ProtocolEndpoint .TIMELINE_ACTIONS , this ::receive)
21+ }
22+
23+
24+ suspend fun receive (packet : PebblePacket ) {
25+ if (packet !is TimelineAction .InvokeAction ) {
26+ throw IllegalStateException (" Received invalid packet type: $packet " )
27+ }
28+
29+ val result = actionHandler?.invoke(packet) ? : return
30+
31+ val returnPacket = TimelineAction .ActionResponse ().apply {
32+ itemID.set(packet.itemID.get())
33+ response.set(if (result.success) 0u else 1u )
34+ numAttributes.set(result.attributes.size.toUByte())
35+ attributes.list = result.attributes
36+ }
37+
38+ protocolHandler.send(returnPacket)
39+ }
40+
41+ class ActionResponse (
42+ val success : Boolean ,
43+ val attributes : List <TimelineItem .Attribute > = emptyList()
44+ )
45+ }
Original file line number Diff line number Diff line change @@ -333,7 +333,6 @@ class SFixedList<T : Mappable>(
333333
334334 private val mapIndex = mapper.register(this )
335335 var list = default
336- private set
337336
338337 init {
339338 if (count != default.size) throw PacketEncodeException (" Fixed list count does not match default value count" )
You can’t perform that action at this time.
0 commit comments