Skip to content

Commit

Permalink
chore: swap retrofit for ktor
Browse files Browse the repository at this point in the history
  • Loading branch information
corenting committed May 25, 2024
1 parent bf0b799 commit 55f01ce
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 77 deletions.
29 changes: 17 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ android {
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
coreLibraryDesugaringEnabled true

sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = JavaVersion.VERSION_17
}

// For tests
Expand Down Expand Up @@ -47,27 +49,30 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'

// AndroidX
def lifecycleVersion = '2.7.0'
def lifecycleVersion = '2.8.0'
implementation 'androidx.activity:activity-ktx:1.9.0'
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation 'androidx.fragment:fragment-ktx:1.7.1'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.13.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'com.google.android.material:material:1.12.0'

// Retrofit
def retrofitVersion = '2.11.0'
implementation "com.squareup.retrofit2:retrofit:${retrofitVersion}"
implementation "com.squareup.retrofit2:converter-gson:${retrofitVersion}"
// ktor
def ktorVersion = "2.3.11"
implementation "io.ktor:ktor-client-core:${ktorVersion}"
implementation "io.ktor:ktor-client-cio:${ktorVersion}"
implementation "io.ktor:ktor-client-content-negotiation:${ktorVersion}"
implementation "io.ktor:ktor-serialization-gson:${ktorVersion}"

// Other
implementation 'com.mikepenz:itemanimators:1.1.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.code.gson:gson:2.11.0'

// Tests
testImplementation 'androidx.test:core-ktx:1.5.0'
Expand Down
40 changes: 1 addition & 39 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,4 @@
-keepclassmembers class fr.corenting.traficparis.models.** { <fields>; }
-keep class fr.corenting.traficparis.models.** {
<init>();
}

# Retrofit
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod
# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
# Keep annotation default values (e.g., retrofit2.http.Field.encoded).
-keepattributes AnnotationDefault
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit
# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
# Keep inherited services.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface * extends <1>
# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
# R8 full mode strips generic signatures from return types if not kept.
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
# With R8 full mode generic signatures are stripped for classes that are not kept.
-keep,allowobfuscation,allowshrinking class retrofit2.Response
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package fr.corenting.traficparis.traffic

import fr.corenting.traficparis.models.api.ApiResponse
import fr.corenting.traficparis.models.RequestResult
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

import fr.corenting.traficparis.models.api.ApiResponse
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.cio.CIO
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.get
import io.ktor.serialization.gson.gson

class TrafficRepository {

private val apiService: TrafficApiService = Retrofit.Builder()
.baseUrl("https://tchoutchou.9cw.eu/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(TrafficApiService::class.java)

suspend fun getTraffic(): RequestResult<ApiResponse> {
return try {
RequestResult(data = apiService.getTraffic(), error = null)
val client = HttpClient(CIO) {
install(ContentNegotiation) {
gson()
}
}
val apiResponse: ApiResponse = client.get("https://tchoutchou.9cw.eu/traffic").body()
RequestResult(data = apiResponse, error = null)
} catch (t: Throwable) {
RequestResult(data = null, error = t)
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.9.23'
ext.kotlin_version = '2.0.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.3.2'
classpath 'com.android.tools.build:gradle:8.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip

0 comments on commit 55f01ce

Please sign in to comment.