-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable conferences desktop app with firebase * Include runtime dependencies * Apply title to window * Apply lint style fixes --------- Co-authored-by: Ashley Davies <[email protected]>
- Loading branch information
Showing
12 changed files
with
204 additions
and
42 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
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
111 changes: 111 additions & 0 deletions
111
conferences-app/src/jvmMain/kotlin/io/ashdavies/party/Main.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,111 @@ | ||
package io.ashdavies.party | ||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.window.Window | ||
import androidx.compose.ui.window.application | ||
import com.slack.circuit.backstack.rememberSaveableBackStack | ||
import com.slack.circuit.foundation.CircuitCompositionLocals | ||
import com.slack.circuit.foundation.NavigableCircuitContent | ||
import com.slack.circuit.foundation.rememberCircuitNavigator | ||
import com.slack.circuit.overlay.ContentWithOverlays | ||
import io.ashdavies.analytics.LocalAnalytics | ||
import io.ashdavies.analytics.RemoteAnalytics | ||
import io.ashdavies.check.ProvideAppCheckToken | ||
import io.ashdavies.config.LocalConfigValue | ||
import io.ashdavies.config.LocalRemoteConfig | ||
import io.ashdavies.config.RemoteConfig | ||
import io.ashdavies.content.PlatformContext | ||
import io.ashdavies.http.ProvideHttpClient | ||
import io.ashdavies.http.publicStorage | ||
import io.ashdavies.io.resolveCacheDir | ||
import io.ashdavies.material.dynamicColorScheme | ||
import io.ashdavies.party.config.rememberCircuit | ||
import io.ashdavies.party.firebase.EmptyLocalConfigValue | ||
import io.ashdavies.party.home.HomeScreen | ||
import io.ashdavies.playground.BuildConfig | ||
import io.ashdavies.playground.KeyNavigationDecoration | ||
import io.ashdavies.playground.PlaygroundDatabase | ||
import io.ashdavies.sql.ProvideTransacter | ||
import io.ashdavies.sql.rememberTransacter | ||
import io.ktor.client.plugins.DefaultRequest | ||
import io.ktor.client.plugins.cache.HttpCache | ||
import io.ktor.client.request.header | ||
|
||
public fun main() { | ||
application { | ||
Window( | ||
onCloseRequest = ::exitApplication, | ||
title = "Conferences", | ||
) { | ||
ConferencesApp( | ||
context = PlatformContext.Default, | ||
onClose = ::exitApplication, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ConferencesApp( | ||
context: PlatformContext, | ||
onClose: () -> Unit, | ||
) { | ||
ProvideHttpClient( | ||
config = { | ||
install(DefaultRequest) { | ||
header("User-Agent", System.getProperty("os.name")) | ||
header("X-API-Key", BuildConfig.BROWSER_API_KEY) | ||
} | ||
|
||
install(HttpCache) { | ||
publicStorage(context.resolveCacheDir()) | ||
} | ||
}, | ||
) { | ||
ProvideRemoteLocals { | ||
ProvideAppCheckToken { | ||
val transacter = rememberTransacter( | ||
schema = PlaygroundDatabase.Schema, | ||
context = context, | ||
) { PlaygroundDatabase(it) } | ||
|
||
ProvideTransacter(transacter) { | ||
MaterialTheme(dynamicColorScheme()) { | ||
val circuit = rememberCircuit(context) | ||
|
||
CircuitCompositionLocals(circuit) { | ||
ContentWithOverlays { | ||
val backStack = rememberSaveableBackStack(HomeScreen) | ||
|
||
NavigableCircuitContent( | ||
navigator = rememberCircuitNavigator(backStack) { onClose() }, | ||
backStack = backStack, | ||
decoration = KeyNavigationDecoration( | ||
decoration = circuit.defaultNavDecoration, | ||
onBackInvoked = backStack::pop, | ||
), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ProvideRemoteLocals(content: @Composable () -> Unit) { | ||
CompositionLocalProvider( | ||
LocalAnalytics provides RemoteAnalytics { _, _ -> }, | ||
LocalRemoteConfig provides object : RemoteConfig { | ||
override suspend fun <T : Any> getValue( | ||
key: String, | ||
transform: (LocalConfigValue) -> T, | ||
): T = transform(EmptyLocalConfigValue) | ||
}, | ||
content = content, | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
conferences-app/src/jvmMain/kotlin/io/ashdavies/party/firebase/EmptyLocalConfigValue.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,11 @@ | ||
package io.ashdavies.party.firebase | ||
|
||
import io.ashdavies.config.LocalConfigValue | ||
|
||
internal object EmptyLocalConfigValue : LocalConfigValue { | ||
override fun asLong() = 0L | ||
override fun asDouble() = 0.0 | ||
override fun asString() = "" | ||
override fun asByteArray() = byteArrayOf() | ||
override fun asBoolean() = false | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
plugins { | ||
id("io.ashdavies.compose") | ||
id("io.ashdavies.default") | ||
} | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
remote-config/src/commonMain/kotlin/io/ashdavies/config/LazyRemoteConfig.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,19 @@ | ||
package io.ashdavies.config | ||
|
||
import dev.gitlive.firebase.Firebase | ||
import dev.gitlive.firebase.remoteconfig.FirebaseRemoteConfig | ||
import dev.gitlive.firebase.remoteconfig.FirebaseRemoteConfigValue | ||
import dev.gitlive.firebase.remoteconfig.remoteConfig | ||
|
||
private val FirebaseRemoteConfig by lazy { Firebase.remoteConfig } | ||
|
||
internal class LazyRemoteConfig : RemoteConfig { | ||
override suspend fun <T : Any> getValue(key: String, transform: (LocalConfigValue) -> T): T { | ||
return transform(LocalConfigValue(FirebaseRemoteConfig.getInitializedValue(key))) | ||
} | ||
} | ||
|
||
private suspend fun FirebaseRemoteConfig.getInitializedValue(key: String): FirebaseRemoteConfigValue { | ||
ensureInitialized() | ||
return getValue(key) | ||
} |
21 changes: 21 additions & 0 deletions
21
remote-config/src/commonMain/kotlin/io/ashdavies/config/LocalConfigValue.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,21 @@ | ||
package io.ashdavies.config | ||
|
||
import dev.gitlive.firebase.remoteconfig.FirebaseRemoteConfigValue | ||
|
||
public interface LocalConfigValue { | ||
public fun asLong(): Long | ||
public fun asDouble(): Double | ||
public fun asString(): String | ||
public fun asByteArray(): ByteArray | ||
public fun asBoolean(): Boolean | ||
} | ||
|
||
internal fun LocalConfigValue(value: FirebaseRemoteConfigValue): LocalConfigValue { | ||
return object : LocalConfigValue { | ||
override fun asLong(): Long = value.asLong() | ||
override fun asDouble(): Double = value.asDouble() | ||
override fun asString(): String = value.asString() | ||
override fun asByteArray(): ByteArray = value.asByteArray() | ||
override fun asBoolean(): Boolean = value.asBoolean() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
remote-config/src/commonMain/kotlin/io/ashdavies/config/LocalRemoteConfig.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,8 @@ | ||
package io.ashdavies.config | ||
|
||
import androidx.compose.runtime.ProvidableCompositionLocal | ||
import androidx.compose.runtime.staticCompositionLocalOf | ||
|
||
public val LocalRemoteConfig: ProvidableCompositionLocal<RemoteConfig> = staticCompositionLocalOf { | ||
LazyRemoteConfig() | ||
} |
37 changes: 1 addition & 36 deletions
37
remote-config/src/commonMain/kotlin/io/ashdavies/config/RemoteConfig.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