mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-05 12:07:25 +00:00
Added Injector (Service Locator) object. Created minimal RemoteDataSource implementation.
This commit is contained in:
1 parent
3e7b07904a
commit
22616d0d2f
6 files changed
+57
-36
No files matched your search
@@ -0,0 +1,21 @@
|
|||||||
|
package com.rtbishop.lookingsat
|
||||||
|
|
||||||
|
import com.rtbishop.lookingsat.api.RemoteDataSource
|
||||||
|
import com.rtbishop.lookingsat.api.TransmittersApi
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
|
||||||
|
object Injector {
|
||||||
|
private fun provideRemoteDataSource(): RemoteDataSource {
|
||||||
|
val api = Retrofit.Builder()
|
||||||
|
.baseUrl("https://db.satnogs.org/api/")
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
.create(TransmittersApi::class.java)
|
||||||
|
|
||||||
|
val client = OkHttpClient()
|
||||||
|
|
||||||
|
return RemoteDataSource(api, client)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.rtbishop.lookingsat.api
|
||||||
|
|
||||||
|
import com.rtbishop.lookingsat.repo.Transmitter
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.SequenceInputStream
|
||||||
|
|
||||||
|
private const val TLE_AMATEUR = "https://celestrak.com/NORAD/elements/amateur.txt"
|
||||||
|
private const val TLE_WEATHER = "https://celestrak.com/NORAD/elements/weather.txt"
|
||||||
|
|
||||||
|
class RemoteDataSource(private val api: TransmittersApi, private val client: OkHttpClient) {
|
||||||
|
private val requestAmateur = Request.Builder().url(TLE_AMATEUR).build()
|
||||||
|
private val requestWeather = Request.Builder().url(TLE_WEATHER).build()
|
||||||
|
|
||||||
|
suspend fun fetchTleFiles(): InputStream {
|
||||||
|
val streamAmateur = client.newCall(requestAmateur).execute().body()?.byteStream()
|
||||||
|
val streamWeather = client.newCall(requestWeather).execute().body()?.byteStream()
|
||||||
|
return SequenceInputStream(streamAmateur, streamWeather)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun fetchTransmitters(): List<Transmitter> {
|
||||||
|
return api.fetchTransmittersList()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.rtbishop.lookingsat.api
|
|
||||||
|
|
||||||
import com.rtbishop.lookingsat.repo.Transmitter
|
|
||||||
import retrofit2.Retrofit
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
|
||||||
import retrofit2.http.GET
|
|
||||||
|
|
||||||
interface TransmitterApi {
|
|
||||||
|
|
||||||
@GET("transmitters/?alive=true")
|
|
||||||
suspend fun getTransmitterList(): List<Transmitter>
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
operator fun invoke(): TransmitterApi {
|
|
||||||
return Retrofit.Builder()
|
|
||||||
.baseUrl("https://db.satnogs.org/api/")
|
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
|
||||||
.build()
|
|
||||||
.create(TransmitterApi::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.rtbishop.lookingsat.api
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import com.rtbishop.lookingsat.repo.Transmitter
|
|
||||||
|
|
||||||
class TransmitterService(private val transmitterApi: TransmitterApi) {
|
|
||||||
private val _transmittersList = MutableLiveData<List<Transmitter>>()
|
|
||||||
val transmittersList: LiveData<List<Transmitter>> = _transmittersList
|
|
||||||
|
|
||||||
suspend fun fetchTransmitters() {
|
|
||||||
_transmittersList.postValue(transmitterApi.getTransmitterList())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.rtbishop.lookingsat.api
|
||||||
|
|
||||||
|
import com.rtbishop.lookingsat.repo.Transmitter
|
||||||
|
import retrofit2.http.GET
|
||||||
|
|
||||||
|
interface TransmittersApi {
|
||||||
|
|
||||||
|
@GET("transmitters/")
|
||||||
|
suspend fun fetchTransmittersList(): List<Transmitter>
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import com.google.gson.annotations.SerializedName
|
|||||||
data class Transmitter(
|
data class Transmitter(
|
||||||
@PrimaryKey @SerializedName("uuid") val uuid: String,
|
@PrimaryKey @SerializedName("uuid") val uuid: String,
|
||||||
@SerializedName("description") val description: String,
|
@SerializedName("description") val description: String,
|
||||||
|
@SerializedName("alive") val isAlive: Boolean,
|
||||||
@SerializedName("uplink_low") val uplinkLow: Long?,
|
@SerializedName("uplink_low") val uplinkLow: Long?,
|
||||||
@SerializedName("uplink_high") val uplinkHigh: Long?,
|
@SerializedName("uplink_high") val uplinkHigh: Long?,
|
||||||
@SerializedName("downlink_low") val downlinkLow: Long?,
|
@SerializedName("downlink_low") val downlinkLow: Long?,
|
||||||
|
|||||||
Reference in new issue
Block a user