Skip to content

Commit

Permalink
Replace ktorfit in remote controls (#905)
Browse files Browse the repository at this point in the history
**Background**

Ktorfit updates sometimes causes difficulties to update it. This PR
replace ktorfit inside remote-controls module with raw ktor

**Changes**

- Remote ktorfit from remote-controls 

**Test plan**

- Launch app
- Open remote controls screen
- Follow full userflow of this feature
  • Loading branch information
makeevrserg authored Jul 29, 2024
1 parent 34e5d78 commit 26c8e34
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 1.7.2 - In Progress

- [Refactor] Update to Kotlin 2.0
- [Refactor] Replace Ktorfit with Ktor requests in remote-controls
- [FIX] Distinct fap items by id in paging sources
- [FIX] Battery level charge
- [FIX] Button arrow tint
Expand Down
2 changes: 0 additions & 2 deletions components/remote-controls/api-backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ plugins {
id("flipper.multiplatform-dependencies")
id("kotlinx-serialization")
id("flipper.anvil")
id("flipper.ktorfit-multiplatform")
}

android.namespace = "com.flipperdevices.remotecontrols.api.backend"

commonDependencies {
implementation(libs.ktorfit.lib)
implementation(libs.kotlin.coroutines)
implementation(libs.kotlin.serialization.json)
implementation(projects.components.core.di)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,15 @@ import com.flipperdevices.ifrmvp.backend.model.IfrFileContentResponse
import com.flipperdevices.ifrmvp.backend.model.PagesLayoutBackendModel
import com.flipperdevices.ifrmvp.backend.model.SignalRequestModel
import com.flipperdevices.ifrmvp.backend.model.SignalResponseModel
import de.jensklingenberg.ktorfit.http.Body
import de.jensklingenberg.ktorfit.http.GET
import de.jensklingenberg.ktorfit.http.POST
import de.jensklingenberg.ktorfit.http.Query

interface InfraredBackendApi {
@GET("categories")
suspend fun getCategories(): CategoriesResponse

@GET("brands")
suspend fun getManufacturers(
@Query("category_id") categoryId: Long
): BrandsResponse
suspend fun getManufacturers(categoryId: Long): BrandsResponse

@POST("signal")
suspend fun getSignal(
@Body request: SignalRequestModel
): SignalResponseModel
suspend fun getSignal(request: SignalRequestModel): SignalResponseModel

@GET("key")
suspend fun getIfrFileContent(
@Query("ifr_file_id") ifrFileId: Long
): IfrFileContentResponse
suspend fun getIfrFileContent(ifrFileId: Long): IfrFileContentResponse

@GET("ui")
suspend fun getUiFile(
@Query("ifr_file_id") ifrFileId: Long
): PagesLayoutBackendModel
suspend fun getUiFile(ifrFileId: Long): PagesLayoutBackendModel
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.flipperdevices.ifrmvp.api.infrared

import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.ifrmvp.api.infrared.model.InfraredHost
import com.flipperdevices.ifrmvp.backend.model.BrandsResponse
import com.flipperdevices.ifrmvp.backend.model.CategoriesResponse
import com.flipperdevices.ifrmvp.backend.model.IfrFileContentResponse
import com.flipperdevices.ifrmvp.backend.model.PagesLayoutBackendModel
import com.flipperdevices.ifrmvp.backend.model.SignalRequestModel
import com.flipperdevices.ifrmvp.backend.model.SignalResponseModel
import com.squareup.anvil.annotations.ContributesBinding
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.client.request.url
import io.ktor.http.ContentType
import io.ktor.http.contentType
import javax.inject.Inject

@ContributesBinding(AppGraph::class, InfraredBackendApi::class)
class InfraredBackendApiImpl(
private val httpClient: HttpClient,
private val host: InfraredHost = InfraredHost.DEV
) : InfraredBackendApi {
@Inject
constructor(httpClient: HttpClient) : this(httpClient, InfraredHost.DEV)

override suspend fun getCategories(): CategoriesResponse {
return httpClient.get {
url("${host.url}/categories")
contentType(ContentType.Application.Json)
}.body()
}

override suspend fun getManufacturers(categoryId: Long): BrandsResponse {
return httpClient.get {
url("${host.url}/brands")
parameter("category_id", categoryId)
contentType(ContentType.Application.Json)
}.body()
}

override suspend fun getSignal(request: SignalRequestModel): SignalResponseModel {
return httpClient.post {
url("${host.url}/signal")
contentType(ContentType.Application.Json)
setBody(request)
}.body()
}

override suspend fun getIfrFileContent(ifrFileId: Long): IfrFileContentResponse {
return httpClient.get {
url("${host.url}/key")
parameter("ifr_file_id", ifrFileId)
contentType(ContentType.Application.Json)
}.body()
}

override suspend fun getUiFile(ifrFileId: Long): PagesLayoutBackendModel {
return httpClient.get {
url("${host.url}/ui")
parameter("ifr_file_id", ifrFileId)
contentType(ContentType.Application.Json)
}.body()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.flipperdevices.ifrmvp.api.infrared.model

enum class InfraredHost(val url: String) {
DEV("https://infrared.dev.flipp.dev/"),
PROD("https://infrared.flipperzero.one/")
}

0 comments on commit 26c8e34

Please sign in to comment.