-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
begin handling timeline/notification actions under kmp
- Loading branch information
Showing
17 changed files
with
174 additions
and
854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...id/shared/src/commonMain/kotlin/io/rebble/cobble/shared/domain/calendar/CalendarAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.rebble.cobble.shared.domain.calendar | ||
|
||
enum class CalendarAction { | ||
Remove, | ||
Mute, | ||
Accept, | ||
Maybe, | ||
Decline; | ||
|
||
companion object { | ||
fun fromID(id: Int): CalendarAction = entries.first {it.ordinal == id} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...ed/src/commonMain/kotlin/io/rebble/cobble/shared/domain/calendar/CalendarActionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.rebble.cobble.shared.domain.calendar | ||
|
||
import com.benasher44.uuid.Uuid | ||
import io.rebble.cobble.shared.PlatformContext | ||
import io.rebble.cobble.shared.data.calendarWatchappId | ||
import io.rebble.cobble.shared.database.NextSyncAction | ||
import io.rebble.cobble.shared.database.dao.TimelinePinDao | ||
import io.rebble.cobble.shared.domain.timeline.TimelineActionManager | ||
import io.rebble.cobble.shared.domain.timeline.WatchTimelineSyncer | ||
import io.rebble.libpebblecommon.packets.blobdb.TimelineItem | ||
import io.rebble.libpebblecommon.services.blobdb.TimelineService | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.launch | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
class CalendarActionHandler(private val scope: CoroutineScope): KoinComponent { | ||
private val platformContext: PlatformContext by inject() | ||
private val timelineActionManager: TimelineActionManager by inject() | ||
private val timelinePinDao: TimelinePinDao by inject() | ||
private val timelineSyncer: WatchTimelineSyncer by inject() | ||
|
||
private val calendarActionFlow = timelineActionManager.actionFlowForApp(calendarWatchappId) | ||
|
||
init { | ||
calendarActionFlow.onEach { | ||
val (action, deferred) = it | ||
val itemId = action.itemID.get() | ||
val response = try { | ||
when (CalendarAction.fromID(action.actionID.get().toInt())) { | ||
CalendarAction.Remove -> handleRemove(itemId) | ||
CalendarAction.Mute -> handleMute(itemId) | ||
CalendarAction.Accept -> handleAccept(itemId) | ||
CalendarAction.Maybe -> handleMaybe(itemId) | ||
CalendarAction.Decline -> handleDecline(itemId) | ||
} | ||
} catch (e: NoSuchElementException) { | ||
TimelineService.ActionResponse( | ||
success = false | ||
) | ||
} | ||
deferred.complete(response) | ||
}.launchIn(scope) | ||
} | ||
|
||
private suspend fun handleRemove(itemId: Uuid): TimelineService.ActionResponse { | ||
timelinePinDao.setSyncActionForPins(listOf(itemId), NextSyncAction.Delete) | ||
timelineSyncer.syncPinDatabaseWithWatch() | ||
|
||
return TimelineService.ActionResponse( | ||
success = true, | ||
attributes = listOf( | ||
TimelineItem.Attribute( | ||
|
||
) | ||
) | ||
) | ||
} | ||
|
||
private suspend fun handleMute(itemId: Uuid): TimelineService.ActionResponse { | ||
// Handle mute action | ||
} | ||
|
||
private suspend fun handleAccept(itemId: Uuid): TimelineService.ActionResponse { | ||
// Handle accept action | ||
} | ||
|
||
private suspend fun handleMaybe(itemId: Uuid): TimelineService.ActionResponse { | ||
// Handle maybe action | ||
} | ||
|
||
private suspend fun handleDecline(itemId: Uuid): TimelineService.ActionResponse { | ||
// Handle decline action | ||
} | ||
} |
Oops, something went wrong.