OXYGENHUB
# 1dfa631436b6 oxygenhub-android / app / src / main / java / io / oxygenhub / android / ui / backdrop / Scenes.kt
846 B · last changed The hub's living backgrounds in the app: the mark at sign-in, Your sky on the dashboard, live runs pulse (refs #23) 8 days ago source blame history raw
1
package io.oxygenhub.android.ui.backdrop
2
3
import io.oxygenhub.android.api.UserSky
4
import uniffi.rust_core.SkyEvent
5
import uniffi.rust_core.Backdrop as Scene
6
7
/** Your sky's events for the scene: each aged by the hub's clock, in days; malformed ones left out. */
8
fun skyEvents(sky: UserSky): List<SkyEvent> = sky.events.mapNotNull { e ->
9
    if (e.size < 4 || e[0] !in sky.repos.indices || e[1] !in 0L..4L) return@mapNotNull null
10
    SkyEvent(e[0].toUInt(), e[1].toUInt(), ((sky.now - e[2]).coerceAtLeast(0) / 86_400_000.0).toFloat(), e[3].coerceIn(1, 10_000).toUInt())
11
}
12
13
/** Your sky, as on the hub's dashboard; the quiet field when there is nothing of yours to draw. */
14
fun skyScene(sky: UserSky?, still: Boolean): Scene =
15
    if (sky == null || sky.repos.isEmpty()) Scene.adrift(still) else Scene.sky(sky.repos, skyEvents(sky), 0f, 0f, still)