diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index 876dfc20d..24aa870d7 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -14,6 +14,8 @@ * limitations under the License. */ +import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING + plugins { alias(libs.plugins.nowinandroid.kmp.library) alias(libs.plugins.nowinandroid.android.library.jacoco) @@ -38,7 +40,7 @@ secrets { defaultPropertiesFileName = "secrets.defaults.properties" } -buildKonfig { +buildkonfig { packageName = "com.google.samples.apps.nowinandroid.core.network" defaultConfigs { buildConfigField(STRING, "BACKEND_URL", "\"https://www.example.com\"") diff --git a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/assets/SampleData.kt b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/assets/SampleData.kt index 3c47eade9..bd02586da 100644 --- a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/assets/SampleData.kt +++ b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/assets/SampleData.kt @@ -4761,4 +4761,4 @@ internal val NEWS_DATA = """ ] } ] -""".trimIndent() \ No newline at end of file +""".trimIndent() diff --git a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/DiskCacheComponent.kt b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/DiskCacheComponent.kt deleted file mode 100644 index e954315fd..000000000 --- a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/DiskCacheComponent.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.samples.apps.nowinandroid.core.network.di - -import coil3.disk.DiskCache -import me.tatarka.inject.annotations.Provides - -expect class DiskCacheComponent { - @Provides - internal fun newDiskCache(): DiskCache? -} \ No newline at end of file diff --git a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/ImageLoaderComponent.kt b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/ImageLoaderComponent.kt index cfae7527f..b0e194413 100644 --- a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/ImageLoaderComponent.kt +++ b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/ImageLoaderComponent.kt @@ -18,7 +18,6 @@ package com.google.samples.apps.nowinandroid.core.network.di import coil3.ImageLoader import coil3.PlatformContext -import coil3.disk.DiskCache import coil3.memory.MemoryCache import coil3.request.crossfade import coil3.util.DebugLogger @@ -37,7 +36,6 @@ abstract class ImageLoaderComponent { @Provides fun provideImageLoader( context: PlatformContext, - diskCache: DiskCache?, debug: Boolean, ): ImageLoader { return ImageLoader.Builder(context) @@ -47,9 +45,6 @@ abstract class ImageLoaderComponent { .maxSizePercent(context, percent = 0.25) .build() } - .diskCache { - diskCache - } // Show a short crossfade when loading images asynchronously. .crossfade(true) // Enable logging if this is a debug build. diff --git a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt index 4408885c5..dc8be8b8c 100644 --- a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt +++ b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt @@ -16,6 +16,7 @@ package com.google.samples.apps.nowinandroid.core.network.di +import com.google.samples.apps.nowinandroid.core.network.BuildKonfig import de.jensklingenberg.ktorfit.Ktorfit import de.jensklingenberg.ktorfit.converter.builtin.CallConverterFactory import de.jensklingenberg.ktorfit.converter.builtin.FlowConverterFactory @@ -37,7 +38,7 @@ internal abstract class NetworkModule { @Provides fun provideKtorfit(json: Json): Ktorfit = ktorfit { - baseUrl(BuildConfig.BACKEND_URL) + baseUrl(BuildKonfig.BACKEND_URL) httpClient( HttpClient { install(ContentNegotiation) { diff --git a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt index 8b4b235ff..355584433 100644 --- a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt +++ b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt @@ -18,6 +18,8 @@ package com.google.samples.apps.nowinandroid.core.network.fake import com.google.samples.apps.nowinandroid.core.di.IODispatcher import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource +import com.google.samples.apps.nowinandroid.core.network.assets.NEWS_DATA +import com.google.samples.apps.nowinandroid.core.network.assets.TOPICS_DATA import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic @@ -37,13 +39,13 @@ class FakeNiaNetworkDataSource @Inject constructor( @OptIn(ExperimentalSerializationApi::class) override suspend fun getTopics(ids: List?): List = withContext(ioDispatcher) { - networkJson.decodeFromString(TOPICS_ASSET) + networkJson.decodeFromString(TOPICS_DATA) } @OptIn(ExperimentalSerializationApi::class) override suspend fun getNewsResources(ids: List?): List = withContext(ioDispatcher) { - networkJson.decodeFromString(NEWS_ASSET) + networkJson.decodeFromString(NEWS_DATA) } override suspend fun getTopicChangeList(after: Int?): List = @@ -51,11 +53,6 @@ class FakeNiaNetworkDataSource @Inject constructor( override suspend fun getNewsResourceChangeList(after: Int?): List = getNewsResources().mapToChangeList(NetworkNewsResource::id) - - companion object { - private const val NEWS_ASSET = "news.json" - private const val TOPICS_ASSET = "topics.json" - } } /** diff --git a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt index cac997563..3ae6ac79f 100644 --- a/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt +++ b/core/network/src/commonMain/kotlin/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt @@ -29,7 +29,7 @@ import me.tatarka.inject.annotations.Inject /** * Retrofit API declaration for NIA Network API */ -private interface RetrofitNiaNetworkApi { +internal interface RetrofitNiaNetworkApi { @GET(value = "topics") suspend fun getTopics( @Query("id") ids: List?, @@ -55,7 +55,7 @@ private interface RetrofitNiaNetworkApi { * Wrapper for data provided from the [NIA_BASE_URL] */ @Serializable -private data class NetworkResponse( +internal data class NetworkResponse( val data: T, ) diff --git a/core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt b/core/network/src/commonTest/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt similarity index 98% rename from core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt rename to core/network/src/commonTest/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt index b64c06e52..c88755a6d 100644 --- a/core/network/src/test/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt +++ b/core/network/src/commonTest/kotlin/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt @@ -24,9 +24,8 @@ import kotlinx.datetime.LocalDateTime import kotlinx.datetime.TimeZone import kotlinx.datetime.toInstant import kotlinx.serialization.json.Json -import org.junit.Before -import org.junit.Test import kotlin.test.BeforeTest +import kotlin.test.Test import kotlin.test.assertEquals class FakeNiaNetworkDataSourceTest { diff --git a/core/network/src/prod/kotlin/com/google/samples/apps/nowinandroid/core/network/di/FlavoredNetworkModule.kt b/core/network/src/prod/kotlin/com/google/samples/apps/nowinandroid/core/network/di/FlavoredNetworkModule.kt deleted file mode 100644 index bff1ca5be..000000000 --- a/core/network/src/prod/kotlin/com/google/samples/apps/nowinandroid/core/network/di/FlavoredNetworkModule.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.samples.apps.nowinandroid.core.network.di - -import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource -import com.google.samples.apps.nowinandroid.core.network.retrofit.RetrofitNiaNetwork -import dagger.Binds -import dagger.Module -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent - -@Module -@InstallIn(SingletonComponent::class) -internal interface FlavoredNetworkModule { - - @Binds - fun binds(impl: RetrofitNiaNetwork): NiaNetworkDataSource -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a8b69017e..3b70ada5e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -75,7 +75,7 @@ sqldelight = "2.0.1" kotlinInject = '0.6.3' multiplatform-settings = "1.1.1" kermit = "2.0.3" -ktor = "3.0.0-beta-1" +ktor = "2.3.9" ktrofit = "1.12.0" buildKonfig = "0.15.1"