Skip to content

Commit

Permalink
Fix Moshi Proguard error (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
firemaples authored Sep 25, 2023
1 parent 2f97303 commit ad30c9c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tw.firemaples.onscreenocr.translator.azure

import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName
import com.squareup.moshi.Json
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.Header
Expand Down Expand Up @@ -32,7 +32,7 @@ interface MicrosoftAzureAPIService {

@Keep
data class TranslateRequest(
@SerializedName("Text")
@Json(name = "Text")
val text: String
) {
companion object {
Expand All @@ -42,24 +42,24 @@ data class TranslateRequest(

@Keep
data class TranslateResponse(
@SerializedName("detectedLanguage")
@Json(name = "detectedLanguage")
val detectedLanguage: DetectedLanguage,
@SerializedName("translations")
@Json(name = "translations")
val translations: List<Translation>,
)

@Keep
data class DetectedLanguage(
@SerializedName("language")
@Json(name = "language")
val language: String,
@SerializedName("score")
@Json(name = "score")
val score: Float,
)

@Keep
data class Translation(
@SerializedName("text")
@Json(name = "text")
val text: String,
@SerializedName("to")
@Json(name = "to")
val to: String,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tw.firemaples.onscreenocr.translator.mymemory

import com.google.errorprone.annotations.Keep
import com.google.gson.annotations.SerializedName
import com.squareup.moshi.Json
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
Expand All @@ -17,38 +17,47 @@ interface MyMemoryAPIService {

@Keep
data class ResponseData(
@SerializedName("translatedText") val translatedText: String,
@SerializedName("match") val match: Float?,
@Json(name = "translatedText")
val translatedText: String,
@Json(name = "match")
val match: Float?,
)

//@Keep
//data class Match(
// @SerializedName("id") val id: String,
// @SerializedName("segment") val segment: String,
// @SerializedName("translation") val translation: String,
// @SerializedName("source") val source: String,
// @SerializedName("target") val target: String,
// @SerializedName("quality") val quality: Int,
// @SerializedName("reference") val reference: Any?,
// @SerializedName("usageCount") val usageCount: Int,
// @SerializedName("subject") val subject: String?,
// @SerializedName("createdBy") val createdBy: String?,
// @SerializedName("lastUpdatedBy") val lastUpdatedBy: String?,
// @SerializedName("createDate") val createDate: String,
// @SerializedName("lastUpdateDate") val lastUpdateDate: String,
// @SerializedName("match") val match: Float,
// @Json(name = "id") val id: String,
// @Json(name = "segment") val segment: String,
// @Json(name = "translation") val translation: String,
// @Json(name = "source") val source: String,
// @Json(name = "target") val target: String,
// @Json(name = "quality") val quality: Int,
// @Json(name = "reference") val reference: Any?,
// @Json(name = "usageCount") val usageCount: Int,
// @Json(name = "subject") val subject: String?,
// @Json(name = "createdBy") val createdBy: String?,
// @Json(name = "lastUpdatedBy") val lastUpdatedBy: String?,
// @Json(name = "createDate") val createDate: String,
// @Json(name = "lastUpdateDate") val lastUpdateDate: String,
// @Json(name = "match") val match: Float,
//)

@Keep
data class TranslateResponse(
@SerializedName("responseData") val responseData: ResponseData,
@SerializedName("quotaFinished") val quotaFinished: Boolean?,
@SerializedName("mtLangSupported") val mtLangSupported: Any?,
@SerializedName("responseDetails") val responseDetails: String,
@SerializedName("responseStatus") val responseStatus: Any?, // this field can be a number or string
@SerializedName("responderId") val responderId: Any?,
@SerializedName("exceptionCode") val exceptionCode: Any?,
// @SerializedName("matches") val matches: List<Match>, // this field can be an empty string while the API failed
@Json(name = "responseData")
val responseData: ResponseData,
@Json(name = "quotaFinished")
val quotaFinished: Boolean?,
@Json(name = "mtLangSupported")
val mtLangSupported: Any?,
@Json(name = "responseDetails")
val responseDetails: String,
@Json(name = "responseStatus")
val responseStatus: Any?, // this field can be a number or string
@Json(name = "responderId")
val responderId: Any?,
@Json(name = "exceptionCode")
val exceptionCode: Any?,
// @Json(name = "matches") val matches: List<Match>, // this field can be an empty string while the API failed
) {
fun isSuccess(): Boolean = responseStatus.toString().toDoubleOrNull() == 200.0
}

0 comments on commit ad30c9c

Please sign in to comment.