Moved sources urls to database storage

This commit is contained in:
Arty Bishop committed 2021-10-27 21:47:02 +01:00
1 parent af7e027350
commit 5f4c63ee49
27 files changed
+418 -137

No files matched your search

@@ -45,6 +45,22 @@ class DataRepository(
return localSource.getTransmitters(catNum)
}
override fun getDefaultSources(): List<String> {
return listOf(
"https://celestrak.com/NORAD/elements/active.txt",
"https://amsat.org/tle/current/nasabare.txt",
"https://www.prismnet.com/~mmccants/tles/classfd.zip",
"https://www.prismnet.com/~mmccants/tles/inttles.zip"
)
}
override suspend fun getSavedSources(): List<String> {
val savedSources = localSource.getSources()
return if (savedSources.isEmpty()) {
getDefaultSources()
} else savedSources
}
override suspend fun getSelectedSatellites(): List<Satellite> {
return localSource.getSelectedSatellites()
}
@@ -55,6 +71,9 @@ class DataRepository(
override suspend fun updateEntriesFromWeb(sources: List<String>) {
coroutineScope {
launch(repoDispatcher) {
localSource.updateSources(sources)
}
launch(repoDispatcher) {
val streams = mutableListOf<InputStream>()
val entries = mutableListOf<SatEntry>()
@@ -29,11 +29,15 @@ interface LocalDataSource {
fun getTransmitters(catNum: Int): Flow<List<Transmitter>>
suspend fun getSources(): List<String>
suspend fun getSelectedSatellites(): List<Satellite>
suspend fun updateEntries(entries: List<SatEntry>)
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean)
suspend fun updateSources(sources: List<String>)
suspend fun updateTransmitters(transmitters: List<Transmitter>)
}
@@ -1,27 +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.domain
object Constants {
const val URL_BASE = "https://db.satnogs.org/api/"
const val URL_CELESTRAK = "https://celestrak.com/NORAD/elements/active.txt"
const val URL_AMSAT = "https://amsat.org/tle/current/nasabare.txt"
const val URL_PRISM_CLASSFD = "https://www.prismnet.com/~mmccants/tles/classfd.zip"
const val URL_PRISM_INTEL = "https://www.prismnet.com/~mmccants/tles/inttles.zip"
}
@@ -0,0 +1,9 @@
package com.rtbishop.look4sat.domain
import com.rtbishop.look4sat.domain.predict.GeoPos
import kotlinx.coroutines.flow.SharedFlow
interface LocationProvider {
val updatedLocation: SharedFlow<GeoPos?>
}
@@ -52,15 +52,15 @@ object QthConverter {
return "$lonFirst$latFirst$lonSecond$latSecond$lonThird$latThird"
}
fun isValidPosition(lat: Double, lon: Double): Boolean {
return (lat > -90.0 && lat < 90.0) && (lon > -180.0 && lon < 360.0)
}
private fun isValidQth(qthString: String): Boolean {
val qthPattern = "[a-xA-X][a-xA-X][0-9][0-9][a-xA-X][a-xA-X]".toRegex()
return qthString.matches(qthPattern)
}
private fun isValidPosition(lat: Double, lon: Double): Boolean {
return (lat > -90.0 && lat < 90.0) && (lon > -180.0 && lon < 360.0)
}
private fun Double.roundToDecimals(decimals: Int): Double {
var multiplier = 1.0
repeat(decimals) { multiplier *= 10 }
@@ -29,6 +29,10 @@ interface SatelliteRepo {
fun getSatTransmitters(catNum: Int): Flow<List<Transmitter>>
fun getDefaultSources(): List<String>
suspend fun getSavedSources(): List<String>
suspend fun getSelectedSatellites(): List<Satellite>
suspend fun updateEntriesFromFile(stream: InputStream)
@@ -17,4 +17,4 @@
*/
package com.rtbishop.look4sat.domain.predict
data class GeoPos(val latitude: Double, val longitude: Double, val altitude: Double = 0.0)
data class GeoPos(val latitude: Double, val longitude: Double, val name: String? = null)
@@ -168,10 +168,10 @@ abstract class Satellite(val params: TLE) {
val c =
invert(sqrt(1.0 + flatFactor * (flatFactor - 2) * sqr(sin(deg2Rad * gsPos.latitude))))
val sq = sqr(1.0 - flatFactor) * c
val achcp = (earthRadius * c + gsPos.altitude / 1000.0) * cos(deg2Rad * gsPos.latitude)
val achcp = (earthRadius * c) * cos(deg2Rad * gsPos.latitude)
obsPos.setXYZ(
achcp * cos(gsPosTheta.get()), achcp * sin(gsPosTheta.get()),
(earthRadius * sq + gsPos.altitude / 1000.0) * sin(deg2Rad * gsPos.latitude)
(earthRadius * sq) * sin(deg2Rad * gsPos.latitude)
)
obsVel.setXYZ(-mFactor * obsPos.y, mFactor * obsPos.x, 0.0)
magnitude(obsPos)