kopia lustrzana https://github.com/rt-bishop/Look4Sat
Switched from Gson to Moshi converter, removed OkHttp dependency
rodzic
75374ca4d9
commit
ad194ba5df
|
@ -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"
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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>()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue