Skip to content

Commit 9857d14

Browse files
committed
refactor: switch to kotlinx serialization (closes #184)
1 parent 607925e commit 9857d14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+187
-153
lines changed

app/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id("com.android.application")
33
id("org.jetbrains.kotlin.android")
44
id("kotlin-kapt")
5+
id("kotlinx-serialization")
56
}
67

78
android {
@@ -90,7 +91,8 @@ dependencies {
9091

9192
// Retrofit
9293
implementation("com.squareup.retrofit2:retrofit:2.11.0")
93-
implementation("com.squareup.retrofit2:converter-jackson:2.11.0")
94+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
95+
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0")
9496
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
9597

9698
// Coil

app/proguard-rules.pro

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,27 @@
2121
#-renamesourcefileattribute SourceFile
2222

2323
-keep class com.bnyro.wallpaper.obj.** { *; }
24-
-keep class com.bnyro.wallpaper.api.**.** { *; }
24+
-keep class com.bnyro.wallpaper.api.**.** { *; }
25+
26+
# Keep rules required by Kotlinx Serialization
27+
-if @kotlinx.serialization.Serializable class **
28+
-keepclassmembers class <1> {
29+
static <1>$Companion Companion;
30+
}
31+
32+
-if @kotlinx.serialization.Serializable class ** {
33+
static **$* *;
34+
}
35+
-keepclassmembers class <2>$<3> {
36+
kotlinx.serialization.KSerializer serializer(...);
37+
}
38+
39+
-if @kotlinx.serialization.Serializable class ** {
40+
public static ** INSTANCE;
41+
}
42+
-keepclassmembers class <1> {
43+
public static <1> INSTANCE;
44+
kotlinx.serialization.KSerializer serializer(...);
45+
}
46+
47+
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

app/src/main/java/com/bnyro/wallpaper/api/Api.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class Api {
1616
abstract suspend fun getRandomWallpaperUrl(): String?
1717

1818
fun getPref(key: String, defValue: String): String {
19-
return Preferences.getString(this.name + key, defValue) ?: defValue
19+
return Preferences.getString(this.name + key, defValue)
2020
}
2121

2222
fun setPref(key: String, value: String) {

app/src/main/java/com/bnyro/wallpaper/api/bi/BiApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.bnyro.wallpaper.api.bi
22

33
import com.bnyro.wallpaper.api.Api
44
import com.bnyro.wallpaper.db.obj.Wallpaper
5-
import com.bnyro.wallpaper.util.RetrofitBuilder
5+
import com.bnyro.wallpaper.util.RetrofitHelper
66

77
class BiApi : Api() {
88
override val name: String = "Bing"
@@ -12,7 +12,7 @@ class BiApi : Api() {
1212
)
1313
private val previewResolution = "1366x768"
1414

15-
val api = RetrofitBuilder.create(baseUrl, Bing::class.java)
15+
val api = RetrofitHelper.create(baseUrl, Bing::class.java)
1616

1717
private fun getImgSrc(path: String, resolution: String): String {
1818
return "$baseUrl${path}_${resolution}.jpg"
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package com.bnyro.wallpaper.api.bi.obj
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
4-
import com.fasterxml.jackson.annotation.JsonProperty
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
55

6-
@JsonIgnoreProperties(ignoreUnknown = true)
6+
@Serializable
77
data class BingImage(
8-
@JsonProperty("bot") val bot: Int? = null,
9-
@JsonProperty("copyright") val copyright: String? = null,
10-
@JsonProperty("copyrightlink") val copyrightLink: String? = null,
11-
@JsonProperty("drk") val drk: Int? = null,
12-
@JsonProperty("enddate") val endDate: String? = null,
13-
@JsonProperty("fullstartdate") val fullStartDate: String? = null,
14-
@JsonProperty("hsh") val hsh: String? = null,
15-
@JsonProperty("quiz") val quiz: String? = null,
16-
@JsonProperty("startdate") val startDate: String? = null,
17-
@JsonProperty("title") val title: String = "",
18-
@JsonProperty("top") val top: Int? = null,
19-
@JsonProperty("url") val url: String = "",
20-
@JsonProperty("urlbase") val urlBase: String = "",
21-
@JsonProperty("wp") val wp: Boolean = false
8+
@SerialName("bot") val bot: Int? = null,
9+
@SerialName("copyright") val copyright: String? = null,
10+
@SerialName("copyrightlink") val copyrightLink: String? = null,
11+
@SerialName("drk") val drk: Int? = null,
12+
@SerialName("enddate") val endDate: String? = null,
13+
@SerialName("fullstartdate") val fullStartDate: String? = null,
14+
@SerialName("hsh") val hsh: String? = null,
15+
@SerialName("quiz") val quiz: String? = null,
16+
@SerialName("startdate") val startDate: String? = null,
17+
@SerialName("title") val title: String = "",
18+
@SerialName("top") val top: Int? = null,
19+
@SerialName("url") val url: String = "",
20+
@SerialName("urlbase") val urlBase: String = "",
21+
@SerialName("wp") val wp: Boolean = false
2222
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.bnyro.wallpaper.api.bi.obj
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
3+
import kotlinx.serialization.Serializable
44

5-
@JsonIgnoreProperties(ignoreUnknown = true)
5+
@Serializable
66
data class BingImageResponse(
77
val images: List<BingImage> = emptyList()
88
)

app/src/main/java/com/bnyro/wallpaper/api/le/LeApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.bnyro.wallpaper.api.le
22

33
import com.bnyro.wallpaper.api.CommunityApi
44
import com.bnyro.wallpaper.db.obj.Wallpaper
5-
import com.bnyro.wallpaper.util.RetrofitBuilder
5+
import com.bnyro.wallpaper.util.RetrofitHelper
66

77
class LeApi : CommunityApi() {
88
override val name: String = "Lemmy"
@@ -32,7 +32,7 @@ class LeApi : CommunityApi() {
3232

3333
override val defaultCommunityName: String = "[email protected]"
3434

35-
private val api = RetrofitBuilder.create(baseUrl, Lemmy::class.java)
35+
private val api = RetrofitHelper.create(baseUrl, Lemmy::class.java)
3636

3737
override suspend fun getWallpapers(page: Int): List<Wallpaper> {
3838
return api.getWallpapers(
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.bnyro.wallpaper.api.le.obj
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
4-
import com.fasterxml.jackson.annotation.JsonProperty
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
55

6-
@JsonIgnoreProperties(ignoreUnknown = true)
6+
@Serializable
77
data class LemmyCreator(
8-
@JsonProperty("name") val name: String = "",
8+
@SerialName("name") val name: String = "",
99
)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.bnyro.wallpaper.api.le.obj
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
4-
import com.fasterxml.jackson.annotation.JsonProperty
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
55

6-
@JsonIgnoreProperties(ignoreUnknown = true)
6+
@Serializable
77
data class LemmyPost(
8-
@JsonProperty("ap_id") val postUrl: String = "",
9-
@JsonProperty("name") val name: String = "",
10-
@JsonProperty("published") val published: String = "",
11-
@JsonProperty("thumbnail_url") val thumbnailUrl: String? = null,
8+
@SerialName("ap_id") val postUrl: String = "",
9+
@SerialName("name") val name: String = "",
10+
@SerialName("published") val published: String = "",
11+
@SerialName("thumbnail_url") val thumbnailUrl: String? = null,
1212
)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.bnyro.wallpaper.api.le.obj
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
4-
import com.fasterxml.jackson.annotation.JsonProperty
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
55

6-
@JsonIgnoreProperties(ignoreUnknown = true)
6+
@Serializable
77
data class LemmyPostView(
8-
@JsonProperty("creator") val creator: LemmyCreator = LemmyCreator(),
9-
@JsonProperty("post") val post: LemmyPost = LemmyPost(),
8+
@SerialName("creator") val creator: LemmyCreator = LemmyCreator(),
9+
@SerialName("post") val post: LemmyPost = LemmyPost(),
1010
)

0 commit comments

Comments
 (0)