Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Simplified packages and classes structure
Arty Bishopf6fcd2140405
diff --git a/app/src/main/java/com/rtbishop/look4sat/MainApplication.kt b/app/src/main/java/com/rtbishop/look4sat/MainApplication.ktindex 206aa622..d5f2b55b 100644--- a/app/src/main/java/com/rtbishop/look4sat/MainApplication.kt+++ b/app/src/main/java/com/rtbishop/look4sat/MainApplication.kt@@ -33,13 +33,13 @@ class MainApplication : Application() {}private fun checkAutoUpdate() {- val settingsRepository = container.settingsRepository- if (settingsRepository.isUpdateEnabled()) {- val timeDelta = System.currentTimeMillis() - settingsRepository.getLastUpdateTime()+ val settingsRepo = container.settingsRepo+ if (settingsRepo.isUpdateEnabled()) {+ val timeDelta = System.currentTimeMillis() - settingsRepo.getLastUpdateTime()if (timeDelta > 172800000) { // 48 hours in msval sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault())println("Started periodic data update on ${sdf.format(Date())}")- container.dataRepository.updateFromWeb()+ container.databaseRepo.updateFromWeb()}}}diff --git a/app/src/main/java/com/rtbishop/look4sat/MainContainer.kt b/app/src/main/java/com/rtbishop/look4sat/MainContainer.ktindex f7e83935..e38aa4b7 100644--- a/app/src/main/java/com/rtbishop/look4sat/MainContainer.kt+++ b/app/src/main/java/com/rtbishop/look4sat/MainContainer.kt@@ -7,23 +7,22 @@ import android.hardware.SensorManagerimport android.location.LocationManagerimport androidx.room.Roomimport com.rtbishop.look4sat.data.DataParser-import com.rtbishop.look4sat.data.DataRepository-import com.rtbishop.look4sat.data.SatelliteRepository-import com.rtbishop.look4sat.data.SelectionRepository-import com.rtbishop.look4sat.domain.IDataRepository-import com.rtbishop.look4sat.domain.ISatelliteRepository-import com.rtbishop.look4sat.domain.ISensorRepository-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.data.DatabaseRepo+import com.rtbishop.look4sat.data.SatelliteRepo+import com.rtbishop.look4sat.data.SelectionRepo+import com.rtbishop.look4sat.domain.IDatabaseRepo+import com.rtbishop.look4sat.domain.ISatelliteRepo+import com.rtbishop.look4sat.domain.ISelectionRepo+import com.rtbishop.look4sat.domain.ISensorsRepo+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.framework.BluetoothReporterimport com.rtbishop.look4sat.framework.NetworkReporter-import com.rtbishop.look4sat.framework.SensorRepository-import com.rtbishop.look4sat.framework.SettingsRepository+import com.rtbishop.look4sat.framework.SensorsRepo+import com.rtbishop.look4sat.framework.SettingsRepo+import com.rtbishop.look4sat.framework.data.DataSource+import com.rtbishop.look4sat.framework.data.LocalStorageimport com.rtbishop.look4sat.framework.data.MIGRATION_1_2import com.rtbishop.look4sat.framework.data.MainDatabase-import com.rtbishop.look4sat.framework.data.local.EntriesStorage-import com.rtbishop.look4sat.framework.data.local.RadiosStorage-import com.rtbishop.look4sat.framework.data.remote.FileSource-import com.rtbishop.look4sat.framework.data.remote.NetworkSourceimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.SupervisorJob@@ -31,52 +30,48 @@ import org.osmdroid.config.Configurationclass MainContainer(private val context: Context) {- val bluetoothReporter = provideBluetoothReporter()- val networkReporter = provideNetworkReporter()- val settingsRepository = provideSettingsRepository()- val dataRepository = provideDataRepository(settingsRepository)- val sensorRepository = provideSensorRepository()- val satelliteRepository = provideSatelliteRepository()+ private val database = Room.databaseBuilder(context, MainDatabase::class.java, "Look4SatDb")+ .addMigrations(MIGRATION_1_2).fallbackToDestructiveMigration().build()+ private val localStorage = LocalStorage(database.storageDao())+ val settingsRepo = provideSettingsRepo()+ val databaseRepo = provideDatabaseRepo(settingsRepo)+ val sensorsRepo = provideSensorRepo()+ val satelliteRepo = provideSatelliteRepo()- private fun provideBluetoothReporter(): BluetoothReporter {- val manager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager- return BluetoothReporter(manager, CoroutineScope(Dispatchers.IO))+ fun provideBluetoothReporter(): BluetoothReporter {+ val btManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager+ return BluetoothReporter(btManager, CoroutineScope(Dispatchers.IO))}- private fun provideNetworkReporter(): NetworkReporter {+ fun provideNetworkReporter(): NetworkReporter {return NetworkReporter(CoroutineScope(Dispatchers.IO))}- private fun provideDataRepository(settings: ISettingsRepository): IDataRepository {- val db = Room.databaseBuilder(context, MainDatabase::class.java, "Look4SatDb")- .addMigrations(MIGRATION_1_2).fallbackToDestructiveMigration().build()- val parser = DataParser(Dispatchers.Default)- val fileSource = FileSource(context.contentResolver, Dispatchers.IO)- val entries = EntriesStorage(db.entriesDao())- val radios = RadiosStorage(db.radiosDao())- val remoteSource = NetworkSource(Dispatchers.IO)+ private fun provideDatabaseRepo(settingsRepo: ISettingsRepo): IDatabaseRepo {+ val dataParser = DataParser(Dispatchers.Default)+ val dataSource = DataSource(context.contentResolver, Dispatchers.IO)val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)- return DataRepository(parser, fileSource, entries, radios, remoteSource, scope, settings)+ return DatabaseRepo(dataParser, localStorage, dataSource, scope, settingsRepo)}- fun provideSelectionRepository(): SelectionRepository {- return SelectionRepository(Dispatchers.Default, dataRepository, settingsRepository)+ fun provideSelectionRepo(): ISelectionRepo {+ return SelectionRepo(Dispatchers.Default, localStorage, settingsRepo)}- private fun provideSensorRepository(): ISensorRepository {- val manager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager- val sensor = manager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)- return SensorRepository(manager, sensor)+ private fun provideSensorRepo(): ISensorsRepo {+ val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager+ val sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)+ return SensorsRepo(sensorManager, sensor)}- private fun provideSatelliteRepository(): ISatelliteRepository {- return SatelliteRepository(Dispatchers.Default)+ private fun provideSatelliteRepo(): ISatelliteRepo {+ return SatelliteRepo(Dispatchers.Default, localStorage)}- private fun provideSettingsRepository(): ISettingsRepository {- val manager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager+ private fun provideSettingsRepo(): ISettingsRepo {+ val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManagerval preferences = context.getSharedPreferences("default", Context.MODE_PRIVATE)Configuration.getInstance().load(context, preferences)- return SettingsRepository(manager, preferences)+ return SettingsRepo(locationManager, preferences)}}diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/SensorRepository.kt b/app/src/main/java/com/rtbishop/look4sat/framework/SensorsRepo.ktsimilarity index 88%rename from app/src/main/java/com/rtbishop/look4sat/framework/SensorRepository.ktrename to app/src/main/java/com/rtbishop/look4sat/framework/SensorsRepo.ktindex 08c43c39..aa21e0ce 100644--- a/app/src/main/java/com/rtbishop/look4sat/framework/SensorRepository.kt+++ b/app/src/main/java/com/rtbishop/look4sat/framework/SensorsRepo.kt@@ -21,14 +21,14 @@ import android.hardware.Sensorimport android.hardware.SensorEventimport android.hardware.SensorEventListenerimport android.hardware.SensorManager-import com.rtbishop.look4sat.domain.ISensorRepository+import com.rtbishop.look4sat.domain.ISensorsRepoimport com.rtbishop.look4sat.domain.RAD2DEGimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.StateFlowimport kotlin.math.round-class SensorRepository(private val manager: SensorManager, private val sensor: Sensor?) :- SensorEventListener, ISensorRepository {+class SensorsRepo(private val sensorManager: SensorManager, private val sensor: Sensor?) :+ SensorEventListener, ISensorsRepo {private val rotationMatrix = FloatArray(9)private val orientationValues = FloatArray(3)@@ -38,10 +38,10 @@ class SensorRepository(private val manager: SensorManager, private val sensor: Soverride val orientation: StateFlow<Pair<Float, Float>> = _orientationoverride fun enableSensor() {- sensor?.let { manager.registerListener(this, it, 16000) }+ sensor?.let { sensorManager.registerListener(this, it, 16000) }}- override fun disableSensor() = manager.unregisterListener(this)+ override fun disableSensor() = sensorManager.unregisterListener(this)override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {sensorAccuracy = accuracydiff --git a/app/src/main/java/com/rtbishop/look4sat/framework/SettingsRepository.kt b/app/src/main/java/com/rtbishop/look4sat/framework/SettingsRepo.ktsimilarity index 98%rename from app/src/main/java/com/rtbishop/look4sat/framework/SettingsRepository.ktrename to app/src/main/java/com/rtbishop/look4sat/framework/SettingsRepo.ktindex 3074b9c0..9049cafb 100644--- a/app/src/main/java/com/rtbishop/look4sat/framework/SettingsRepository.kt+++ b/app/src/main/java/com/rtbishop/look4sat/framework/SettingsRepo.kt@@ -23,7 +23,7 @@ import android.location.LocationManagerimport androidx.core.content.editimport androidx.core.location.LocationManagerCompatimport androidx.core.os.CancellationSignal-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.model.GeoPosimport com.rtbishop.look4sat.utility.QthConverterimport com.rtbishop.look4sat.utility.round@@ -31,9 +31,9 @@ import kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.StateFlowimport java.util.concurrent.Executors-class SettingsRepository(+class SettingsRepo(private val manager: LocationManager, private val preferences: SharedPreferences-) : ISettingsRepository {+) : ISettingsRepo {private val keyModes = "satModes"private val keyCompass = "compass"diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/data/remote/FileSource.kt b/app/src/main/java/com/rtbishop/look4sat/framework/data/DataSource.ktsimilarity index 64%rename from app/src/main/java/com/rtbishop/look4sat/framework/data/remote/FileSource.ktrename to app/src/main/java/com/rtbishop/look4sat/framework/data/DataSource.ktindex e3a3665c..174d2a17 100644--- a/app/src/main/java/com/rtbishop/look4sat/framework/data/remote/FileSource.kt+++ b/app/src/main/java/com/rtbishop/look4sat/framework/data/DataSource.kt@@ -15,21 +15,25 @@* 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.data.remote+package com.rtbishop.look4sat.framework.dataimport android.content.ContentResolverimport android.net.Uri-import com.rtbishop.look4sat.data.IFileSource+import com.rtbishop.look4sat.data.IDataSourceimport kotlinx.coroutines.CoroutineDispatcherimport kotlinx.coroutines.withContextimport java.io.InputStream+import java.net.URL-class FileSource(- private val contentResolver: ContentResolver,- private val coroutineDispatcher: CoroutineDispatcher-) : IFileSource {+class DataSource(+ private val resolver: ContentResolver, private val dispatcher: CoroutineDispatcher+) : IDataSource {- override suspend fun getDataStream(uri: String): InputStream? {- return withContext(coroutineDispatcher) { contentResolver.openInputStream(Uri.parse(uri)) }+ override suspend fun getFileStream(uri: String): InputStream? {+ return withContext(dispatcher) { resolver.openInputStream(Uri.parse(uri)) }+ }++ override suspend fun getNetworkStream(url: String): InputStream? {+ return withContext(dispatcher) { URL(url).openStream() }}}diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/data/local/EntriesStorage.kt b/app/src/main/java/com/rtbishop/look4sat/framework/data/LocalStorage.ktsimilarity index 52%rename from app/src/main/java/com/rtbishop/look4sat/framework/data/local/EntriesStorage.ktrename to app/src/main/java/com/rtbishop/look4sat/framework/data/LocalStorage.ktindex 12fc726d..ee905e7a 100644--- a/app/src/main/java/com/rtbishop/look4sat/framework/data/local/EntriesStorage.kt+++ b/app/src/main/java/com/rtbishop/look4sat/framework/data/LocalStorage.kt@@ -15,38 +15,42 @@* 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.data.local+package com.rtbishop.look4sat.framework.data-import com.rtbishop.look4sat.data.IEntriesStorage+import com.rtbishop.look4sat.data.ILocalStorageimport com.rtbishop.look4sat.domain.Satellite-import com.rtbishop.look4sat.framework.data.dao.EntriesDao+import com.rtbishop.look4sat.model.SatRadioimport com.rtbishop.look4sat.framework.model.SatEntry as FrameworkEntryimport com.rtbishop.look4sat.framework.model.SatItem as FrameworkItem+import com.rtbishop.look4sat.framework.model.SatRadio as FrameworkRadioimport com.rtbishop.look4sat.model.SatEntry as DomainEntryimport com.rtbishop.look4sat.model.SatItem as DomainItem+import com.rtbishop.look4sat.model.SatRadio as DomainRadio-class EntriesStorage(private val entriesDao: EntriesDao) : IEntriesStorage {+class LocalStorage(private val storageDao: StorageDao) : ILocalStorage {- override fun getEntriesTotal() = entriesDao.getEntriesTotal()+ //region # Entries region++ override fun getEntriesTotal() = storageDao.getEntriesTotal()override suspend fun getEntriesList(): List<DomainItem> {- return entriesDao.getEntriesList().toDomainItems()+ return storageDao.getEntriesList().toDomainItems()}override suspend fun getEntriesWithIds(ids: List<Int>): List<Satellite> {val selectedSatellites = mutableListOf<Satellite>()ids.chunked(999).forEach { idsPart ->- val entries = entriesDao.getEntriesWithIds(idsPart)+ val entries = storageDao.getEntriesWithIds(idsPart)selectedSatellites.addAll(entries.map { entry -> entry.data.getSatellite() })}return selectedSatellites}override suspend fun insertEntries(entries: List<DomainEntry>) {- entriesDao.insertEntries(entries.toFrameworkEntries())+ storageDao.insertEntries(entries.toFrameworkEntries())}- override suspend fun deleteEntries() = entriesDao.deleteEntries()+ override suspend fun deleteEntries() = storageDao.deleteEntries()private fun DomainEntry.toFramework() = FrameworkEntry(this.data, this.comment)@@ -55,4 +59,36 @@ class EntriesStorage(private val entriesDao: EntriesDao) : IEntriesStorage {private fun List<DomainEntry>.toFrameworkEntries() = this.map { entry -> entry.toFramework() }private fun List<FrameworkItem>.toDomainItems() = this.map { item -> item.toDomain() }++ //endregion++ //region # Radios region++ override fun getRadiosTotal() = storageDao.getRadiosTotal()++ override suspend fun getRadiosWithId(id: Int): List<SatRadio> {+ return storageDao.getRadiosWithId(id).toDomainRadios()+ }++ override suspend fun insertRadios(radios: List<SatRadio>) {+ storageDao.insertRadios(radios.toFrameworkRadios())+ }++ override suspend fun deleteRadios() = storageDao.deleteRadios()++ private fun DomainRadio.toFramework() = FrameworkRadio(+ this.uuid, this.info, this.isAlive, this.downlink, this.uplink,+ this.mode, this.isInverted, this.catnum, this.comment+ )++ private fun FrameworkRadio.toDomain() = DomainRadio(+ this.uuid, this.info, this.isAlive, this.downlink, this.uplink,+ this.mode, this.isInverted, this.catnum, this.comment+ )++ private fun List<DomainRadio>.toFrameworkRadios() = this.map { radio -> radio.toFramework() }++ private fun List<FrameworkRadio>.toDomainRadios() = this.map { radio -> radio.toDomain() }++ //endregion}diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/data/MainDatabase.kt b/app/src/main/java/com/rtbishop/look4sat/framework/data/MainDatabase.ktindex 576438ca..70b70a67 100644--- a/app/src/main/java/com/rtbishop/look4sat/framework/data/MainDatabase.kt+++ b/app/src/main/java/com/rtbishop/look4sat/framework/data/MainDatabase.kt@@ -21,17 +21,13 @@ import androidx.room.Databaseimport androidx.room.RoomDatabaseimport androidx.room.migration.Migrationimport androidx.sqlite.db.SupportSQLiteDatabase-import com.rtbishop.look4sat.framework.data.dao.EntriesDao-import com.rtbishop.look4sat.framework.data.dao.RadiosDaoimport com.rtbishop.look4sat.framework.model.SatEntryimport com.rtbishop.look4sat.framework.model.SatRadio@Database(entities = [SatEntry::class, SatRadio::class], version = 2)abstract class MainDatabase : RoomDatabase() {- abstract fun entriesDao(): EntriesDao-- abstract fun radiosDao(): RadiosDao+ abstract fun storageDao(): StorageDao}val MIGRATION_1_2 = object : Migration(1, 2) {diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/data/dao/EntriesDao.kt b/app/src/main/java/com/rtbishop/look4sat/framework/data/StorageDao.ktsimilarity index 67%rename from app/src/main/java/com/rtbishop/look4sat/framework/data/dao/EntriesDao.ktrename to app/src/main/java/com/rtbishop/look4sat/framework/data/StorageDao.ktindex d320f5de..3b1a4f16 100644--- a/app/src/main/java/com/rtbishop/look4sat/framework/data/dao/EntriesDao.kt+++ b/app/src/main/java/com/rtbishop/look4sat/framework/data/StorageDao.kt@@ -15,22 +15,23 @@* 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.data.dao+package com.rtbishop.look4sat.framework.dataimport androidx.room.*import com.rtbishop.look4sat.framework.model.SatEntryimport com.rtbishop.look4sat.framework.model.SatItem+import com.rtbishop.look4sat.framework.model.SatRadioimport kotlinx.coroutines.flow.Flow@Dao-interface EntriesDao {+interface StorageDao {@Query("SELECT COUNT(*) FROM entries")fun getEntriesTotal(): Flow<Int>-// @Transaction-@Query("SELECT catnum, name FROM entries ORDER BY name ASC")-suspend fun getEntriesList(): List<SatItem>+ //@Transaction+ @Query("SELECT catnum, name FROM entries ORDER BY name ASC")+ suspend fun getEntriesList(): List<SatItem>@Transaction@Query("SELECT * FROM entries WHERE catnum IN (:selectedIds)")@@ -41,4 +42,17 @@ suspend fun getEntriesList(): List<SatItem>@Query("DELETE FROM entries")suspend fun deleteEntries()++ @Query("SELECT COUNT(*) FROM radios")+ fun getRadiosTotal(): Flow<Int>++ @Transaction+ @Query("SELECT * FROM radios WHERE catnum = :id AND isAlive = 1")+ suspend fun getRadiosWithId(id: Int): List<SatRadio>++ @Insert(onConflict = OnConflictStrategy.REPLACE)+ suspend fun insertRadios(radios: List<SatRadio>)++ @Query("DELETE FROM radios")+ suspend fun deleteRadios()}diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/data/dao/RadiosDao.kt b/app/src/main/java/com/rtbishop/look4sat/framework/data/dao/RadiosDao.ktdeleted file mode 100644index b152ca42..00000000--- a/app/src/main/java/com/rtbishop/look4sat/framework/data/dao/RadiosDao.kt+++ /dev/null@@ -1,39 +0,0 @@-/*- * Look4Sat. Amateur radio satellite tracker and pass predictor.- * Copyright (C) 2019-2022 Arty Bishop ([email protected])- *- * 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.data.dao--import androidx.room.*-import com.rtbishop.look4sat.framework.model.SatRadio-import kotlinx.coroutines.flow.Flow--@Dao-interface RadiosDao {-- @Query("SELECT COUNT(*) FROM radios")- fun getRadiosTotal(): Flow<Int>-- @Transaction- @Query("SELECT * FROM radios WHERE catnum = :id AND isAlive = 1")- suspend fun getRadiosWithId(id: Int): List<SatRadio>-- @Insert(onConflict = OnConflictStrategy.REPLACE)- suspend fun insertRadios(radios: List<SatRadio>)-- @Query("DELETE FROM radios")- suspend fun deleteRadios()-}diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/data/local/RadiosStorage.kt b/app/src/main/java/com/rtbishop/look4sat/framework/data/local/RadiosStorage.ktdeleted file mode 100644index 9712ee41..00000000--- a/app/src/main/java/com/rtbishop/look4sat/framework/data/local/RadiosStorage.kt+++ /dev/null@@ -1,52 +0,0 @@-/*- * Look4Sat. Amateur radio satellite tracker and pass predictor.- * Copyright (C) 2019-2022 Arty Bishop ([email protected])- *- * 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.data.local--import com.rtbishop.look4sat.data.IRadiosStorage-import com.rtbishop.look4sat.framework.data.dao.RadiosDao-import com.rtbishop.look4sat.framework.model.SatRadio as FrameworkRadio-import com.rtbishop.look4sat.model.SatRadio as DomainRadio--class RadiosStorage(private val radiosDao: RadiosDao) : IRadiosStorage {-- override fun getRadiosTotal() = radiosDao.getRadiosTotal()-- override suspend fun getRadiosWithId(id: Int): List<DomainRadio> {- return radiosDao.getRadiosWithId(id).toDomainRadios()- }-- override suspend fun insertRadios(radios: List<DomainRadio>) {- radiosDao.insertRadios(radios.toFrameworkRadios())- }-- override suspend fun deleteRadios() = radiosDao.deleteRadios()-- private fun DomainRadio.toFramework() = FrameworkRadio(- this.uuid, this.info, this.isAlive, this.downlink, this.uplink,- this.mode, this.isInverted, this.catnum, this.comment- )-- private fun FrameworkRadio.toDomain() = DomainRadio(- this.uuid, this.info, this.isAlive, this.downlink, this.uplink,- this.mode, this.isInverted, this.catnum, this.comment- )-- private fun List<DomainRadio>.toFrameworkRadios() = this.map { radio -> radio.toFramework() }-- private fun List<FrameworkRadio>.toDomainRadios() = this.map { radio -> radio.toDomain() }-}diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/data/remote/NetworkSource.kt b/app/src/main/java/com/rtbishop/look4sat/framework/data/remote/NetworkSource.ktdeleted file mode 100644index 50c72886..00000000--- a/app/src/main/java/com/rtbishop/look4sat/framework/data/remote/NetworkSource.kt+++ /dev/null@@ -1,31 +0,0 @@-/*- * Look4Sat. Amateur radio satellite tracker and pass predictor.- * Copyright (C) 2019-2022 Arty Bishop ([email protected])- *- * 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.data.remote--import com.rtbishop.look4sat.data.INetworkSource-import kotlinx.coroutines.CoroutineDispatcher-import kotlinx.coroutines.withContext-import java.io.InputStream-import java.net.URL--class NetworkSource(private val coroutineDispatcher: CoroutineDispatcher) : INetworkSource {-- override suspend fun getDataStream(url: String): InputStream? {- return withContext(coroutineDispatcher) { URL(url).openStream() }- }-}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/Components.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/Components.ktindex 8ae51b1c..b7cdef0c 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/Components.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/Components.kt@@ -5,7 +5,6 @@ import android.content.Intentimport android.net.Uriimport android.widget.Toastimport androidx.compose.foundation.clickable-import androidx.compose.foundation.interaction.Interactionimport androidx.compose.foundation.interaction.MutableInteractionSourceimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.fillMaxSize@@ -25,8 +24,6 @@ import androidx.compose.ui.composedimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.sp-import kotlinx.coroutines.flow.Flow-import kotlinx.coroutines.flow.emptyFlow@Composablefun CardButton(onClick: () -> Unit, text: String, modifier: Modifier = Modifier) {@@ -66,9 +63,3 @@ fun gotoUrl(context: Context, url: String) {fun Modifier.onClick(onClick: () -> Unit): Modifier = composed {clickable(remember { MutableInteractionSource() }, null) { onClick() }}--class NoRippleInteractionSource : MutableInteractionSource {- override val interactions: Flow<Interaction> = emptyFlow()- override suspend fun emit(interaction: Interaction) {}- override fun tryEmit(interaction: Interaction) = true-}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesScreen.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesScreen.ktindex 16ec5ae7..6a929530 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesScreen.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesScreen.kt@@ -45,8 +45,8 @@ fun EntriesScreen(navToPasses: () -> Unit) {}}- val unselectAll = { viewModel.updateSelection(false) }- val selectAll = { viewModel.updateSelection(true) }+ val unselectAll = { viewModel.setSelection(false) }+ val selectAll = { viewModel.setSelection(true) }Column(modifier = Modifier.padding(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {TopBar(setQuery = { newQuery: String -> viewModel.setQuery(newQuery) }, saveSelection = {viewModel.saveSelection()@@ -58,7 +58,7 @@ fun EntriesScreen(navToPasses: () -> Unit) {CardLoadingIndicator()} else {EntriesCard(uiState.itemsList) { list, value ->- viewModel.updateSelection(list, value)+ viewModel.setSelection(list, value)}}}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesScreenState.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesUiState.ktsimilarity index 87%rename from app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesScreenState.ktrename to app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesUiState.ktindex 2915ae54..13f27d39 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesScreenState.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesUiState.kt@@ -2,7 +2,7 @@ package com.rtbishop.look4sat.presentation.entriesimport com.rtbishop.look4sat.model.SatItem-data class EntriesScreenState(+data class EntriesUiState(val isLoading: Boolean,val itemsList: List<SatItem>,val currentType: String,diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.ktindex ba727b2b..988cd148 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.kt@@ -24,13 +24,13 @@ import androidx.lifecycle.viewModelScopeimport androidx.lifecycle.viewmodel.initializerimport androidx.lifecycle.viewmodel.viewModelFactoryimport com.rtbishop.look4sat.MainApplication-import com.rtbishop.look4sat.data.SelectionRepository+import com.rtbishop.look4sat.domain.ISelectionRepoimport kotlinx.coroutines.delayimport kotlinx.coroutines.launch-class EntriesViewModel(private val selectionRepo: SelectionRepository) : ViewModel() {+class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel() {- private val defaultUiState = EntriesScreenState(+ private val defaultUiState = EntriesUiState(isLoading = true,itemsList = emptyList(),currentType = selectionRepo.getCurrentType(),@@ -54,12 +54,12 @@ class EntriesViewModel(private val selectionRepo: SelectionRepository) : ViewModfun setQuery(query: String) = viewModelScope.launch { selectionRepo.setQuery(query) }- fun updateSelection(selectAll: Boolean) = viewModelScope.launch {- selectionRepo.updateSelection(selectAll)+ fun setSelection(selectAll: Boolean) = viewModelScope.launch {+ selectionRepo.setSelection(selectAll)}- fun updateSelection(catNums: List<Int>, isSelected: Boolean) = viewModelScope.launch {- selectionRepo.updateSelection(catNums, isSelected)+ fun setSelection(ids: List<Int>, isTicked: Boolean) = viewModelScope.launch {+ selectionRepo.setSelection(ids, isTicked)}fun saveSelection() = viewModelScope.launch { selectionRepo.saveSelection() }@@ -69,7 +69,7 @@ class EntriesViewModel(private val selectionRepo: SelectionRepository) : ViewModval applicationKey = ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYinitializer {val container = (this[applicationKey] as MainApplication).container- EntriesViewModel(container.provideSelectionRepository())+ EntriesViewModel(container.provideSelectionRepo())}}}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapScreen.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapScreen.ktindex 8f6fe0ac..cfd8d254 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapScreen.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapScreen.kt@@ -65,7 +65,7 @@ private val labelRect = Rect()fun MapScreen() {val viewModel = viewModel(MapViewModel::class.java, factory = MapViewModel.Factory)viewModel.selectDefaultSatellite(-1)- val stationPos = viewModel.stationPos.collectAsState(initial = null)+ val stationPos = viewModel.stationPosition.collectAsState(initial = null)val positions = viewModel.positions.collectAsState(initial = null)val satTrack = viewModel.track.collectAsState(initial = null)val footprint = viewModel.footprint.collectAsState(initial = null)diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapViewModel.ktindex b8fea306..68f06588 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/map/MapViewModel.kt@@ -23,9 +23,8 @@ import androidx.lifecycle.viewModelScopeimport androidx.lifecycle.viewmodel.initializerimport androidx.lifecycle.viewmodel.viewModelFactoryimport com.rtbishop.look4sat.MainApplication-import com.rtbishop.look4sat.domain.IDataRepository-import com.rtbishop.look4sat.domain.ISatelliteRepository-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.domain.ISatelliteRepo+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.domain.Satelliteimport com.rtbishop.look4sat.model.GeoPosimport com.rtbishop.look4sat.model.SatPos@@ -46,22 +45,19 @@ import kotlin.math.maximport kotlin.math.minclass MapViewModel(- private val dataRepository: IDataRepository,- private val satelliteRepository: ISatelliteRepository,- private val settingsRepository: ISettingsRepository+ private val satelliteRepo: ISatelliteRepo, private val settingsRepo: ISettingsRepo) : ViewModel() {- private val stationPosNew = settingsRepository.stationPosition.value- private val stationPosition = GeoPos(stationPosNew.latitude, stationPosNew.longitude)- private var allPasses = satelliteRepository.getPasses()+ private val stationPos = settingsRepo.stationPosition.value+ private var allPasses = satelliteRepo.getPasses()private var allSatellites = listOf<Satellite>()private var dataUpdateJob: Job? = nullprivate var dataUpdateRate = 1000Lprivate var selectedSatellite: Satellite? = null- val stationPos = flow {- val osmLat = clipLat(stationPosition.latitude)- val osmLon = clipLon(stationPosition.longitude)+ val stationPosition = flow {+ val osmLat = clipLat(stationPos.latitude)+ val osmLon = clipLon(stationPos.longitude)emit(GeoPos(osmLat, osmLon))}@@ -92,8 +88,8 @@ class MapViewModel(fun selectDefaultSatellite(catnum: Int) {viewModelScope.launch {- val selectedIds = settingsRepository.satelliteSelection.value- dataRepository.getEntriesWithIds(selectedIds).also { satellites ->+ val selectedIds = settingsRepo.satelliteSelection.value+ satelliteRepo.getEntriesWithIds(selectedIds).also { satellites ->if (satellites.isNotEmpty()) {allSatellites = satellitesif (catnum == -1) {@@ -113,12 +109,12 @@ class MapViewModel(dataUpdateJob?.cancelAndJoin()dataUpdateJob = launch {val dateNow = Date()- getSatTrack(satellite, stationPosition, dateNow)+ getSatTrack(satellite, stationPos, dateNow)while (isActive) {dateNow.time = System.currentTimeMillis()- getPositions(allSatellites, stationPosition, dateNow)- getSatFootprint(satellite, stationPosition, dateNow)- getSatData(satellite, stationPosition, dateNow)+ getPositions(allSatellites, stationPos, dateNow)+ getSatFootprint(satellite, stationPos, dateNow)+ getSatData(satellite, stationPos, dateNow)delay(updateFreq)}}@@ -130,7 +126,7 @@ class MapViewModel(val currentTrack = mutableListOf<GeoPos>()val endDate = Date(date.time + (satellite.data.orbitalPeriod * 2.4 * 60000L).toLong())var oldLongitude = 0.0- satelliteRepository.getTrack(satellite, pos, date.time, endDate.time).forEach { satPos ->+ satelliteRepo.getTrack(satellite, pos, date.time, endDate.time).forEach { satPos ->val osmLat = clipLat(satPos.latitude.toDegrees())val osmLon = clipLon(satPos.longitude.toDegrees())val currentPosition = GeoPos(osmLat, osmLon)@@ -157,7 +153,7 @@ class MapViewModel(private suspend fun getPositions(satellites: List<Satellite>, pos: GeoPos, date: Date) {val positions = mutableMapOf<Satellite, GeoPos>()satellites.forEach { satellite ->- val satPos = satelliteRepository.getPosition(satellite, pos, date.time)+ val satPos = satelliteRepo.getPosition(satellite, pos, date.time)val osmLat = clipLat(satPos.latitude.toDegrees())val osmLon = clipLon(satPos.longitude.toDegrees())positions[satellite] = GeoPos(osmLat, osmLon)@@ -166,7 +162,7 @@ class MapViewModel(}private suspend fun getSatFootprint(satellite: Satellite, pos: GeoPos, date: Date) {- val satPos = satelliteRepository.getPosition(satellite, pos, date.time)+ val satPos = satelliteRepo.getPosition(satellite, pos, date.time)_footprint.emit(satPos)}@@ -184,7 +180,7 @@ class MapViewModel(}}}- val satPos = satelliteRepository.getPosition(sat, pos, date.time)+ val satPos = satelliteRepo.getPosition(sat, pos, date.time)val azimuth = satPos.azimuth.toDegrees()val elevation = satPos.elevation.toDegrees()val osmLat = clipLat(satPos.latitude.toDegrees())@@ -232,11 +228,7 @@ class MapViewModel(val applicationKey = ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYinitializer {val container = (this[applicationKey] as MainApplication).container- MapViewModel(- container.dataRepository,- container.satelliteRepository,- container.settingsRepository- )+ MapViewModel(container.satelliteRepo, container.settingsRepo)}}}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.ktindex df953ca5..1803f5da 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.kt@@ -23,9 +23,8 @@ import androidx.lifecycle.viewModelScopeimport androidx.lifecycle.viewmodel.initializerimport androidx.lifecycle.viewmodel.viewModelFactoryimport com.rtbishop.look4sat.MainApplication-import com.rtbishop.look4sat.domain.IDataRepository-import com.rtbishop.look4sat.domain.ISatelliteRepository-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.domain.ISatelliteRepo+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.model.DataStateimport com.rtbishop.look4sat.model.SatPassimport com.rtbishop.look4sat.utility.toTimerString@@ -38,9 +37,7 @@ import kotlinx.coroutines.isActiveimport kotlinx.coroutines.launchclass PassesViewModel(- private val dataRepository: IDataRepository,- private val satelliteRepository: ISatelliteRepository,- private val settingsRepository: ISettingsRepository+ private val satelliteRepo: ISatelliteRepo, private val settingsRepo: ISettingsRepo) : ViewModel() {private val _passes = MutableStateFlow<DataState<List<SatPass>>>(DataState.Loading)@@ -50,18 +47,18 @@ class PassesViewModel(val passes: StateFlow<DataState<List<SatPass>>> = _passesval timerText: StateFlow<Triple<String, String, String>?> = _timerText- fun getHoursAhead() = settingsRepository.getHoursAhead()+ fun getHoursAhead() = settingsRepo.getHoursAhead()- fun getMinElevation() = settingsRepository.getMinElevation()+ fun getMinElevation() = settingsRepo.getMinElevation()init {viewModelScope.launch {- satelliteRepository.calculatedPasses.collect { passes ->+ satelliteRepo.calculatedPasses.collect { passes ->passesProcessing?.cancelAndJoin()passesProcessing = viewModelScope.launch {while (isActive) {val timeNow = System.currentTimeMillis()- val newPasses = satelliteRepository.processPasses(passes, timeNow)+ val newPasses = satelliteRepo.processPasses(passes, timeNow)if (newPasses.isNotEmpty()) {try {@@ -88,20 +85,15 @@ class PassesViewModel(}}viewModelScope.launch {- settingsRepository.satelliteSelection.collect { calculatePasses() }- }- viewModelScope.launch {- dataRepository.updateState.collect { updateState ->- if (updateState is DataState.Success) calculatePasses()- }+ settingsRepo.satelliteSelection.collect { calculatePasses() }}}- fun shouldUseUTC() = settingsRepository.isUtcEnabled()+ fun shouldUseUTC() = settingsRepo.isUtcEnabled()fun calculatePasses(hoursAhead: Int = 1,- minElevation: Double = settingsRepository.getMinElevation(),+ minElevation: Double = settingsRepo.getMinElevation(),timeRef: Long = System.currentTimeMillis()) {viewModelScope.launch {@@ -109,12 +101,12 @@ class PassesViewModel(// _timerText.postValue(timerDefaultText)passesProcessing?.cancelAndJoin()// selection?.let { items -> settingsRepository.saveEntriesSelection(items) }- settingsRepository.setHoursAhead(hoursAhead)- settingsRepository.setMinElevation(minElevation)- val stationPos = settingsRepository.stationPosition.value- val selectedIds = settingsRepository.satelliteSelection.value- val satellites = dataRepository.getEntriesWithIds(selectedIds)- satelliteRepository.calculatePasses(+ settingsRepo.setHoursAhead(hoursAhead)+ settingsRepo.setMinElevation(minElevation)+ val stationPos = settingsRepo.stationPosition.value+ val selectedIds = settingsRepo.satelliteSelection.value+ val satellites = satelliteRepo.getEntriesWithIds(selectedIds)+ satelliteRepo.calculatePasses(satellites, stationPos, timeRef, hoursAhead, minElevation)}@@ -125,11 +117,7 @@ class PassesViewModel(val applicationKey = ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYinitializer {val container = (this[applicationKey] as MainApplication).container- PassesViewModel(- container.dataRepository,- container.satelliteRepository,- container.settingsRepository- )+ PassesViewModel(container.satelliteRepo, container.settingsRepo)}}}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/radar/RadarViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/radar/RadarViewModel.ktindex d55d8421..13053e03 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/radar/RadarViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/radar/RadarViewModel.kt@@ -28,10 +28,9 @@ import androidx.lifecycle.viewModelScopeimport androidx.lifecycle.viewmodel.initializerimport androidx.lifecycle.viewmodel.viewModelFactoryimport com.rtbishop.look4sat.MainApplication-import com.rtbishop.look4sat.domain.IDataRepository-import com.rtbishop.look4sat.domain.ISatelliteRepository-import com.rtbishop.look4sat.domain.ISensorRepository-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.domain.ISatelliteRepo+import com.rtbishop.look4sat.domain.ISensorsRepo+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.domain.Satelliteimport com.rtbishop.look4sat.framework.BluetoothReporterimport com.rtbishop.look4sat.framework.NetworkReporter@@ -47,26 +46,25 @@ import kotlinx.coroutines.isActiveimport kotlinx.coroutines.launchclass RadarViewModel(+ private val savedStateHandle: SavedStateHandle,private val bluetoothReporter: BluetoothReporter,private val networkReporter: NetworkReporter,- private val savedStateHandle: SavedStateHandle,- private val dataRepository: IDataRepository,- private val satelliteRepository: ISatelliteRepository,- private val sensorRepository: ISensorRepository,- private val settingsRepository: ISettingsRepository+ private val satelliteRepo: ISatelliteRepo,+ private val settingsRepo: ISettingsRepo,+ private val sensorsRepo: ISensorsRepo) : ViewModel() {- private val stationPos = settingsRepository.stationPosition.value+ private val stationPos = settingsRepo.stationPosition.valueprivate val magDeclination = getMagDeclination(stationPos)val transmitters = mutableStateOf<List<SatRadio>>(emptyList())val radarData = mutableStateOf<RadarData?>(null)- val orientation = mutableStateOf(sensorRepository.orientation.value)+ val orientation = mutableStateOf(sensorsRepo.orientation.value)init {- if (settingsRepository.isSensorEnabled()) {+ if (settingsRepo.isSensorEnabled()) {viewModelScope.launch {- sensorRepository.enableSensor()- sensorRepository.orientation.collect { data ->+ sensorsRepo.enableSensor()+ sensorsRepo.orientation.collect { data ->orientation.value = Pair(data.first + magDeclination, data.second)}}@@ -74,24 +72,24 @@ class RadarViewModel(}override fun onCleared() {- sensorRepository.disableSensor()+ sensorsRepo.disableSensor()super.onCleared()}fun getPass() = flow {val catNum = savedStateHandle.get<Int>("catNum") ?: 0val aosTime = savedStateHandle.get<Long>("aosTime") ?: 0L- satelliteRepository.calculatedPasses.collect { passes ->+ satelliteRepo.calculatedPasses.collect { passes ->val pass = passes.find { pass -> pass.catNum == catNum && pass.aosTime == aosTime }val currentPass = pass ?: passes.firstOrNull()currentPass?.let { satPass ->emit(satPass)- val transmitters = dataRepository.getRadiosWithId(satPass.catNum)+ val transmitters = satelliteRepo.getRadiosWithId(satPass.catNum)viewModelScope.launch {while (isActive) {val timeNow = System.currentTimeMillis()val satPos =- satelliteRepository.getPosition(satPass.satellite, stationPos, timeNow)+ satelliteRepo.getPosition(satPass.satellite, stationPos, timeNow)sendPassData(satPass, satPos, satPass.satellite)sendPassDataBT(satPos)processRadios(transmitters, satPass.satellite, timeNow)@@ -102,27 +100,27 @@ class RadarViewModel(}}- fun getUseCompass(): Boolean = settingsRepository.isSensorEnabled()+ fun getUseCompass(): Boolean = settingsRepo.isSensorEnabled()- fun getShowSweep(): Boolean = settingsRepository.isSweepEnabled()+ fun getShowSweep(): Boolean = settingsRepo.isSweepEnabled()private fun getMagDeclination(geoPos: GeoPos, time: Long = System.currentTimeMillis()): Float {val latitude = geoPos.latitude.toFloat()val longitude = geoPos.longitude.toFloat()- return GeomagneticField(latitude, longitude, 0f, time).declination+ return GeomagneticField(latitude, longitude, geoPos.altitude.toFloat(), time).declination}private fun sendPassData(satPass: SatPass, satPos: SatPos, satellite: Satellite) {viewModelScope.launch {var track: List<SatPos> = emptyList()if (!satPass.isDeepSpace) {- track = satelliteRepository.getTrack(+ track = satelliteRepo.getTrack(satellite, stationPos, satPass.aosTime, satPass.losTime)}- if (settingsRepository.getRotatorEnabled()) {- val server = settingsRepository.getRotatorServer()- val port = settingsRepository.getRotatorPort().toInt()+ if (settingsRepo.getRotatorEnabled()) {+ val server = settingsRepo.getRotatorServer()+ val port = settingsRepo.getRotatorPort().toInt()val azimuth = satPos.azimuth.toDegrees().round(1)val elevation = satPos.elevation.toDegrees().round(1)networkReporter.reportRotation(server, port, azimuth, elevation)@@ -133,10 +131,10 @@ class RadarViewModel(private fun sendPassDataBT(satPos: SatPos) {viewModelScope.launch {- if (settingsRepository.getBTEnabled()) {- val btDevice = settingsRepository.getBTDeviceAddr()+ if (settingsRepo.getBTEnabled()) {+ val btDevice = settingsRepo.getBTDeviceAddr()if (bluetoothReporter.isConnected()) {- val format = settingsRepository.getBTFormat()+ val format = settingsRepo.getBTFormat()val azimuth = satPos.azimuth.toDegrees().round(0).toInt()val elevation = satPos.elevation.toDegrees().round(0).toInt()bluetoothReporter.reportRotation(format, azimuth, elevation)@@ -151,7 +149,7 @@ class RadarViewModel(private fun processRadios(radios: List<SatRadio>, satellite: Satellite, time: Long) {viewModelScope.launch {delay(125)- val list = satelliteRepository.processRadios(satellite, stationPos, radios, time)+ val list = satelliteRepo.processRadios(satellite, stationPos, radios, time)transmitters.value = list}}@@ -160,16 +158,14 @@ class RadarViewModel(val Factory: ViewModelProvider.Factory = viewModelFactory {val applicationKey = ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYinitializer {- val savedStateHandle = createSavedStateHandle()val container = (this[applicationKey] as MainApplication).containerRadarViewModel(- container.bluetoothReporter,- container.networkReporter,- savedStateHandle,- container.dataRepository,- container.satelliteRepository,- container.sensorRepository,- container.settingsRepository+ createSavedStateHandle(),+ container.provideBluetoothReporter(),+ container.provideNetworkReporter(),+ container.satelliteRepo,+ container.settingsRepo,+ container.sensorsRepo)}}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsScreenState.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsUiState.ktsimilarity index 100%rename from app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsScreenState.ktrename to app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsUiState.ktdiff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsViewModel.ktindex c176d842..f74cd4ec 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/settings/SettingsViewModel.kt@@ -25,18 +25,18 @@ import androidx.lifecycle.viewmodel.initializerimport androidx.lifecycle.viewmodel.viewModelFactoryimport com.rtbishop.look4sat.MainApplicationimport com.rtbishop.look4sat.R-import com.rtbishop.look4sat.domain.IDataRepository-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.domain.IDatabaseRepo+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.model.DataStateimport kotlinx.coroutines.flow.combineimport kotlinx.coroutines.launchclass SettingsViewModel(- private val dataRepository: IDataRepository, private val settingsRepository: ISettingsRepository+ private val databaseRepo: IDatabaseRepo, private val settingsRepo: ISettingsRepo) : ViewModel() {private val defaultLocationSettings = LocationSettings(false,- settingsRepository.stationPosition.value,+ settingsRepo.stationPosition.value,0,{ setGpsPosition() },{ latitude, longitude -> setGeoPosition(latitude, longitude) },@@ -45,18 +45,18 @@ class SettingsViewModel(val locationSettings = mutableStateOf(defaultLocationSettings)private val defaultDataSettings = DataSettings(false,- settingsRepository.getLastUpdateTime(),+ settingsRepo.getLastUpdateTime(),0,0,- { dataRepository.updateFromWeb() },- { dataRepository.updateFromFile(it) },- { dataRepository.clearAllData() })+ { databaseRepo.updateFromWeb() },+ { databaseRepo.updateFromFile(it) },+ { databaseRepo.clearAllData() })val dataSettings = mutableStateOf(defaultDataSettings)- private val defaultOtherSettings = OtherSettings(settingsRepository.isUtcEnabled(),- settingsRepository.isUpdateEnabled(),- settingsRepository.isSweepEnabled(),- settingsRepository.isSensorEnabled(),+ private val defaultOtherSettings = OtherSettings(settingsRepo.isUtcEnabled(),+ settingsRepo.isUpdateEnabled(),+ settingsRepo.isSweepEnabled(),+ settingsRepo.isSensorEnabled(),{ setUtc(it) },{ setUpdate(it) },{ setSweep(it) },@@ -65,23 +65,23 @@ class SettingsViewModel(init {viewModelScope.launch {- settingsRepository.stationPosition.collect { stationPos ->+ settingsRepo.stationPosition.collect { stationPos ->locationSettings.value = locationSettings.value.copy(isUpdating = false, stationPos = stationPos)}}viewModelScope.launch {- dataRepository.updateState.collect {+ databaseRepo.updateState.collect {val isUpdating = it is DataState.LoadingdataSettings.value = dataSettings.value.copy(- isUpdating = isUpdating, lastUpdated = settingsRepository.getLastUpdateTime()+ isUpdating = isUpdating, lastUpdated = settingsRepo.getLastUpdateTime())}}viewModelScope.launch {combine(- dataRepository.getEntriesTotal(), dataRepository.getRadiosTotal()+ databaseRepo.getEntriesTotal(), databaseRepo.getRadiosTotal()) { sats, radios ->dataSettings.value = dataSettings.value.copy(satsTotal = sats, radiosTotal = radios)}.collect {}@@ -89,7 +89,7 @@ class SettingsViewModel(}private fun setGpsPosition() {- if (settingsRepository.setGpsPosition()) {+ if (settingsRepo.setGpsPosition()) {val messageResId = R.string.location_successlocationSettings.value =locationSettings.value.copy(isUpdating = true, messageResId = messageResId)@@ -100,7 +100,7 @@ class SettingsViewModel(}private fun setGeoPosition(latitude: Double, longitude: Double) {- if (settingsRepository.setGeoPosition(latitude, longitude)) {+ if (settingsRepo.setGeoPosition(latitude, longitude)) {val messageResId = R.string.location_successlocationSettings.value = locationSettings.value.copy(messageResId = messageResId)} else {@@ -110,7 +110,7 @@ class SettingsViewModel(}private fun setQthPosition(locator: String) {- if (settingsRepository.setQthPosition(locator)) {+ if (settingsRepo.setQthPosition(locator)) {val messageResId = R.string.location_successlocationSettings.value = locationSettings.value.copy(messageResId = messageResId)} else {@@ -124,22 +124,22 @@ class SettingsViewModel(}private fun setUtc(value: Boolean) {- settingsRepository.setUtcState(value)+ settingsRepo.setUtcState(value)otherSettings.value = otherSettings.value.copy(getUtc = value)}private fun setUpdate(value: Boolean) {- settingsRepository.setUpdateState(value)+ settingsRepo.setUpdateState(value)otherSettings.value = otherSettings.value.copy(getUpdate = value)}private fun setSweep(value: Boolean) {- settingsRepository.setSweepState(value)+ settingsRepo.setSweepState(value)otherSettings.value = otherSettings.value.copy(getSweep = value)}private fun setSensor(value: Boolean) {- settingsRepository.setSensorState(value)+ settingsRepo.setSensorState(value)otherSettings.value = otherSettings.value.copy(getSensor = value)}@@ -163,7 +163,7 @@ class SettingsViewModel(val applicationKey = ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYinitializer {val container = (this[applicationKey] as MainApplication).container- SettingsViewModel(container.dataRepository, container.settingsRepository)+ SettingsViewModel(container.databaseRepo, container.settingsRepo)}}}diff --git a/base/src/main/java/com/rtbishop/look4sat/data/DataRepository.kt b/base/src/main/java/com/rtbishop/look4sat/data/DatabaseRepo.ktsimilarity index 73%rename from base/src/main/java/com/rtbishop/look4sat/data/DataRepository.ktrename to base/src/main/java/com/rtbishop/look4sat/data/DatabaseRepo.ktindex 5f5949e5..347122b2 100644--- a/base/src/main/java/com/rtbishop/look4sat/data/DataRepository.kt+++ b/base/src/main/java/com/rtbishop/look4sat/data/DatabaseRepo.kt@@ -17,11 +17,10 @@*/package com.rtbishop.look4sat.data-import com.rtbishop.look4sat.domain.IDataRepository-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.domain.IDatabaseRepo+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.model.DataStateimport com.rtbishop.look4sat.model.SatEntry-import com.rtbishop.look4sat.model.SatItemimport kotlinx.coroutines.CoroutineExceptionHandlerimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.async@@ -32,15 +31,13 @@ import kotlinx.coroutines.launchimport java.io.InputStreamimport java.util.zip.ZipInputStream-class DataRepository(+class DatabaseRepo(private val dataParser: DataParser,- private val fileSource: IFileSource,- private val entrySource: IEntriesStorage,- private val radioSource: IRadiosStorage,- private val remoteSource: INetworkSource,+ private val localStorage: ILocalStorage,+ private val dataSource: IDataSource,private val repositoryScope: CoroutineScope,- private val settingsRepository: ISettingsRepository-) : IDataRepository {+ private val settingsRepository: ISettingsRepo+) : IDatabaseRepo {private val exceptionHandler = CoroutineExceptionHandler { _, exception ->_updateState.value = DataState.Exception(exception.message)@@ -49,27 +46,16 @@ class DataRepository(private val _updateState = MutableStateFlow<DataState<Long>>(DataState.Handled)override val updateState: StateFlow<DataState<Long>> = _updateState- override fun getEntriesTotal() = entrySource.getEntriesTotal()+ override fun getEntriesTotal() = localStorage.getEntriesTotal()- override fun getRadiosTotal() = radioSource.getRadiosTotal()-- override fun getSatelliteTypes() = remoteSource.satelliteSourcesMap.keys.sorted()-- override suspend fun getEntriesList(): List<SatItem> {- val selectedIds = settingsRepository.satelliteSelection.value- return entrySource.getEntriesList().map { it.copy(isSelected = it.catnum in selectedIds) }- }-- override suspend fun getEntriesWithIds(ids: List<Int>) = entrySource.getEntriesWithIds(ids)-- override suspend fun getRadiosWithId(id: Int) = radioSource.getRadiosWithId(id)+ override fun getRadiosTotal() = localStorage.getRadiosTotal()override fun updateFromFile(uri: String) {repositoryScope.launch(exceptionHandler) {_updateState.value = DataState.Loading- fileSource.getDataStream(uri)?.let { stream ->+ dataSource.getFileStream(uri)?.let { stream ->delay(updateStateDelay)- entrySource.insertEntries(importSatellites(stream))+ localStorage.insertEntries(importSatellites(stream))}setUpdateSuccessful()}@@ -79,8 +65,8 @@ class DataRepository(_updateState.value = DataState.LoadingrepositoryScope.launch(exceptionHandler) {val importedEntries = mutableListOf<SatEntry>()- val sourcesMap = remoteSource.satelliteSourcesMap- val jobsMap = sourcesMap.mapValues { async { remoteSource.getDataStream(it.value) } }+ val sourcesMap = settingsRepository.satelliteSourcesMap+ val jobsMap = sourcesMap.mapValues { async { dataSource.getNetworkStream(it.value) } }jobsMap.mapValues { job -> job.value.await() }.forEach { entry ->entry.value?.let { stream ->when (val type = entry.key) {@@ -112,12 +98,12 @@ class DataRepository(}}}- entrySource.insertEntries(importedEntries)+ localStorage.insertEntries(importedEntries)setUpdateSuccessful()}repositoryScope.launch(exceptionHandler) {- remoteSource.getDataStream(remoteSource.radioSourceUrl)?.let { stream ->- radioSource.insertRadios(dataParser.parseJSONStream(stream))+ dataSource.getNetworkStream(settingsRepository.radioSourceUrl)?.let { stream ->+ localStorage.insertRadios(dataParser.parseJSONStream(stream))}}}@@ -130,8 +116,8 @@ class DataRepository(repositoryScope.launch {_updateState.value = DataState.Loadingdelay(updateStateDelay)- entrySource.deleteEntries()- radioSource.deleteRadios()+ localStorage.deleteEntries()+ localStorage.deleteRadios()setUpdateSuccessful(0L)}}diff --git a/base/src/main/java/com/rtbishop/look4sat/data/IFileSource.kt b/base/src/main/java/com/rtbishop/look4sat/data/IDataSource.ktsimilarity index 85%rename from base/src/main/java/com/rtbishop/look4sat/data/IFileSource.ktrename to base/src/main/java/com/rtbishop/look4sat/data/IDataSource.ktindex 3fac9a66..4a34237e 100644--- a/base/src/main/java/com/rtbishop/look4sat/data/IFileSource.kt+++ b/base/src/main/java/com/rtbishop/look4sat/data/IDataSource.kt@@ -19,7 +19,9 @@ package com.rtbishop.look4sat.dataimport java.io.InputStream-interface IFileSource {+interface IDataSource {- suspend fun getDataStream(uri: String): InputStream?+ suspend fun getFileStream(uri: String): InputStream?++ suspend fun getNetworkStream(url: String): InputStream?}diff --git a/base/src/main/java/com/rtbishop/look4sat/data/IEntriesStorage.kt b/base/src/main/java/com/rtbishop/look4sat/data/ILocalStorage.ktsimilarity index 83%rename from base/src/main/java/com/rtbishop/look4sat/data/IEntriesStorage.ktrename to base/src/main/java/com/rtbishop/look4sat/data/ILocalStorage.ktindex f3c9f583..eac86014 100644--- a/base/src/main/java/com/rtbishop/look4sat/data/IEntriesStorage.kt+++ b/base/src/main/java/com/rtbishop/look4sat/data/ILocalStorage.kt@@ -20,9 +20,10 @@ package com.rtbishop.look4sat.dataimport com.rtbishop.look4sat.domain.Satelliteimport com.rtbishop.look4sat.model.SatEntryimport com.rtbishop.look4sat.model.SatItem+import com.rtbishop.look4sat.model.SatRadioimport kotlinx.coroutines.flow.Flow-interface IEntriesStorage {+interface ILocalStorage {fun getEntriesTotal(): Flow<Int>@@ -33,4 +34,12 @@ interface IEntriesStorage {suspend fun insertEntries(entries: List<SatEntry>)suspend fun deleteEntries()++ fun getRadiosTotal(): Flow<Int>++ suspend fun getRadiosWithId(id: Int): List<SatRadio>++ suspend fun insertRadios(radios: List<SatRadio>)++ suspend fun deleteRadios()}diff --git a/base/src/main/java/com/rtbishop/look4sat/data/IRadiosStorage.kt b/base/src/main/java/com/rtbishop/look4sat/data/IRadiosStorage.ktdeleted file mode 100644index 7ffc42e3..00000000--- a/base/src/main/java/com/rtbishop/look4sat/data/IRadiosStorage.kt+++ /dev/null@@ -1,32 +0,0 @@-/*- * Look4Sat. Amateur radio satellite tracker and pass predictor.- * Copyright (C) 2019-2022 Arty Bishop ([email protected])- *- * 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.model.SatRadio-import kotlinx.coroutines.flow.Flow--interface IRadiosStorage {-- fun getRadiosTotal(): Flow<Int>-- suspend fun getRadiosWithId(id: Int): List<SatRadio>-- suspend fun insertRadios(radios: List<SatRadio>)-- suspend fun deleteRadios()-}diff --git a/base/src/main/java/com/rtbishop/look4sat/data/SatelliteRepository.kt b/base/src/main/java/com/rtbishop/look4sat/data/SatelliteRepo.ktsimilarity index 96%rename from base/src/main/java/com/rtbishop/look4sat/data/SatelliteRepository.ktrename to base/src/main/java/com/rtbishop/look4sat/data/SatelliteRepo.ktindex 824c82e2..6542fad3 100644--- a/base/src/main/java/com/rtbishop/look4sat/data/SatelliteRepository.kt+++ b/base/src/main/java/com/rtbishop/look4sat/data/SatelliteRepo.kt@@ -17,7 +17,7 @@*/package com.rtbishop.look4sat.data-import com.rtbishop.look4sat.domain.ISatelliteRepository+import com.rtbishop.look4sat.domain.ISatelliteRepoimport com.rtbishop.look4sat.domain.Satelliteimport com.rtbishop.look4sat.model.GeoPosimport com.rtbishop.look4sat.model.SatPass@@ -30,7 +30,10 @@ import kotlinx.coroutines.flow.MutableSharedFlowimport kotlinx.coroutines.flow.SharedFlowimport kotlinx.coroutines.withContext-class SatelliteRepository(private val dispatcher: CoroutineDispatcher) : ISatelliteRepository {+class SatelliteRepo(+ private val dispatcher: CoroutineDispatcher,+ private val localStorage: ILocalStorage+) : ISatelliteRepo {private var passes = listOf<SatPass>()private val _calculatedPasses = MutableSharedFlow<List<SatPass>>(replay = 1)@@ -38,6 +41,10 @@ class SatelliteRepository(private val dispatcher: CoroutineDispatcher) : ISatelloverride fun getPasses(): List<SatPass> = passes+ override suspend fun getEntriesWithIds(ids: List<Int>) = localStorage.getEntriesWithIds(ids)++ override suspend fun getRadiosWithId(id: Int) = localStorage.getRadiosWithId(id)+override suspend fun getPosition(sat: Satellite, pos: GeoPos, time: Long): SatPos {return withContext(dispatcher) { sat.getPosition(pos, time) }}diff --git a/base/src/main/java/com/rtbishop/look4sat/data/SelectionRepository.kt b/base/src/main/java/com/rtbishop/look4sat/data/SelectionRepo.ktsimilarity index 58%rename from base/src/main/java/com/rtbishop/look4sat/data/SelectionRepository.ktrename to base/src/main/java/com/rtbishop/look4sat/data/SelectionRepo.ktindex 2a1c6df5..5b1182ec 100644--- a/base/src/main/java/com/rtbishop/look4sat/data/SelectionRepository.kt+++ b/base/src/main/java/com/rtbishop/look4sat/data/SelectionRepo.kt@@ -1,7 +1,7 @@package com.rtbishop.look4sat.data-import com.rtbishop.look4sat.domain.IDataRepository-import com.rtbishop.look4sat.domain.ISettingsRepository+import com.rtbishop.look4sat.domain.ISelectionRepo+import com.rtbishop.look4sat.domain.ISettingsRepoimport com.rtbishop.look4sat.model.SatItemimport kotlinx.coroutines.CoroutineDispatcherimport kotlinx.coroutines.ExperimentalCoroutinesApi@@ -12,11 +12,11 @@ import kotlinx.coroutines.flow.mapimport kotlinx.coroutines.withContext@OptIn(ExperimentalCoroutinesApi::class)-class SelectionRepository(+class SelectionRepo(private val dispatcher: CoroutineDispatcher,- private val dataRepository: IDataRepository,- private val settingsRepository: ISettingsRepository-) {+ private val localStorage: ILocalStorage,+ private val settingsRepo: ISettingsRepo+) : ISelectionRepo {private val currentItems = MutableStateFlow<List<SatItem>>(emptyList())private val currentType = MutableStateFlow("All")private val currentQuery = MutableStateFlow("")@@ -27,37 +27,44 @@ class SelectionRepository(itemsWithType.map { items -> items.filterByQuery(query) }}- fun getCurrentType() = currentType.value+ override fun getCurrentType() = currentType.value- fun getTypesList() = dataRepository.getSatelliteTypes()+ override fun getTypesList() = settingsRepo.satelliteSourcesMap.keys.sorted()- suspend fun getEntriesFlow() = withContext(dispatcher) {- currentItems.value = dataRepository.getEntriesList()+ override suspend fun getEntriesFlow() = withContext(dispatcher) {+ val selectedIds = settingsRepo.satelliteSelection.value+ currentItems.value = localStorage.getEntriesList().map { item ->+ item.copy(isSelected = item.catnum in selectedIds)+ }return@withContext itemsWithQuery}- suspend fun setType(type: String) = withContext(dispatcher) { currentType.value = type }+ override suspend fun setType(type: String) = withContext(dispatcher) {+ currentType.value = type+ }- suspend fun setQuery(query: String) = withContext(dispatcher) { currentQuery.value = query }+ override suspend fun setQuery(query: String) = withContext(dispatcher) {+ currentQuery.value = query+ }- suspend fun updateSelection(selectAll: Boolean) = withContext(dispatcher) {- updateSelection(itemsWithQuery.first().map { item -> item.catnum }, selectAll)+ override suspend fun setSelection(selectAll: Boolean) = withContext(dispatcher) {+ setSelection(itemsWithQuery.first().map { item -> item.catnum }, selectAll)}- suspend fun updateSelection(catNums: List<Int>, isSelected: Boolean) = withContext(dispatcher) {+ override suspend fun setSelection(ids: List<Int>, isTicked: Boolean) = withContext(dispatcher) {currentItems.value = currentItems.value.map { item ->- if (item.catnum in catNums) item.copy(isSelected = isSelected) else item+ if (item.catnum in ids) item.copy(isSelected = isTicked) else item}}- suspend fun saveSelection() = withContext(dispatcher) {+ override suspend fun saveSelection() = withContext(dispatcher) {val currentSelection = currentItems.value.filter { it.isSelected }.map { it.catnum }- settingsRepository.saveEntriesSelection(currentSelection)+ settingsRepo.saveEntriesSelection(currentSelection)}private suspend fun List<SatItem>.filterByType(type: String) = withContext(dispatcher) {if (type == "All") return@withContext this@filterByType- val catnums = settingsRepository.loadSatType(type)+ val catnums = settingsRepo.loadSatType(type)if (catnums.isEmpty()) return@withContext this@filterByTypereturn@withContext [email protected] { item -> item.catnum in catnums }}diff --git a/base/src/main/java/com/rtbishop/look4sat/domain/IDataRepository.kt b/base/src/main/java/com/rtbishop/look4sat/domain/IDatabaseRepo.ktsimilarity index 78%rename from base/src/main/java/com/rtbishop/look4sat/domain/IDataRepository.ktrename to base/src/main/java/com/rtbishop/look4sat/domain/IDatabaseRepo.ktindex 7c1ccd5b..c74f38ec 100644--- a/base/src/main/java/com/rtbishop/look4sat/domain/IDataRepository.kt+++ b/base/src/main/java/com/rtbishop/look4sat/domain/IDatabaseRepo.kt@@ -18,12 +18,10 @@package com.rtbishop.look4sat.domainimport com.rtbishop.look4sat.model.DataState-import com.rtbishop.look4sat.model.SatItem-import com.rtbishop.look4sat.model.SatRadioimport kotlinx.coroutines.flow.Flowimport kotlinx.coroutines.flow.StateFlow-interface IDataRepository {+interface IDatabaseRepo {val updateState: StateFlow<DataState<Long>>@@ -31,14 +29,6 @@ interface IDataRepository {fun getRadiosTotal(): Flow<Int>- fun getSatelliteTypes(): List<String>-- suspend fun getEntriesList(): List<SatItem>-- suspend fun getEntriesWithIds(ids: List<Int>): List<Satellite>-- suspend fun getRadiosWithId(id: Int): List<SatRadio>-fun updateFromFile(uri: String)fun updateFromWeb()diff --git a/base/src/main/java/com/rtbishop/look4sat/domain/ISatelliteRepository.kt b/base/src/main/java/com/rtbishop/look4sat/domain/ISatelliteRepo.ktsimilarity index 85%rename from base/src/main/java/com/rtbishop/look4sat/domain/ISatelliteRepository.ktrename to base/src/main/java/com/rtbishop/look4sat/domain/ISatelliteRepo.ktindex 844640ed..37ece884 100644--- a/base/src/main/java/com/rtbishop/look4sat/domain/ISatelliteRepository.kt+++ b/base/src/main/java/com/rtbishop/look4sat/domain/ISatelliteRepo.kt@@ -6,12 +6,16 @@ import com.rtbishop.look4sat.model.SatPosimport com.rtbishop.look4sat.model.SatRadioimport kotlinx.coroutines.flow.SharedFlow-interface ISatelliteRepository {+interface ISatelliteRepo {val calculatedPasses: SharedFlow<List<SatPass>>fun getPasses(): List<SatPass>+ suspend fun getEntriesWithIds(ids: List<Int>): List<Satellite>++ suspend fun getRadiosWithId(id: Int): List<SatRadio>+suspend fun getPosition(sat: Satellite, pos: GeoPos, time: Long): SatPossuspend fun getTrack(sat: Satellite, pos: GeoPos, start: Long, end: Long): List<SatPos>diff --git a/base/src/main/java/com/rtbishop/look4sat/domain/ISelectionRepo.kt b/base/src/main/java/com/rtbishop/look4sat/domain/ISelectionRepo.ktnew file mode 100644index 00000000..6c70b5c1--- /dev/null+++ b/base/src/main/java/com/rtbishop/look4sat/domain/ISelectionRepo.kt@@ -0,0 +1,23 @@+package com.rtbishop.look4sat.domain++import com.rtbishop.look4sat.model.SatItem+import kotlinx.coroutines.flow.Flow++interface ISelectionRepo {++ fun getCurrentType(): String++ fun getTypesList(): List<String>++ suspend fun getEntriesFlow(): Flow<List<SatItem>>++ suspend fun setType(type: String)++ suspend fun setQuery(query: String)++ suspend fun setSelection(selectAll: Boolean)++ suspend fun setSelection(ids: List<Int>, isTicked: Boolean)++ suspend fun saveSelection()+}diff --git a/base/src/main/java/com/rtbishop/look4sat/domain/ISensorRepository.kt b/base/src/main/java/com/rtbishop/look4sat/domain/ISensorsRepo.ktsimilarity index 85%rename from base/src/main/java/com/rtbishop/look4sat/domain/ISensorRepository.ktrename to base/src/main/java/com/rtbishop/look4sat/domain/ISensorsRepo.ktindex 0580adc3..2f7e9223 100644--- a/base/src/main/java/com/rtbishop/look4sat/domain/ISensorRepository.kt+++ b/base/src/main/java/com/rtbishop/look4sat/domain/ISensorsRepo.kt@@ -2,7 +2,7 @@ package com.rtbishop.look4sat.domainimport kotlinx.coroutines.flow.StateFlow-interface ISensorRepository {+interface ISensorsRepo {val orientation: StateFlow<Pair<Float, Float>>diff --git a/base/src/main/java/com/rtbishop/look4sat/data/INetworkSource.kt b/base/src/main/java/com/rtbishop/look4sat/domain/ISettingsRepo.ktsimilarity index 66%rename from base/src/main/java/com/rtbishop/look4sat/data/INetworkSource.ktrename to base/src/main/java/com/rtbishop/look4sat/domain/ISettingsRepo.ktindex 043df8f6..aec77462 100644--- a/base/src/main/java/com/rtbishop/look4sat/data/INetworkSource.kt+++ b/base/src/main/java/com/rtbishop/look4sat/domain/ISettingsRepo.kt@@ -15,13 +15,15 @@* 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.domain-import java.io.InputStream+import com.rtbishop.look4sat.model.GeoPos+import kotlinx.coroutines.flow.StateFlow-interface INetworkSource {+interface ISettingsRepo {val radioSourceUrl: String get() = "https://db.satnogs.org/api/transmitters/?format=json"+val satelliteSourcesMap: Map<String, String>get() = mapOf("All" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=active&FORMAT=csv",@@ -52,5 +54,79 @@ interface INetworkSource {"X-Comm" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=x-comm&FORMAT=csv")- suspend fun getDataStream(url: String): InputStream?+ val stationPosition: StateFlow<GeoPos>++ val satelliteSelection: StateFlow<List<Int>>++ fun setGpsPosition(): Boolean++ fun setGeoPosition(latitude: Double, longitude: Double, altitude: Double = 0.0): Boolean++ fun setQthPosition(locator: String): Boolean++ fun getHoursAhead(): Int++ fun setHoursAhead(hoursAhead: Int)++ fun getMinElevation(): Double++ fun setMinElevation(minElevation: Double)++ fun isUtcEnabled(): Boolean++ fun setUtcState(value: Boolean)++ fun getLastUpdateTime(): Long++ fun setLastUpdateTime(updateTime: Long)++ fun isUpdateEnabled(): Boolean++ fun setUpdateState(value: Boolean)++ fun isSensorEnabled(): Boolean++ fun setSensorState(value: Boolean)++ fun isSweepEnabled(): Boolean++ fun setSweepState(value: Boolean)++ fun saveModesSelection(modes: List<String>)++ fun loadModesSelection(): List<String>++ fun saveEntriesSelection(catnums: List<Int>)++ fun saveSatType(type: String, catnums: List<Int>)++ fun loadSatType(type: String): List<Int>++ fun getRotatorEnabled(): Boolean++ fun setRotatorEnabled(value: Boolean)++ fun getRotatorServer(): String++ fun setRotatorServer(value: String)++ fun getRotatorPort(): String++ fun setRotatorPort(value: String)++ fun getBTEnabled(): Boolean++ fun setBTEnabled(value: Boolean)++ fun getBTDeviceAddr(): String++ fun setBTDeviceAddr(value: String)++ fun getBTDeviceName(): String++ fun setBTDeviceName(value: String)++ fun getBTFormat(): String++ fun setBTFormat(value: String)}diff --git a/base/src/main/java/com/rtbishop/look4sat/domain/ISettingsRepository.kt b/base/src/main/java/com/rtbishop/look4sat/domain/ISettingsRepository.ktdeleted file mode 100644index b54b1fa8..00000000--- a/base/src/main/java/com/rtbishop/look4sat/domain/ISettingsRepository.kt+++ /dev/null@@ -1,100 +0,0 @@-/*- * Look4Sat. Amateur radio satellite tracker and pass predictor.- * Copyright (C) 2019-2022 Arty Bishop ([email protected])- *- * 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.GeoPos-import kotlinx.coroutines.flow.StateFlow--interface ISettingsRepository {-- val stationPosition: StateFlow<GeoPos>-- val satelliteSelection: StateFlow<List<Int>>-- fun setGpsPosition(): Boolean-- fun setGeoPosition(latitude: Double, longitude: Double, altitude: Double = 0.0): Boolean-- fun setQthPosition(locator: String): Boolean-- fun getHoursAhead(): Int-- fun setHoursAhead(hoursAhead: Int)-- fun getMinElevation(): Double-- fun setMinElevation(minElevation: Double)-- fun isUtcEnabled(): Boolean-- fun setUtcState(value: Boolean)-- fun getLastUpdateTime(): Long-- fun setLastUpdateTime(updateTime: Long)-- fun isUpdateEnabled(): Boolean-- fun setUpdateState(value: Boolean)-- fun isSensorEnabled(): Boolean-- fun setSensorState(value: Boolean)-- fun isSweepEnabled(): Boolean-- fun setSweepState(value: Boolean)-- fun saveModesSelection(modes: List<String>)-- fun loadModesSelection(): List<String>-- fun saveEntriesSelection(catnums: List<Int>)-- fun saveSatType(type: String, catnums: List<Int>)-- fun loadSatType(type: String): List<Int>-- fun getRotatorEnabled(): Boolean-- fun setRotatorEnabled(value: Boolean)-- fun getRotatorServer(): String-- fun setRotatorServer(value: String)-- fun getRotatorPort(): String-- fun setRotatorPort(value: String)-- fun getBTEnabled(): Boolean-- fun setBTEnabled(value: Boolean)-- fun getBTDeviceAddr(): String-- fun setBTDeviceAddr(value: String)-- fun getBTDeviceName(): String-- fun setBTDeviceName(value: String)-- fun getBTFormat(): String-- fun setBTFormat(value: String)-}diff --git a/base/src/main/java/com/rtbishop/look4sat/utility/Extensions.kt b/base/src/main/java/com/rtbishop/look4sat/utility/Extensions.ktindex cc9453d1..e5844c69 100644--- a/base/src/main/java/com/rtbishop/look4sat/utility/Extensions.kt+++ b/base/src/main/java/com/rtbishop/look4sat/utility/Extensions.kt@@ -72,17 +72,3 @@ fun String.isValidPort(): Boolean {val port = "([1-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])"return this.matches(port.toRegex()) && this.toInt() in 1024..65535}--//fun ping(hostname: String, port: Int): Int {-// val start = System.currentTimeMillis()-// val socket = Socket()-// try {-// socket.connect(InetSocketAddress(hostname, port), 5000)-// socket.close()-// } catch (exception: Exception) {-// exception.printStackTrace()-// println("Failed to ping: $hostname")-// return Int.MAX_VALUE-// }-// return (System.currentTimeMillis() - start).toInt()-//}