Switched from Gson to Moshi converter, removed OkHttp dependency

This commit is contained in:
Arty Bishop committed 2020-10-06 23:24:17 +01:00
1 parent 75374ca4d9
commit ad194ba5df
6 files changed
+21 -22

No files matched your search

+1 -2
View File
@@ -82,8 +82,7 @@ dependencies {
kapt "com.google.dagger:dagger-compiler:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version" implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version" implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "org.osmdroid:osmdroid-android:$openStreetMap_version" implementation "org.osmdroid:osmdroid-android:$openStreetMap_version"
@@ -24,7 +24,7 @@ import dagger.Module
import dagger.Provides import dagger.Provides
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.moshi.MoshiConverterFactory
import javax.inject.Singleton import javax.inject.Singleton
@Module @Module
@@ -41,7 +41,7 @@ class NetworkModule {
fun provideTransApi(): TransmittersApi { fun provideTransApi(): TransmittersApi {
return Retrofit.Builder() return Retrofit.Builder()
.baseUrl("https://db.satnogs.org/api/") .baseUrl("https://db.satnogs.org/api/")
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(MoshiConverterFactory.create())
.build() .build()
.create(TransmittersApi::class.java) .create(TransmittersApi::class.java)
} }
@@ -21,18 +21,18 @@ package com.rtbishop.look4sat.data
import androidx.room.Entity import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import com.google.gson.annotations.SerializedName import com.squareup.moshi.Json
@Entity(tableName = "transmitters") @Entity(tableName = "transmitters")
data class SatTrans( data class SatTrans(
@PrimaryKey @SerializedName("uuid") val uuid: String, @PrimaryKey @Json(name = "uuid") val uuid: String,
@SerializedName("description") val description: String, @Json(name = "description") val description: String,
@SerializedName("alive") val isAlive: Boolean, @Json(name = "alive") val isAlive: Boolean,
@SerializedName("uplink_low") val uplinkLow: Long?, @Json(name = "uplink_low") val uplinkLow: Long?,
@SerializedName("uplink_high") val uplinkHigh: Long?, @Json(name = "uplink_high") val uplinkHigh: Long?,
@SerializedName("downlink_low") val downlinkLow: Long?, @Json(name = "downlink_low") val downlinkLow: Long?,
@SerializedName("downlink_high") val downlinkHigh: Long?, @Json(name = "downlink_high") val downlinkHigh: Long?,
@SerializedName("mode") val mode: String?, @Json(name = "mode") val mode: String?,
@SerializedName("invert") val isInverted: Boolean, @Json(name = "invert") val isInverted: Boolean,
@SerializedName("norad_cat_id") val catNum: Int @Json(name = "norad_cat_id") val catNum: Int
) )
@@ -72,7 +72,7 @@ class DefaultRepository @Inject constructor(
val streams = mutableListOf<InputStream>() val streams = mutableListOf<InputStream>()
sources.forEach { source -> sources.forEach { source ->
val request = Request.Builder().url(source.url).build() 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) } stream?.let { inputStream -> streams.add(inputStream) }
} }
val importedEntries = mutableListOf<SatEntry>() val importedEntries = mutableListOf<SatEntry>()
@@ -2,18 +2,19 @@ package com.rtbishop.look4sat.utility
import androidx.room.TypeConverter import androidx.room.TypeConverter
import com.github.amsacode.predict4java.TLE import com.github.amsacode.predict4java.TLE
import com.google.gson.Gson import com.squareup.moshi.Moshi
class Converters { class Converters {
private val gSon = Gson() private val jsonConverter = Moshi.Builder().build()
private val jsonAdapter = jsonConverter.adapter(TLE::class.java)
@TypeConverter @TypeConverter
fun tleToString(tle: TLE): String { fun tleToString(tle: TLE): String {
return gSon.toJson(tle) return jsonAdapter.toJson(tle)
} }
@TypeConverter @TypeConverter
fun tleFromString(string: String): TLE { fun tleFromString(string: String): TLE? {
return gSon.fromJson(string, TLE::class.java) return jsonAdapter.fromJson(string)
} }
} }
-1
View File
@@ -30,7 +30,6 @@ buildscript {
room_version = '2.2.5' room_version = '2.2.5'
dagger_version = '2.29.1' dagger_version = '2.29.1'
retrofit_version = '2.9.0' retrofit_version = '2.9.0'
okhttp_version = '4.9.0'
openStreetMap_version = '6.1.8' openStreetMap_version = '6.1.8'
predict4java_version = '1.3.1' predict4java_version = '1.3.1'
} }