mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added DataParser.kt with tests, removed unused classes
This commit is contained in:
1 parent
c8f7a29812
commit
5998a7e66d
19 files changed
+285
-346
No files matched your search
@@ -71,10 +71,6 @@ dependencies {
|
||||
implementation "com.google.dagger:hilt-android:$hilt_version"
|
||||
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
|
||||
|
||||
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
|
||||
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
|
||||
|
||||
implementation "org.osmdroid:osmdroid-android:$osmdroid_version"
|
||||
implementation "com.jakewharton.timber:timber:$timber_version"
|
||||
|
||||
|
||||
@@ -26,15 +26,11 @@ import com.rtbishop.look4sat.framework.model.Transmitter as FrameworkTransmitter
|
||||
|
||||
fun DomainEntry.toFramework() = FrameworkEntry(this.tle, this.isSelected)
|
||||
|
||||
fun DomainItem.toFramework() = FrameworkItem(this.catnum, this.name, this.isSelected, this.modes)
|
||||
|
||||
fun DomainTransmitter.toFramework() = FrameworkTransmitter(
|
||||
this.uuid, this.info, this.isAlive, this.downlink,
|
||||
this.uplink, this.mode, this.isInverted, this.catnum
|
||||
)
|
||||
|
||||
fun FrameworkEntry.toDomain() = DomainEntry(this.tle, this.isSelected)
|
||||
|
||||
fun FrameworkItem.toDomain() = DomainItem(this.catnum, this.name, this.isSelected, this.modes)
|
||||
|
||||
fun FrameworkTransmitter.toDomain() = DomainTransmitter(
|
||||
@@ -44,12 +40,8 @@ fun FrameworkTransmitter.toDomain() = DomainTransmitter(
|
||||
|
||||
fun List<DomainEntry>.toFrameworkEntries() = this.map { it.toFramework() }
|
||||
|
||||
fun List<DomainItem>.toFrameworkItems() = this.map { it.toFramework() }
|
||||
|
||||
fun List<DomainTransmitter>.toFramework() = this.map { it.toFramework() }
|
||||
|
||||
fun List<FrameworkEntry>.toDomainEntries() = this.map { it.toDomain() }
|
||||
|
||||
fun List<FrameworkItem>.toDomainItems() = this.map { it.toDomain() }
|
||||
|
||||
fun List<FrameworkTransmitter>.toDomain() = this.map { it.toDomain() }
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rtbishop.look4sat.framework.model
|
||||
|
||||
import com.rtbishop.look4sat.domain.predict.TLE
|
||||
import com.squareup.moshi.Json
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
data class OMM(
|
||||
@field:Json(name = "OBJECT_NAME") val name: String,
|
||||
@field:Json(name = "EPOCH") val epochString: String,
|
||||
@field:Json(name = "MEAN_MOTION") val meanmo: Double,
|
||||
@field:Json(name = "ECCENTRICITY") val eccn: Double,
|
||||
@field:Json(name = "INCLINATION") val incl: Double,
|
||||
@field:Json(name = "RA_OF_ASC_NODE") val raan: Double,
|
||||
@field:Json(name = "ARG_OF_PERICENTER") val argper: Double,
|
||||
@field:Json(name = "MEAN_ANOMALY") val meanan: Double,
|
||||
@field:Json(name = "NORAD_CAT_ID") val catnum: Int,
|
||||
@field:Json(name = "BSTAR") val bstar: Double,
|
||||
) {
|
||||
|
||||
fun toTLE(): TLE {
|
||||
calendar.time = sdf.parse(epochString) ?: Date()
|
||||
val year = calendar.get(Calendar.YEAR).toString().substring(2, 4)
|
||||
val day = calendar.get(Calendar.DAY_OF_YEAR)
|
||||
val hours = calendar.get(Calendar.HOUR_OF_DAY)
|
||||
val minutes = calendar.get(Calendar.MINUTE)
|
||||
val seconds = calendar.get(Calendar.SECOND)
|
||||
val fraction = ((hours * 60 * 60 + minutes * 60 + seconds) / secondsInDay).toString()
|
||||
val epoch = "$year$day${fraction.substring(1, fraction.length)}".toDouble()
|
||||
return TLE(name, epoch, meanmo, eccn, incl, raan, argper, meanan, catnum, bstar)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val secondsInDay = 86400.0
|
||||
private const val pattern = "yyyy-MM-dd'T'HH:mm:ss"
|
||||
private val calendar = Calendar.getInstance()
|
||||
private val sdf = SimpleDateFormat(pattern, Locale.US)
|
||||
}
|
||||
}
|
||||
@@ -19,16 +19,15 @@ package com.rtbishop.look4sat.framework.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
@Entity(tableName = "transmitters")
|
||||
data class Transmitter(
|
||||
@PrimaryKey @field:Json(name = "uuid") val uuid: String,
|
||||
@field:Json(name = "description") val info: String,
|
||||
@field:Json(name = "alive") val isAlive: Boolean,
|
||||
@field:Json(name = "downlink_low") var downlink: Long?,
|
||||
@field:Json(name = "uplink_low") var uplink: Long?,
|
||||
@field:Json(name = "mode") val mode: String?,
|
||||
@field:Json(name = "invert") val isInverted: Boolean,
|
||||
@field:Json(name = "norad_cat_id") val catnum: Int?
|
||||
@PrimaryKey val uuid: String,
|
||||
val info: String,
|
||||
val isAlive: Boolean,
|
||||
var downlink: Long?,
|
||||
var uplink: Long?,
|
||||
val mode: String?,
|
||||
val isInverted: Boolean,
|
||||
val catnum: Int?
|
||||
)
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.rtbishop.look4sat.framework.remote
|
||||
|
||||
import com.rtbishop.look4sat.data.RemoteDataSource
|
||||
import com.rtbishop.look4sat.domain.model.Transmitter
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
|
||||
class DefaultRemoteSource(private val dispatcher: CoroutineDispatcher) : RemoteDataSource {
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
override suspend fun fetchFileStream(url: String): InputStream? = withContext(dispatcher) {
|
||||
return@withContext URL(url).openStream()
|
||||
}
|
||||
|
||||
override suspend fun fetchTransmitters(url: String): List<Transmitter> {
|
||||
val stream = URL(url).openStream()
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private suspend fun download(url: String): InputStream? = withContext(dispatcher) {
|
||||
return@withContext try {
|
||||
URL(url).openStream().bufferedReader().useLines { lines ->
|
||||
lines.forEachIndexed { index, line ->
|
||||
val items = line.split(",")
|
||||
}
|
||||
}
|
||||
null
|
||||
} catch (e: Exception) {
|
||||
return@withContext null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.rtbishop.look4sat.framework.remote
|
||||
|
||||
import com.rtbishop.look4sat.data.RemoteDataSource
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
|
||||
class RemoteSource(private val ioDispatcher: CoroutineDispatcher) : RemoteDataSource {
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
override suspend fun fetchFileStream(fileUrl: String): InputStream {
|
||||
return withContext(ioDispatcher) { URL(fileUrl).openStream() }
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rtbishop.look4sat.framework.remote
|
||||
|
||||
import com.rtbishop.look4sat.data.RemoteDataSource
|
||||
import com.rtbishop.look4sat.domain.model.Transmitter
|
||||
import com.rtbishop.look4sat.framework.toDomain
|
||||
import java.io.InputStream
|
||||
|
||||
class RetrofitRemoteSource(private val satelliteApi: SatelliteApi) : RemoteDataSource {
|
||||
|
||||
override suspend fun fetchFileStream(url: String): InputStream? {
|
||||
return satelliteApi.fetchFileStream(url).body()?.byteStream()
|
||||
}
|
||||
|
||||
override suspend fun fetchTransmitters(url: String): List<Transmitter> {
|
||||
return satelliteApi.fetchTransmitters(url).toDomain()
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rtbishop.look4sat.framework.remote
|
||||
|
||||
import com.rtbishop.look4sat.framework.model.Transmitter
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Streaming
|
||||
import retrofit2.http.Url
|
||||
|
||||
interface SatelliteApi {
|
||||
|
||||
@Streaming
|
||||
@GET
|
||||
suspend fun fetchFileStream(@Url url: String): Response<ResponseBody>
|
||||
|
||||
@GET
|
||||
suspend fun fetchTransmitters(@Url url: String): List<Transmitter>
|
||||
}
|
||||
@@ -23,17 +23,11 @@ import android.content.SharedPreferences
|
||||
import android.hardware.SensorManager
|
||||
import android.location.LocationManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.room.Room
|
||||
import com.rtbishop.look4sat.framework.local.*
|
||||
import com.rtbishop.look4sat.framework.remote.SatelliteApi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
|
||||
@@ -20,11 +20,12 @@ package com.rtbishop.look4sat.injection
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import com.rtbishop.look4sat.data.DefaultRepository
|
||||
import com.rtbishop.look4sat.domain.DataParser
|
||||
import com.rtbishop.look4sat.domain.DataRepository
|
||||
import com.rtbishop.look4sat.domain.DataReporter
|
||||
import com.rtbishop.look4sat.domain.predict.Predictor
|
||||
import com.rtbishop.look4sat.framework.local.*
|
||||
import com.rtbishop.look4sat.framework.remote.DefaultRemoteSource
|
||||
import com.rtbishop.look4sat.framework.remote.RemoteSource
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
@@ -41,17 +42,15 @@ object CoreModule {
|
||||
@Singleton
|
||||
fun provideSatelliteRepo(
|
||||
@ApplicationContext context: Context,
|
||||
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@DefaultDispatcher defaultDispatcher: CoroutineDispatcher
|
||||
): DataRepository {
|
||||
val dataParser = DataParser(defaultDispatcher)
|
||||
val db = Room.databaseBuilder(context, SatelliteDb::class.java, "SatelliteDb")
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4).build()
|
||||
val roomLocalSource = LocalSource(db.entriesDao(), db.sourcesDao(), db.transmittersDao())
|
||||
// val satelliteApi = Retrofit.Builder().baseUrl("https://localhost")
|
||||
// .addConverterFactory(MoshiConverterFactory.create()).build()
|
||||
// .create(SatelliteApi::class.java)
|
||||
// val retrofitRemoteSource = RetrofitRemoteSource(satelliteApi)
|
||||
val defaultRemoteSource = DefaultRemoteSource(dispatcher)
|
||||
return DefaultRepository(roomLocalSource, defaultRemoteSource, dispatcher)
|
||||
val localSource = LocalSource(db.entriesDao(), db.sourcesDao(), db.transmittersDao())
|
||||
val remoteSource = RemoteSource(ioDispatcher)
|
||||
return DefaultRepository(dataParser, localSource, remoteSource, ioDispatcher)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
Reference in new issue
Block a user