Moved and renamed several classes

This commit is contained in:
Arty Bishop committed 2021-10-27 21:47:02 +01:00
1 parent 6fa63fdcff
commit 55a827330f
59 files changed
+383 -322

No files matched your search

@@ -0,0 +1,28 @@
/*
* 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.common
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,25 @@
/*
* 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.common
sealed class DataState<out T> {
data class Success<out T>(val data: T) : DataState<T>()
data class Error(val error: Throwable) : DataState<Nothing>()
object Empty : DataState<Nothing>()
object Loading : DataState<Nothing>()
}
@@ -17,9 +17,12 @@
*/
package com.rtbishop.look4sat.data
import com.rtbishop.look4sat.domain.Transmitter
import com.rtbishop.look4sat.domain.Satellite
import com.rtbishop.look4sat.domain.TLE
import com.rtbishop.look4sat.domain.Repository
import com.rtbishop.look4sat.model.SatEntry
import com.rtbishop.look4sat.model.SatItem
import com.rtbishop.look4sat.model.Transmitter
import com.rtbishop.look4sat.predict4kotlin.Satellite
import com.rtbishop.look4sat.predict4kotlin.TLE
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
@@ -28,38 +31,29 @@ import kotlinx.coroutines.withContext
import java.io.InputStream
import java.util.zip.ZipInputStream
class SatelliteRepo(
private val preferences: Preferences,
private val localSource: LocalSource,
private val remoteSource: RemoteSource,
class DataRepository(
private val localSource: LocalDataSource,
private val remoteSource: RemoteDataSource,
private val repoDispatcher: CoroutineDispatcher
) {
) : Repository {
fun saveSelectedModes(modes: List<String>) {
preferences.saveModesSelection(modes)
}
fun loadSelectedModes(): List<String> {
return preferences.loadModesSelection()
}
fun getSatItems(): Flow<List<SatItem>> {
override fun getSatItems(): Flow<List<SatItem>> {
return localSource.getEntriesWithModes()
}
fun getSatTransmitters(catNum: Int): Flow<List<Transmitter>> {
override fun getSatTransmitters(catNum: Int): Flow<List<Transmitter>> {
return localSource.getTransmitters(catNum)
}
suspend fun getSelectedSatellites(): List<Satellite> {
override suspend fun getSelectedSatellites(): List<Satellite> {
return localSource.getSelectedSatellites()
}
suspend fun updateEntriesFromFile(stream: InputStream) = withContext(repoDispatcher) {
override suspend fun updateEntriesFromFile(stream: InputStream) = withContext(repoDispatcher) {
localSource.updateEntries(importSatEntries(stream))
}
suspend fun updateEntriesFromWeb(sources: List<String>) {
override suspend fun updateEntriesFromWeb(sources: List<String>) {
coroutineScope {
launch(repoDispatcher) {
val streams = mutableListOf<InputStream>()
@@ -84,7 +78,7 @@ class SatelliteRepo(
}
}
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean) {
override suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean) {
localSource.updateEntriesSelection(catNums, isSelected)
}
@@ -17,11 +17,13 @@
*/
package com.rtbishop.look4sat.data
import com.rtbishop.look4sat.domain.Transmitter
import com.rtbishop.look4sat.domain.Satellite
import com.rtbishop.look4sat.model.SatEntry
import com.rtbishop.look4sat.model.SatItem
import com.rtbishop.look4sat.model.Transmitter
import com.rtbishop.look4sat.predict4kotlin.Satellite
import kotlinx.coroutines.flow.Flow
interface LocalSource {
interface LocalDataSource {
fun getEntriesWithModes(): Flow<List<SatItem>>
@@ -1,63 +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.data
import com.rtbishop.look4sat.domain.GeoPos
interface Preferences {
fun positionToQTH(lat: Double, lon: Double): String?
fun loadStationPosition(): GeoPos
fun saveStationPosition(pos: GeoPos)
fun updatePositionFromGPS(): Boolean
fun updatePositionFromQTH(qthString: String): Boolean
fun getMagDeclination(): Float
fun getHoursAhead(): Int
fun getMinElevation(): Double
fun shouldUseTextLabels(): Boolean
fun shouldUseUTC(): Boolean
fun shouldUseCompass(): Boolean
fun shouldShowSweep(): Boolean
fun isSetupDone(): Boolean
fun setSetupDone()
fun saveModesSelection(modes: List<String>)
fun loadModesSelection(): List<String>
fun getRotatorServer(): Pair<String, Int>?
fun loadTleSources(): List<String>
fun saveTleSources(sources: List<String>)
fun loadDefaultSources(): List<String>
}
@@ -17,10 +17,10 @@
*/
package com.rtbishop.look4sat.data
import com.rtbishop.look4sat.domain.Transmitter
import com.rtbishop.look4sat.model.Transmitter
import java.io.InputStream
interface RemoteSource {
interface RemoteDataSource {
suspend fun fetchFileStream(url: String): InputStream?
@@ -1,3 +1,20 @@
/*
* 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
import kotlinx.coroutines.CoroutineDispatcher
@@ -5,7 +22,7 @@ import kotlinx.coroutines.withContext
import java.io.BufferedWriter
import java.net.Socket
class PassReporter(private val reporterDispatcher: CoroutineDispatcher) {
class DataReporter(private val reporterDispatcher: CoroutineDispatcher) {
private var radioSocket: Socket? = null
private var radioWriter: BufferedWriter? = null
@@ -17,6 +17,7 @@
*/
package com.rtbishop.look4sat.domain
import com.rtbishop.look4sat.predict4kotlin.GeoPos
import kotlin.math.round
object QthConverter {
@@ -0,0 +1,39 @@
/*
* 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
import com.rtbishop.look4sat.model.SatItem
import com.rtbishop.look4sat.model.Transmitter
import com.rtbishop.look4sat.predict4kotlin.Satellite
import kotlinx.coroutines.flow.Flow
import java.io.InputStream
interface Repository {
fun getSatItems(): Flow<List<SatItem>>
fun getSatTransmitters(catNum: Int): Flow<List<Transmitter>>
suspend fun getSelectedSatellites(): List<Satellite>
suspend fun updateEntriesFromFile(stream: InputStream)
suspend fun updateEntriesFromWeb(sources: List<String>)
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean)
}
@@ -0,0 +1,31 @@
/*
* 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.model
data class OMM(
val name: String,
val epochString: String,
val meanmo: Double,
val eccn: Double,
val incl: Double,
val raan: Double,
val argper: Double,
val meanan: Double,
val catnum: Int,
val bstar: Double,
)
@@ -15,9 +15,9 @@
* 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.data
package com.rtbishop.look4sat.model
import com.rtbishop.look4sat.domain.TLE
import com.rtbishop.look4sat.predict4kotlin.TLE
data class SatEntry(
val tle: TLE,
@@ -15,7 +15,7 @@
* 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.data
package com.rtbishop.look4sat.model
data class SatItem(
val catNum: Int,
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.model
data class Transmitter(
val uuid: String,
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
import kotlin.math.*
@@ -15,6 +15,6 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
data class GeoPos(val latitude: Double, val longitude: Double, val altitude: Double = 0.0)
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
import kotlin.math.*
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
import com.rtbishop.look4sat.domain.*
import kotlinx.coroutines.CoroutineDispatcher
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
data class SatPass(
val aosTime: Long,
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
import kotlin.math.*
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
import java.util.*
import java.util.concurrent.atomic.AtomicReference
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.predict4kotlin
import java.io.InputStream
import kotlin.math.pow
@@ -0,0 +1,24 @@
/*
* 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.usecases
import com.rtbishop.look4sat.domain.Repository
class GetSelectedSatellites(private val dataRepository: Repository) {
suspend operator fun invoke() = dataRepository.getSelectedSatellites()
}
@@ -15,9 +15,8 @@
* 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
package com.rtbishop.look4sat.domain
import com.rtbishop.look4sat.domain.QthConverter
import org.junit.Test
class QthConverterTest {
@@ -1,6 +1,22 @@
package com.rtbishop.look4sat
/*
* 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.predict4kotlin
import com.rtbishop.look4sat.domain.TLE
import org.junit.Test
class TleParserTest {