Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Added zipped TLE import from Mike McCants' web site

Arty Bishop44910389e3c6
diff --git a/app/src/main/java/com/rtbishop/look4sat/repository/PrefsRepo.kt b/app/src/main/java/com/rtbishop/look4sat/repository/PrefsRepo.kt
index 12e419cd..363a72d4 100644
--- a/app/src/main/java/com/rtbishop/look4sat/repository/PrefsRepo.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/repository/PrefsRepo.kt
@@ -121,7 +121,9 @@ class PrefsRepo @Inject constructor(val preferences: SharedPreferences, val mosh
private fun loadDefaultSources(): List<TleSource> {
return listOf(
TleSource("https://celestrak.com/NORAD/elements/active.txt"),
- TleSource("https://amsat.org/tle/current/nasabare.txt")
+ TleSource("https://amsat.org/tle/current/nasabare.txt"),
+ TleSource("https://www.prismnet.com/~mmccants/tles/classfd.zip"),
+ TleSource("https://www.prismnet.com/~mmccants/tles/inttles.zip")
)
}
}
diff --git a/app/src/main/java/com/rtbishop/look4sat/repository/SatelliteRepo.kt b/app/src/main/java/com/rtbishop/look4sat/repository/SatelliteRepo.kt
index 06f3549c..9c4ac006 100644
--- a/app/src/main/java/com/rtbishop/look4sat/repository/SatelliteRepo.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/repository/SatelliteRepo.kt
@@ -34,6 +34,7 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import java.io.InputStream
+import java.util.zip.ZipInputStream
import javax.inject.Inject
class SatelliteRepo @Inject constructor(
@@ -59,8 +60,7 @@ class SatelliteRepo @Inject constructor(
withContext(ioDispatcher) {
runCatching {
resolver.openInputStream(uri)?.use { stream ->
- val importedEntries = TLE.importSat(stream).map { tle -> SatEntry(tle) }
- updateAndRestoreSelection(importedEntries)
+ updateAndRestoreSelection(importEntriesFromStreams(listOf(stream)))
}
}
}
@@ -68,17 +68,9 @@ class SatelliteRepo @Inject constructor(
suspend fun updateEntriesFromWeb(sources: List<TleSource>) {
withContext(ioDispatcher) {
- val streams = mutableListOf<InputStream>()
- sources.forEach { source ->
- val stream = satelliteService.fetchFile(source.url).body()?.byteStream()
- stream?.let { inputStream -> streams.add(inputStream) }
- }
- val importedEntries = mutableListOf<SatEntry>()
- streams.forEach { stream ->
- val entries = TLE.importSat(stream).map { tle -> SatEntry(tle) }
- importedEntries.addAll(entries)
- }
- updateAndRestoreSelection(importedEntries)
+ val streams = getStreamsForSources(sources)
+ val entries = importEntriesFromStreams(streams)
+ updateAndRestoreSelection(entries)
}
}
@@ -90,6 +82,32 @@ class SatelliteRepo @Inject constructor(
satelliteDao.insertTransmitters(satelliteService.fetchTransmitters())
}
+ private suspend fun getStreamsForSources(sources: List<TleSource>): List<InputStream> {
+ val streams = mutableListOf<InputStream>()
+ sources.forEach { tleSource ->
+ satelliteService.fetchFile(tleSource.url).body()?.byteStream()?.let { inputStream ->
+ if (tleSource.url.contains(".zip")) {
+ // Handle zip stream
+ val zipInputStream = ZipInputStream(inputStream)
+ val zipEntry = zipInputStream.nextEntry
+ if (zipEntry != null && !zipEntry.isDirectory) streams.add(zipInputStream)
+ } else {
+ streams.add(inputStream)
+ }
+ }
+ }
+ return streams
+ }
+
+ private fun importEntriesFromStreams(streams: List<InputStream>): List<SatEntry> {
+ val importedEntries = mutableListOf<SatEntry>()
+ streams.forEach { stream ->
+ val entries = TLE.importSat(stream).map { tle -> SatEntry(tle) }
+ importedEntries.addAll(entries)
+ }
+ return importedEntries
+ }
+
private suspend fun updateAndRestoreSelection(entries: List<SatEntry>) {
val selectedCatNums = satelliteDao.getSelectedCatNums()
satelliteDao.insertEntries(entries)