-
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.
- Loading branch information
Showing
17 changed files
with
446 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
android/app/src/main/kotlin/io/rebble/cobble/bridges/common/KMPApiBridge.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,22 @@ | ||
package io.rebble.cobble.bridges.common | ||
|
||
import io.rebble.cobble.bridges.FlutterBridge | ||
import io.rebble.cobble.bridges.ui.BridgeLifecycleController | ||
import io.rebble.cobble.pigeons.Pigeons | ||
import io.rebble.cobble.shared.domain.state.CurrentToken | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import javax.inject.Inject | ||
|
||
class KMPApiBridge @Inject constructor( | ||
private val tokenState: MutableStateFlow<CurrentToken>, | ||
bridgeLifecycleController: BridgeLifecycleController | ||
): FlutterBridge, Pigeons.KMPApi { | ||
|
||
init { | ||
bridgeLifecycleController.setupControl(Pigeons.KMPApi::setup, this) | ||
} | ||
|
||
override fun updateToken(token: Pigeons.StringWrapper) { | ||
tokenState.value = token.value?.let { CurrentToken.LoggedIn(it) } ?: CurrentToken.LoggedOut | ||
} | ||
} |
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
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
49 changes: 49 additions & 0 deletions
49
android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/api/AppstoreClient.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,49 @@ | ||
package io.rebble.cobble.shared.api | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.request.* | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.serialization.kotlinx.json.json | ||
import io.rebble.cobble.shared.domain.api.appstore.LockerEntry | ||
|
||
class AppstoreClient( | ||
val baseUrl: String, | ||
private val token: String | ||
) { | ||
private val version = "v1" | ||
private val client = HttpClient { | ||
install(ContentNegotiation) { | ||
json() | ||
} | ||
} | ||
|
||
suspend fun getLocker(): List<LockerEntry> { | ||
val body: Map<String, List<LockerEntry>> = client.get("$baseUrl/$version/locker") { | ||
headers { | ||
append(HttpHeaders.Accept, "application/json") | ||
append(HttpHeaders.Authorization, "Bearer $token") | ||
} | ||
}.body() | ||
return body["applications"] ?: emptyList() | ||
} | ||
|
||
suspend fun addToLocker(uuid: String) { | ||
client.put("$baseUrl/$version/locker/$uuid") { | ||
headers { | ||
append(HttpHeaders.Accept, "application/json") | ||
append(HttpHeaders.Authorization, "Bearer $token") | ||
} | ||
} | ||
} | ||
|
||
suspend fun removeFromLocker(uuid: String) { | ||
client.delete("$baseUrl/$version/locker/$uuid") { | ||
headers { | ||
append(HttpHeaders.Accept, "application/json") | ||
append(HttpHeaders.Authorization, "Bearer $token") | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/api/RWS.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,22 @@ | ||
package io.rebble.cobble.shared.api | ||
|
||
import io.rebble.cobble.shared.domain.state.CurrentToken | ||
import io.rebble.cobble.shared.domain.state.CurrentToken.LoggedOut.tokenOrNull | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.* | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
import org.koin.core.qualifier.named | ||
|
||
object RWS: KoinComponent { | ||
private val domainSuffix = "rebble.io" | ||
private val token: StateFlow<CurrentToken> by inject(named("currentToken")) | ||
private val scope = CoroutineScope(Dispatchers.Default) | ||
|
||
private val _appstoreClient = token.map { | ||
it.tokenOrNull?.let { t -> AppstoreClient("https://appstore-api.$domainSuffix", t) } | ||
}.stateIn(scope, SharingStarted.Eagerly, null) | ||
val appstoreClient: AppstoreClient? | ||
get() = _appstoreClient.value | ||
} |
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
101 changes: 101 additions & 0 deletions
101
...d/shared/src/commonMain/kotlin/io/rebble/cobble/shared/domain/api/appstore/LockerEntry.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,101 @@ | ||
package io.rebble.cobble.shared.domain.api.appstore | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerialName | ||
|
||
@Serializable | ||
data class LockerEntry( | ||
val id: String, | ||
val uuid: String, | ||
@SerialName("user_token") val userToken: String, | ||
val title: String, | ||
val type: String, | ||
val category: String, | ||
val version: String? = null, | ||
val hearts: Int, | ||
@SerialName("is_configurable") val isConfigurable: Boolean, | ||
@SerialName("is_timeline_enabled") val isTimelineEnabled: Boolean, | ||
val links: LockerEntryLinks, | ||
val developer: LockerEntryDeveloper, | ||
@SerialName("hardware_platforms") val hardwarePlatforms: List<LockerEntryPlatform>, | ||
val compatibility: LockerEntryCompatibility, | ||
val companions: Map<String, LockerEntryCompanionApp?>, | ||
val pbw: LockerEntryPBW? = null | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryLinks( | ||
val remove: String, | ||
val href: String, | ||
val share: String | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryDeveloper( | ||
val id: String, | ||
val name: String, | ||
@SerialName("contact_email") val contactEmail: String | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryPlatform( | ||
@SerialName("sdk_version") val sdkVersion: String, | ||
@SerialName("pebble_process_info_flags") val pebbleProcessInfoFlags: Int, | ||
val name: String, | ||
val description: String, | ||
val images: LockerEntryPlatformImages | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryPlatformImages( | ||
val icon: String, | ||
val list: String, | ||
val screenshot: String | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryCompatibility( | ||
val ios: LockerEntryCompatibilityPhonePlatformDetails, | ||
val android: LockerEntryCompatibilityPhonePlatformDetails, | ||
val aplite: LockerEntryCompatibilityWatchPlatformDetails, | ||
val basalt: LockerEntryCompatibilityWatchPlatformDetails, | ||
val chalk: LockerEntryCompatibilityWatchPlatformDetails, | ||
val diorite: LockerEntryCompatibilityWatchPlatformDetails, | ||
val emery: LockerEntryCompatibilityWatchPlatformDetails | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryCompatibilityPhonePlatformDetails( | ||
val supported: Boolean, | ||
@SerialName("min_js_version") val minJsVersion: Int? = null | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryCompatibilityWatchPlatformDetails( | ||
val supported: Boolean, | ||
val firmware: LockerEntryFirmwareVersion | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryFirmwareVersion( | ||
val major: Int, | ||
val minor: Int? = null, | ||
val patch: Int? = null | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryCompanionApp( | ||
val id: Int, | ||
val icon: String, | ||
val name: String, | ||
val url: String, | ||
val required: Boolean, | ||
@SerialName("pebblekit_version") val pebblekitVersion: String | ||
) | ||
|
||
@Serializable | ||
data class LockerEntryPBW( | ||
val file: String, | ||
@SerialName("icon_resource_id") val iconResourceId: Int, | ||
@SerialName("release_id") val releaseId: String | ||
) |
12 changes: 12 additions & 0 deletions
12
android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/domain/state/CurrentToken.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,12 @@ | ||
package io.rebble.cobble.shared.domain.state | ||
|
||
open class CurrentToken { | ||
object LoggedOut : CurrentToken() | ||
data class LoggedIn(val token: String) : CurrentToken() | ||
|
||
val CurrentToken.tokenOrNull: String? | ||
get() = when (this) { | ||
is LoggedIn -> token | ||
else -> null | ||
} | ||
} |
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
Oops, something went wrong.