Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ androidx-credentials = "1.5.0"
androidx-datastore = "1.2.0"
androidx-lifecycle = "2.8.7" # Used by the Wear OS app only
androidx-wear-compose = "1.4.1"
apollo = "4.1.1"
apollo-adapters = "0.0.4"
apollo = "4.4.2"
apollo-adapters = "0.7.0"
apollo-cache = "1.0.0"
coil = "3.1.0"
compose = "1.7.8" # Used by the Wear OS app only
crashlytics-plugin = "3.0.6"
Expand Down Expand Up @@ -50,8 +51,7 @@ androidx-datastore-preferences = { module = "androidx.datastore:datastore-prefer
androidx-datastore-preferences-core = { module = "androidx.datastore:datastore-preferences-core", version.ref = "androidx-datastore" }
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
apollo-adapters-kotlinx-datetime = { module = "com.apollographql.adapters:apollo-adapters-kotlinx-datetime", version.ref = "apollo-adapters" }
apollo-normalized-cache = { module = "com.apollographql.apollo:apollo-normalized-cache", version.ref = "apollo" }
apollo-normalized-cache-sqlite = { module = "com.apollographql.apollo:apollo-normalized-cache-sqlite", version.ref = "apollo" }
apollo-normalized-cache-sqlite = { module = "com.apollographql.cache:normalized-cache-sqlite", version.ref = "apollo-cache" }
apollo-runtime = { module = "com.apollographql.apollo:apollo-runtime", version.ref = "apollo" }
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" }
Expand Down
9 changes: 8 additions & 1 deletion shared/data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.apollographql.apollo.annotations.ApolloExperimental

plugins {
alias(libs.plugins.androidmakers.kmp.library)
alias(libs.plugins.apollo)
Expand All @@ -19,7 +21,6 @@ kotlin {
api(libs.apollo.runtime)
implementation(libs.apollo.adapters.kotlinx.datetime)
implementation(libs.apollo.normalized.cache.sqlite)
implementation(libs.apollo.normalized.cache)

api(libs.androidx.datastore.preferences)
api(libs.androidx.datastore.preferences.core)
Expand Down Expand Up @@ -47,9 +48,15 @@ kotlin {
apollo {
service("service") {
packageName.set("fr.androidmakers.store.graphql")
@OptIn(ApolloExperimental::class)
generateDataBuilders.set(true)
mapScalar("GraphQLLocalDateTime", "kotlinx.datetime.LocalDateTime", "com.apollographql.adapter.datetime.KotlinxLocalDateTimeAdapter")

@OptIn(ApolloExperimental::class)
plugin("com.apollographql.cache:normalized-cache-apollo-compiler-plugin:${libs.versions.apollo.cache.get()}") {
argument("com.apollographql.cache.packageName", packageName.get())
}

introspection {
schemaFile.set(file("src/commonMain/graphql/schema.graphqls"))
endpointUrl.set("https://androidmakers.fr/graphql")
Expand Down
3 changes: 2 additions & 1 deletion shared/data/src/commonMain/graphql/extra.graphqls
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# noinspection GraphQLUnresolvedReference,GraphQLMissingType
extend schema
@link(url: "https://specs.apollo.dev/cache/v0.4", import: ["@typePolicy", "@fieldPolicy"])

extend type Room @typePolicy(keyFields: "id")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ package fr.androidmakers.store.graphql
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.api.http.HttpRequest
import com.apollographql.apollo.api.http.HttpResponse
import com.apollographql.apollo.cache.normalized.api.MemoryCacheFactory
import com.apollographql.apollo.cache.normalized.normalizedCache
import com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.apollo.network.http.HttpInterceptor
import com.apollographql.apollo.network.http.HttpInterceptorChain
import com.apollographql.cache.normalized.api.NormalizedCacheFactory
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
import fr.androidmakers.domain.repo.UserRepository
import fr.androidmakers.store.graphql.cache.Cache.cache

expect suspend fun getIdToken(userRepository: UserRepository): String?

fun ApolloClient(
sqlNormalizedCacheFactory: SqlNormalizedCacheFactory,
sqlNormalizedCacheFactory: NormalizedCacheFactory,
userRepository: UserRepository,
): ApolloClient {
val memoryCacheFactory = MemoryCacheFactory(20_000_000).chain(sqlNormalizedCacheFactory)
return ApolloClient.Builder()
.serverUrl("https://androidmakers.fr/graphql")
.addHttpInterceptor(object : HttpInterceptor {
Expand All @@ -36,6 +35,6 @@ fun ApolloClient(
)
}
})
.normalizedCache(memoryCacheFactory)
.cache(MemoryCacheFactory(20_000_000).chain(sqlNormalizedCacheFactory))
.build()
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
package fr.androidmakers.store.graphql

import com.apollographql.apollo.ApolloCall
import com.apollographql.apollo.api.ApolloResponse
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.cache.normalized.FetchPolicy
import com.apollographql.apollo.cache.normalized.fetchPolicy
import com.apollographql.apollo.exception.ApolloException
import com.apollographql.apollo.exception.CacheMissException
import com.apollographql.apollo.exception.DefaultApolloException
import com.apollographql.cache.normalized.FetchPolicy
import com.apollographql.cache.normalized.fetchPolicy
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.flow

internal fun <T : Operation.Data> Flow<ApolloResponse<T>>.ignoreCacheMisses(): Flow<ApolloResponse<T>> {
return filterNot {
// Ignore cache misses
it.exception is CacheMissException
}
}


internal fun <T : Operation.Data> ApolloCall<T>.cacheAndNetwork(
refresh: Boolean = false
): Flow<Result<T>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fr.androidmakers.store.graphql

import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.cache.normalized.FetchPolicy
import com.apollographql.apollo.cache.normalized.fetchPolicy
import com.apollographql.cache.normalized.FetchPolicy
import com.apollographql.cache.normalized.fetchPolicy
import fr.androidmakers.domain.model.Session
import fr.androidmakers.domain.repo.SessionsRepository
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -31,7 +31,7 @@ class SessionsGraphQLRepository(private val apolloClient: ApolloClient) : Sessio
}
}

override fun getBookmarks(uid: String): Flow<Result<Set<String>>> {
override fun getBookmarks(userId: String): Flow<Result<Set<String>>> {
return apolloClient.query(BookmarksQuery())
.fetchPolicy(FetchPolicy.NetworkOnly)
.toFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.androidmakers.di
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
import fr.androidmakers.store.graphql.ApolloClient
import fr.androidmakers.store.wear.WearMessaging
import fr.androidmakers.store.wear.WearMessagingImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.androidmakers.di
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
import fr.androidmakers.store.graphql.ApolloClient
import fr.androidmakers.store.wear.WearMessaging
import fr.androidmakers.store.wear.WearMessagingImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.androidmakers.di
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
import fr.androidmakers.domain.model.User
import fr.androidmakers.domain.repo.UserRepository
import fr.androidmakers.store.graphql.ApolloClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.wear.compose.foundation.pager.PagerState
import androidx.wear.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -20,11 +17,14 @@ import androidx.core.app.ActivityCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavType
import androidx.navigation.navArgument
import androidx.wear.compose.foundation.SwipeToDismissBoxState
import androidx.wear.compose.foundation.SwipeToDismissValue
import androidx.wear.compose.foundation.edgeSwipeToDismiss
import androidx.wear.compose.foundation.pager.PagerState
import androidx.wear.compose.foundation.pager.rememberPagerState
import androidx.wear.compose.foundation.rememberSwipeToDismissBoxState
import androidx.wear.compose.navigation.SwipeDismissableNavHost
import androidx.wear.compose.navigation.composable
Expand All @@ -42,7 +42,6 @@ import fr.paug.androidmakers.wear.ui.session.list.SessionListScreen
import fr.paug.androidmakers.wear.ui.settings.SettingsScreen
import fr.paug.androidmakers.wear.ui.signin.SignInScreen
import fr.paug.androidmakers.wear.ui.theme.AndroidMakersWearTheme
import kotlinx.coroutines.flow.map
import org.koin.androidx.compose.koinViewModel
import org.koin.core.parameter.parametersOf

Expand Down Expand Up @@ -89,8 +88,8 @@ fun WearApp(

AndroidMakersWearTheme {
AppScaffold {
val isResumed by LocalLifecycleOwner.current.lifecycle.currentStateFlow.map { it == Lifecycle.State.RESUMED }
.collectAsState(false)
val lifecycleState by LocalLifecycleOwner.current.lifecycle.currentStateFlow.collectAsState(false)
val isResumed = lifecycleState == Lifecycle.State.RESUMED
SwipeDismissableNavHost(
navController = navController,
startDestination = Navigation.main,
Expand Down
Loading