Switched from Gson to Moshi converter, removed OkHttp dependency

pull/49/head
Arty Bishop 2020-10-03 15:55:15 +01:00
rodzic 75374ca4d9
commit ad194ba5df
6 zmienionych plików z 21 dodań i 22 usunięć

Wyświetl plik

@ -82,8 +82,7 @@ dependencies {
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
implementation "org.osmdroid:osmdroid-android:$openStreetMap_version"

Wyświetl plik

@ -24,7 +24,7 @@ import dagger.Module
import dagger.Provides
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.moshi.MoshiConverterFactory
import javax.inject.Singleton
@Module
@ -41,7 +41,7 @@ class NetworkModule {
fun provideTransApi(): TransmittersApi {
return Retrofit.Builder()
.baseUrl("https://db.satnogs.org/api/")
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(MoshiConverterFactory.create())
.build()
.create(TransmittersApi::class.java)
}

Wyświetl plik

@ -21,18 +21,18 @@ package com.rtbishop.look4sat.data
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.google.gson.annotations.SerializedName
import com.squareup.moshi.Json
@Entity(tableName = "transmitters")
data class SatTrans(
@PrimaryKey @SerializedName("uuid") val uuid: String,
@SerializedName("description") val description: String,
@SerializedName("alive") val isAlive: Boolean,
@SerializedName("uplink_low") val uplinkLow: Long?,
@SerializedName("uplink_high") val uplinkHigh: Long?,
@SerializedName("downlink_low") val downlinkLow: Long?,
@SerializedName("downlink_high") val downlinkHigh: Long?,
@SerializedName("mode") val mode: String?,
@SerializedName("invert") val isInverted: Boolean,
@SerializedName("norad_cat_id") val catNum: Int
@PrimaryKey @Json(name = "uuid") val uuid: String,
@Json(name = "description") val description: String,
@Json(name = "alive") val isAlive: Boolean,
@Json(name = "uplink_low") val uplinkLow: Long?,
@Json(name = "uplink_high") val uplinkHigh: Long?,
@Json(name = "downlink_low") val downlinkLow: Long?,
@Json(name = "downlink_high") val downlinkHigh: Long?,
@Json(name = "mode") val mode: String?,
@Json(name = "invert") val isInverted: Boolean,
@Json(name = "norad_cat_id") val catNum: Int
)

Wyświetl plik

@ -72,7 +72,7 @@ class DefaultRepository @Inject constructor(
val streams = mutableListOf<InputStream>()
sources.forEach { source ->
val request = Request.Builder().url(source.url).build()
val stream = client.newCall(request).execute().body?.byteStream()
val stream = client.newCall(request).execute().body()?.byteStream()
stream?.let { inputStream -> streams.add(inputStream) }
}
val importedEntries = mutableListOf<SatEntry>()

Wyświetl plik

@ -2,18 +2,19 @@ package com.rtbishop.look4sat.utility
import androidx.room.TypeConverter
import com.github.amsacode.predict4java.TLE
import com.google.gson.Gson
import com.squareup.moshi.Moshi
class Converters {
private val gSon = Gson()
private val jsonConverter = Moshi.Builder().build()
private val jsonAdapter = jsonConverter.adapter(TLE::class.java)
@TypeConverter
fun tleToString(tle: TLE): String {
return gSon.toJson(tle)
return jsonAdapter.toJson(tle)
}
@TypeConverter
fun tleFromString(string: String): TLE {
return gSon.fromJson(string, TLE::class.java)
fun tleFromString(string: String): TLE? {
return jsonAdapter.fromJson(string)
}
}

Wyświetl plik

@ -30,7 +30,6 @@ buildscript {
room_version = '2.2.5'
dagger_version = '2.29.1'
retrofit_version = '2.9.0'
okhttp_version = '4.9.0'
openStreetMap_version = '6.1.8'
predict4java_version = '1.3.1'
}