Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Switched from Gson to Moshi converter, removed OkHttp dependency

Arty Bishopad194ba5df8f
diff --git a/app/build.gradle b/app/build.gradle
index ad61dce8..e82f783b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -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"
diff --git a/app/src/main/java/com/rtbishop/look4sat/dagger/modules/NetworkModule.kt b/app/src/main/java/com/rtbishop/look4sat/dagger/modules/NetworkModule.kt
index 9faf4f02..beec93e6 100644
--- a/app/src/main/java/com/rtbishop/look4sat/dagger/modules/NetworkModule.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/dagger/modules/NetworkModule.kt
@@ -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)
}
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/SatTrans.kt b/app/src/main/java/com/rtbishop/look4sat/data/SatTrans.kt
index 441c9a48..555bbe53 100644
--- a/app/src/main/java/com/rtbishop/look4sat/data/SatTrans.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/data/SatTrans.kt
@@ -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
)
diff --git a/app/src/main/java/com/rtbishop/look4sat/repo/DefaultRepository.kt b/app/src/main/java/com/rtbishop/look4sat/repo/DefaultRepository.kt
index d2c73078..e78a334e 100644
--- a/app/src/main/java/com/rtbishop/look4sat/repo/DefaultRepository.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/repo/DefaultRepository.kt
@@ -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>()
diff --git a/app/src/main/java/com/rtbishop/look4sat/utility/Converters.kt b/app/src/main/java/com/rtbishop/look4sat/utility/Converters.kt
index b61cb63c..34f6a43b 100644
--- a/app/src/main/java/com/rtbishop/look4sat/utility/Converters.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/utility/Converters.kt
@@ -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)
}
}
diff --git a/build.gradle b/build.gradle
index f1376742..0f636919 100644
--- a/build.gradle
+++ b/build.gradle
@@ -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'
}