From 4b3ae721a095544a374f90866d24e544405185e8 Mon Sep 17 00:00:00 2001 From: Phil Oliver <3497406+poliver@users.noreply.github.com> Date: Tue, 16 Dec 2025 16:52:29 -0500 Subject: [PATCH] Remove ktorfit (#4019) --- build.gradle.kts | 6 -- core/network/build.gradle.kts | 2 - .../core/network/di/GoogleNetworkModule.kt | 82 +++++++++---------- .../core/network/service/ApiService.kt | 15 +++- gradle/libs.versions.toml | 3 - 5 files changed, 53 insertions(+), 55 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6a54d6bbd..05cd28452 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,6 @@ plugins { alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.kotlin.parcelize) apply false alias(libs.plugins.kotlin.serialization) apply false - alias(libs.plugins.ktorfit) apply false alias(libs.plugins.protobuf) apply false alias(libs.plugins.secrets) apply false alias(libs.plugins.dependency.analysis) @@ -108,11 +107,6 @@ dependencyAnalysis { includeDependency("com.google.dagger:hilt-core") includeDependency(libs.hilt.android) } - - bundle("ktorfit") { - includeDependency("de.jensklingenberg.ktorfit:ktorfit-lib") - includeDependency("de.jensklingenberg.ktorfit:ktorfit-annotations") - } } issues { diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index a3d9ef413..7a16b0557 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -22,7 +22,6 @@ plugins { alias(libs.plugins.dokka) alias(libs.plugins.kover) alias(libs.plugins.protobuf) - alias(libs.plugins.ktorfit) } android { @@ -40,7 +39,6 @@ dependencies { implementation(libs.ktor.client.content.negotiation) implementation(libs.ktor.client.okhttp) implementation(libs.ktor.serialization.kotlinx.json) - implementation(libs.ktorfit) implementation(libs.okhttp3.logging.interceptor) googleImplementation(libs.dd.sdk.android.okhttp) diff --git a/core/network/src/google/kotlin/org/meshtastic/core/network/di/GoogleNetworkModule.kt b/core/network/src/google/kotlin/org/meshtastic/core/network/di/GoogleNetworkModule.kt index 0784f3295..0cc16e66c 100644 --- a/core/network/src/google/kotlin/org/meshtastic/core/network/di/GoogleNetworkModule.kt +++ b/core/network/src/google/kotlin/org/meshtastic/core/network/di/GoogleNetworkModule.kt @@ -20,12 +20,12 @@ package org.meshtastic.core.network.di import android.content.Context import com.datadog.android.okhttp.DatadogEventListener import com.datadog.android.okhttp.DatadogInterceptor +import dagger.Binds import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent -import de.jensklingenberg.ktorfit.Ktorfit import io.ktor.client.HttpClient import io.ktor.client.engine.okhttp.OkHttp import io.ktor.client.plugins.contentnegotiation.ContentNegotiation @@ -36,55 +36,55 @@ import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import org.meshtastic.core.network.BuildConfig import org.meshtastic.core.network.service.ApiService -import org.meshtastic.core.network.service.createApiService +import org.meshtastic.core.network.service.ApiServiceImpl import java.io.File import javax.inject.Singleton @InstallIn(SingletonComponent::class) @Module -class GoogleNetworkModule { +interface GoogleNetworkModule { - @Provides - @Singleton - fun provideOkHttpClient(@ApplicationContext context: Context): OkHttpClient = OkHttpClient.Builder() - .cache( - cache = - Cache( - directory = File(context.applicationContext.cacheDir, "http_cache"), - maxSize = 50L * 1024L * 1024L, // 50 MiB - ), - ) - .addInterceptor( - interceptor = - HttpLoggingInterceptor().apply { - if (BuildConfig.DEBUG) { - setLevel(HttpLoggingInterceptor.Level.BODY) - } - }, - ) - .addInterceptor(interceptor = DatadogInterceptor.Builder(tracedHosts = listOf("meshtastic.org")).build()) - .eventListenerFactory(eventListenerFactory = DatadogEventListener.Factory()) - .build() + @Binds @Singleton + fun bindApiService(apiServiceImpl: ApiServiceImpl): ApiService - @Provides - @Singleton - fun provideHttpClient(okHttpClient: OkHttpClient): HttpClient = HttpClient(engineFactory = OkHttp) { - engine { preconfigured = okHttpClient } - - install(plugin = ContentNegotiation) { - json( - Json { - isLenient = true - ignoreUnknownKeys = true + companion object { + @Provides + @Singleton + fun provideOkHttpClient(@ApplicationContext context: Context): OkHttpClient = OkHttpClient.Builder() + .cache( + cache = + Cache( + directory = File(context.applicationContext.cacheDir, "http_cache"), + maxSize = 50L * 1024L * 1024L, // 50 MiB + ), + ) + .addInterceptor( + interceptor = + HttpLoggingInterceptor().apply { + if (BuildConfig.DEBUG) { + setLevel(HttpLoggingInterceptor.Level.BODY) + } }, ) + .addInterceptor( + interceptor = DatadogInterceptor.Builder(tracedHosts = listOf("meshtastic.org")).build(), + ) + .eventListenerFactory(eventListenerFactory = DatadogEventListener.Factory()) + .build() + + @Provides + @Singleton + fun provideHttpClient(okHttpClient: OkHttpClient): HttpClient = HttpClient(engineFactory = OkHttp) { + engine { preconfigured = okHttpClient } + + install(plugin = ContentNegotiation) { + json( + Json { + isLenient = true + ignoreUnknownKeys = true + }, + ) + } } } - - @Provides - @Singleton - fun provideApiService(httpClient: HttpClient): ApiService { - val ktorfit = Ktorfit.Builder().baseUrl(url = "https://api.meshtastic.org/").httpClient(httpClient).build() - return ktorfit.createApiService() - } } diff --git a/core/network/src/main/kotlin/org/meshtastic/core/network/service/ApiService.kt b/core/network/src/main/kotlin/org/meshtastic/core/network/service/ApiService.kt index 5d461c771..755a88568 100644 --- a/core/network/src/main/kotlin/org/meshtastic/core/network/service/ApiService.kt +++ b/core/network/src/main/kotlin/org/meshtastic/core/network/service/ApiService.kt @@ -17,14 +17,23 @@ package org.meshtastic.core.network.service -import de.jensklingenberg.ktorfit.http.GET +import io.ktor.client.HttpClient +import io.ktor.client.call.body +import io.ktor.client.request.get import org.meshtastic.core.model.NetworkDeviceHardware import org.meshtastic.core.model.NetworkFirmwareReleases +import javax.inject.Inject interface ApiService { - @GET("resource/deviceHardware") suspend fun getDeviceHardware(): List - @GET("github/firmware/list") suspend fun getFirmwareReleases(): NetworkFirmwareReleases } + +class ApiServiceImpl @Inject constructor(private val client: HttpClient) : ApiService { + override suspend fun getDeviceHardware(): List = + client.get("https://api.meshtastic.org/resource/deviceHardware").body() + + override suspend fun getFirmwareReleases(): NetworkFirmwareReleases = + client.get("https://api.meshtastic.org/github/firmware/list").body() +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bccb9b064..2544686b8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,7 +26,6 @@ maps-compose = "6.12.2" # Networking ktor = "3.3.3" -ktorfit = "2.7.1" # Other aboutlibraries = "13.1.0" @@ -120,7 +119,6 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" } ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } -ktorfit = { module = "de.jensklingenberg.ktorfit:ktorfit-lib", version.ref = "ktorfit" } okhttp3-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version = "5.3.2" } # Testing @@ -194,7 +192,6 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kover = { id = "org.jetbrains.kotlinx.kover", version = "0.9.4" } -ktorfit = { id = "de.jensklingenberg.ktorfit", version.ref = "ktorfit" } # Google devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "devtools-ksp" }