Skip to content

Commit

Permalink
Use moshi codegen for release, update proguard
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Sep 10, 2019
1 parent f4f865d commit ab99b37
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ buildscript {
ext.lifecycle_version = '2.0.0'
ext.material_version = '1.0.0'
ext.mockito_version = '2.18.3'
ext.moshi_version = '1.6.0'
ext.moshi_version = '1.8.0'
ext.okhttp3_version = '4.1.0'
ext.realm_version = '5.8.0'
ext.realm_adapters_version = '3.1.0'
Expand Down
22 changes: 15 additions & 7 deletions data/src/main/java/com/moez/QKSMS/manager/ChangelogManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.content.Context
import com.moez.QKSMS.common.util.extensions.versionCode
import com.moez.QKSMS.util.Preferences
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.squareup.moshi.Moshi
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
Expand Down Expand Up @@ -88,35 +89,42 @@ class ChangelogManagerImpl @Inject constructor(
prefs.changelogVersion.set(context.versionCode)
}

private data class ChangelogResponse(
@JsonClass(generateAdapter = true)
data class ChangelogResponse(
@Json(name = "documents") val documents: List<Document>
)

private data class Document(
@JsonClass(generateAdapter = true)
data class Document(
@Json(name = "fields") val fields: Changelog
)

private data class Changelog(
@JsonClass(generateAdapter = true)
data class Changelog(
@Json(name = "added") val added: ArrayField?,
@Json(name = "improved") val improved: ArrayField?,
@Json(name = "fixed") val fixed: ArrayField?,
@Json(name = "versionName") val versionName: StringField,
@Json(name = "versionCode") val versionCode: IntegerField
)

private data class ArrayField(
@JsonClass(generateAdapter = true)
data class ArrayField(
@Json(name = "arrayValue") val value: ArrayValues
)

private data class ArrayValues(
@JsonClass(generateAdapter = true)
data class ArrayValues(
@Json(name = "values") val values: List<StringField>
)

private data class StringField(
@JsonClass(generateAdapter = true)
data class StringField(
@Json(name = "stringValue") val value: String
)

private data class IntegerField(
@JsonClass(generateAdapter = true)
data class IntegerField(
@Json(name = "integerValue") val value: String
)

Expand Down
6 changes: 5 additions & 1 deletion presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@ dependencies {
testImplementation "junit:junit:$junit_version"
testImplementation "org.mockito:mockito-core:$mockito_version"

// moshi
implementation "com.squareup.moshi:moshi:$moshi_version"
debugImplementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
kaptRelease "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"

implementation "com.android.billingclient:billing:1.0"
implementation "com.github.chrisbanes:PhotoView:2.0.0"
implementation "com.f2prateek.rx.preferences2:rx-preferences:$rx_preferences_version"
implementation "com.google.android:flexbox:0.3.1"
implementation "com.jakewharton.timber:timber:$timber_version"
implementation "com.squareup.moshi:moshi:$moshi_version"
implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
implementation "me.leolin:ShortcutBadger:1.1.21"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
62 changes: 62 additions & 0 deletions presentation/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# okio
-dontwarn okio.**

# okhttp3
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

Expand All @@ -28,3 +29,64 @@

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform

# moshi
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

-keepclasseswithmembers class * {
@com.squareup.moshi.* <methods>;
}

-keep @com.squareup.moshi.JsonQualifier interface *

# Enum field names are used by the integrated EnumJsonAdapter.
# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi.
-keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum {
<fields>;
}

# The name of @JsonClass types is used to look up the generated adapter.
-keepnames @com.squareup.moshi.JsonClass class *

# Retain generated target class's synthetic defaults constructor and keep DefaultConstructorMarker's
# name. We will look this up reflectively to invoke the type's constructor.
#
# We can't _just_ keep the defaults constructor because Proguard/R8's spec doesn't allow wildcard
# matching preceding parameters.
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
-keepclassmembers @com.squareup.moshi.JsonClass class * {
<init>(...);
}

# Retain generated JsonAdapters if annotated type is retained.
-if @com.squareup.moshi.JsonClass class *
-keep class <1>JsonAdapter {
<init>(...);
<fields>;
}
-if @com.squareup.moshi.JsonClass class **$*
-keep class <1>_<2>JsonAdapter {
<init>(...);
<fields>;
}
-if @com.squareup.moshi.JsonClass class **$*$*
-keep class <1>_<2>_<3>JsonAdapter {
<init>(...);
<fields>;
}
-if @com.squareup.moshi.JsonClass class **$*$*$*
-keep class <1>_<2>_<3>_<4>JsonAdapter {
<init>(...);
<fields>;
}
-if @com.squareup.moshi.JsonClass class **$*$*$*$*
-keep class <1>_<2>_<3>_<4>_<5>JsonAdapter {
<init>(...);
<fields>;
}
-if @com.squareup.moshi.JsonClass class **$*$*$*$*$*
-keep class <1>_<2>_<3>_<4>_<5>_<6>JsonAdapter {
<init>(...);
<fields>;
}
1 change: 1 addition & 0 deletions presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.CALL_PHONE" />
<!-- Used for starting foreground service for backup/restore on Android P+ -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Expand Down

0 comments on commit ab99b37

Please sign in to comment.