Skip to content

Commit

Permalink
Remove ktorfit (#909)
Browse files Browse the repository at this point in the history
**Background**

Ktorfit is unnecessary complexity that the project doesn't need. Since
Ktorfit switched to the compiler plugin it has become very difficult to
maintain

**Changes**

- Remove ktorfit and migrate to manual ktor usage

**Test plan**

Try open apps tab
  • Loading branch information
LionZXY authored Aug 1, 2024
1 parent 3dcd01b commit d254fce
Show file tree
Hide file tree
Showing 50 changed files with 271 additions and 280 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Attention: don't forget to add the flag for F-Droid before release
- [Refactor] Update to Kotlin 2.0
- [Refactor] Replace Ktorfit with Ktor requests in remote-controls
- [Refactor] Migrate :core:preference to KMP
- [Refactor] Remove ktorfit
- [FIX] Distinct fap items by id in paging sources
- [FIX] Battery level charge
- [FIX] Button arrow tint
Expand Down
1 change: 0 additions & 1 deletion build-logic/plugins/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies {
implementation(libs.grgit.gradle)
implementation(libs.kotlin.ksp.gradle)
implementation(libs.square.anvil.gradle)
implementation(libs.ktorfit.gradle)
implementation(libs.compose.multiplatform.gradle)
implementation(libs.compose.gradle)
implementation(libs.kotlin.jvm.gradle)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class CountlyApiImpl @Inject constructor(
id: String,
params: Map<String, Any?>?
) {
if (countly.events() == null) {
return
}
verbose { "Report event $id with $params" }
if (params == null) {
countly.events().recordEvent(id)
Expand Down
2 changes: 1 addition & 1 deletion components/faphub/dao/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id("flipper.android-lib")
id("flipper.anvil")
id("kotlinx-serialization")
id("flipper.ktorfit")
}

android.namespace = "com.flipperdevices.faphub.dao.network"
Expand All @@ -25,6 +24,7 @@ dependencies {
implementation(libs.kotlin.coroutines)
implementation(libs.kotlin.immutable.collections)
implementation(libs.kotlin.datetime)
implementation(libs.ktor.client)

implementation(libs.annotations)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.flipperdevices.core.preference.FlipperStorageProvider
import com.flipperdevices.core.progress.ProgressListener
import com.flipperdevices.core.progress.ProgressWrapperTracker
import com.flipperdevices.faphub.dao.api.FapDownloadApi
import com.flipperdevices.faphub.dao.network.ktorfit.api.KtorfitBundleApi
import com.flipperdevices.faphub.dao.network.network.api.FapNetworkBundleApi
import com.flipperdevices.faphub.target.model.FlipperTarget
import com.squareup.anvil.annotations.ContributesBinding
import io.ktor.client.call.body
Expand All @@ -22,7 +22,7 @@ import javax.inject.Inject

@ContributesBinding(AppGraph::class, FapDownloadApi::class)
class FapDownloadApiImpl @Inject constructor(
private val bundleApi: KtorfitBundleApi,
private val bundleApi: FapNetworkBundleApi,
private val context: Context
) : FapDownloadApi, LogTagProvider {
override val TAG = "FapDownloadApi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.flipperdevices.faphub.dao.api.FapNetworkApi
import com.flipperdevices.faphub.dao.api.model.FapCategory
import com.flipperdevices.faphub.dao.api.model.SortType
import com.flipperdevices.faphub.dao.network.helper.FapApplicationReceiveHelper
import com.flipperdevices.faphub.dao.network.ktorfit.api.KtorfitApplicationApi
import com.flipperdevices.faphub.dao.network.ktorfit.model.requests.KtorfitApplicationApiRequest
import com.flipperdevices.faphub.dao.network.ktorfit.utils.FapHubNetworkCategoryApi
import com.flipperdevices.faphub.dao.network.ktorfit.utils.HostUrlBuilder
import com.flipperdevices.faphub.dao.network.network.api.FapNetworkApplicationApi
import com.flipperdevices.faphub.dao.network.network.model.FapNetworkHostEnum
import com.flipperdevices.faphub.dao.network.network.model.requests.KtorfitApplicationApiRequest
import com.flipperdevices.faphub.dao.network.network.utils.FapCachedCategoryApi
import com.flipperdevices.faphub.errors.api.throwable.FirmwareNotSupported
import com.flipperdevices.faphub.target.model.FlipperTarget
import com.squareup.anvil.annotations.ContributesBinding
Expand All @@ -21,14 +21,14 @@ import javax.inject.Inject

@ContributesBinding(AppGraph::class, FapNetworkApi::class)
class FapNetworkApiImpl @Inject constructor(
private val applicationApi: KtorfitApplicationApi,
private val categoryApi: FapHubNetworkCategoryApi,
private val hostUrlBuilder: HostUrlBuilder,
private val applicationApi: FapNetworkApplicationApi,
private val categoryApi: FapCachedCategoryApi,
private val networkHost: FapNetworkHostEnum,
private val fapApplicationReceiveHelper: FapApplicationReceiveHelper
) : FapNetworkApi, LogTagProvider {
override val TAG = "FapNetworkApi"

override suspend fun getHostUrl() = hostUrlBuilder.getHostUrl()
override suspend fun getHostUrl() = networkHost.hostUrl
override suspend fun getFeaturedItem(target: FlipperTarget) = catchWithDispatcher {
debug { "Request featured item" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package com.flipperdevices.faphub.dao.network.api

import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.faphub.dao.api.FapReportApi
import com.flipperdevices.faphub.dao.network.ktorfit.api.KtorfitApplicationApi
import com.flipperdevices.faphub.dao.network.ktorfit.model.KtorfitReport
import com.flipperdevices.faphub.dao.network.network.api.FapNetworkApplicationApi
import com.flipperdevices.faphub.dao.network.network.model.KtorfitReport
import com.squareup.anvil.annotations.ContributesBinding
import javax.inject.Inject

private const val DEFAULT_TYPE = "default_android"

@ContributesBinding(AppGraph::class, FapReportApi::class)
class FapReportApiImpl @Inject constructor(
val ktorfitApplicationApi: KtorfitApplicationApi
val fapNetworkApplicationApi: FapNetworkApplicationApi
) : FapReportApi {
override suspend fun report(applicationUid: String, description: String) {
ktorfitApplicationApi.report(
fapNetworkApplicationApi.report(
applicationUid,
KtorfitReport(
description = description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.core.ktx.jre.pmap
import com.flipperdevices.core.log.LogTagProvider
import com.flipperdevices.faphub.dao.api.FapVersionApi
import com.flipperdevices.faphub.dao.network.ktorfit.api.KtorfitVersionApi
import com.flipperdevices.faphub.dao.network.ktorfit.model.requests.KtorfitDetailedVersionRequest
import com.flipperdevices.faphub.dao.network.network.api.FapNetworkVersionApi
import com.flipperdevices.faphub.dao.network.network.model.requests.KtorfitDetailedVersionRequest
import com.squareup.anvil.annotations.ContributesBinding
import javax.inject.Inject

private const val MAX_QUERY_ARRAY_SIZE = 500

@ContributesBinding(AppGraph::class, FapVersionApi::class)
class FapVersionApiImpl @Inject constructor(
private val ktorfitVersionApi: KtorfitVersionApi
private val fapNetworkVersionApi: FapNetworkVersionApi
) : FapVersionApi, LogTagProvider {
override val TAG = "FapVersionApi"

override suspend fun getVersionsMap(versions: List<String>): Map<String, SemVer> {
val fetchedVersions = versions.chunked(MAX_QUERY_ARRAY_SIZE)
.pmap {
ktorfitVersionApi.getVersions(
fapNetworkVersionApi.getVersions(
KtorfitDetailedVersionRequest(
applicationVersions = it,
limit = it.size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.flipperdevices.core.log.LogTagProvider
import com.flipperdevices.core.log.warn
import com.flipperdevices.faphub.dao.api.model.FapCategory
import com.flipperdevices.faphub.dao.api.model.SortType
import com.flipperdevices.faphub.dao.network.ktorfit.api.KtorfitApplicationApi
import com.flipperdevices.faphub.dao.network.ktorfit.model.KtorfitApplicationShort
import com.flipperdevices.faphub.dao.network.ktorfit.model.KtorfitException
import com.flipperdevices.faphub.dao.network.ktorfit.model.KtorfitExceptionCode
import com.flipperdevices.faphub.dao.network.ktorfit.model.requests.KtorfitApplicationApiRequest
import com.flipperdevices.faphub.dao.network.ktorfit.model.types.ApplicationSortType
import com.flipperdevices.faphub.dao.network.ktorfit.model.types.SortOrderType
import com.flipperdevices.faphub.dao.network.network.api.FapNetworkApplicationApi
import com.flipperdevices.faphub.dao.network.network.model.KtorfitApplicationShort
import com.flipperdevices.faphub.dao.network.network.model.KtorfitExceptionCode
import com.flipperdevices.faphub.dao.network.network.model.NetworkException
import com.flipperdevices.faphub.dao.network.network.model.requests.KtorfitApplicationApiRequest
import com.flipperdevices.faphub.dao.network.network.model.types.ApplicationSortType
import com.flipperdevices.faphub.dao.network.network.model.types.SortOrderType
import com.flipperdevices.faphub.errors.api.throwable.FirmwareNotSupported
import com.flipperdevices.faphub.target.model.FlipperTarget
import io.ktor.client.call.body
Expand All @@ -22,7 +22,7 @@ private const val MAX_QUERY_ARRAY_SIZE = 500

@Suppress("LongParameterList")
class FapApplicationReceiveHelper @Inject constructor(
private val applicationApi: KtorfitApplicationApi,
private val applicationApi: FapNetworkApplicationApi,
) : LogTagProvider {
override val TAG = "FapApplicationReceiveHelper"
suspend fun get(
Expand All @@ -46,10 +46,10 @@ class FapApplicationReceiveHelper @Inject constructor(
applicationIds = applicationIds
)
} catch (requestException: ClientRequestException) {
val ktorfitException = runCatching {
requestException.response.body<KtorfitException>()
val networkException = runCatching {
requestException.response.body<NetworkException>()
}.getOrNull() ?: throw requestException
val exceptionCode = KtorfitExceptionCode.fromCode(ktorfitException.detail.code)
val exceptionCode = KtorfitExceptionCode.fromCode(networkException.detail.code)
throw if (exceptionCode == KtorfitExceptionCode.UNKNOWN_SDK) {
FirmwareNotSupported(requestException)
} else {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d254fce

Please sign in to comment.