diff --git a/app/build.gradle b/app/build.gradle
index a024cd57..3f57f618 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -32,12 +32,6 @@ android {
}
}
}
-
- configurations {
- all {
- exclude module: "commons-logging"
- }
- }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -68,7 +62,6 @@ dependencies {
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
- implementation "com.github.davidmoten:predict4java:$predict4java_version"
implementation "org.osmdroid:osmdroid-android:$osmdroid_version"
implementation "com.jakewharton.timber:timber:$timber_version"
diff --git a/app/schemas/com.rtbishop.look4sat.framework.db.SatelliteDb/1.json b/app/schemas/com.rtbishop.look4sat.framework.db.SatelliteDb/1.json
new file mode 100644
index 00000000..077b4a03
--- /dev/null
+++ b/app/schemas/com.rtbishop.look4sat.framework.db.SatelliteDb/1.json
@@ -0,0 +1,114 @@
+{
+ "formatVersion": 1,
+ "database": {
+ "version": 1,
+ "identityHash": "53fa623fc55b279c50d33e6263866a89",
+ "entities": [
+ {
+ "tableName": "entries",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`tle` TEXT NOT NULL, `catNum` INTEGER NOT NULL, `name` TEXT NOT NULL, `isSelected` INTEGER NOT NULL, PRIMARY KEY(`catNum`))",
+ "fields": [
+ {
+ "fieldPath": "tle",
+ "columnName": "tle",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "catNum",
+ "columnName": "catNum",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "name",
+ "columnName": "name",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isSelected",
+ "columnName": "isSelected",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "columnNames": [
+ "catNum"
+ ],
+ "autoGenerate": false
+ },
+ "indices": [],
+ "foreignKeys": []
+ },
+ {
+ "tableName": "transmitters",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `info` TEXT NOT NULL, `isAlive` INTEGER NOT NULL, `downlink` INTEGER, `uplink` INTEGER, `mode` TEXT, `isInverted` INTEGER NOT NULL, `catNum` INTEGER NOT NULL, PRIMARY KEY(`uuid`))",
+ "fields": [
+ {
+ "fieldPath": "uuid",
+ "columnName": "uuid",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "info",
+ "columnName": "info",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isAlive",
+ "columnName": "isAlive",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "downlink",
+ "columnName": "downlink",
+ "affinity": "INTEGER",
+ "notNull": false
+ },
+ {
+ "fieldPath": "uplink",
+ "columnName": "uplink",
+ "affinity": "INTEGER",
+ "notNull": false
+ },
+ {
+ "fieldPath": "mode",
+ "columnName": "mode",
+ "affinity": "TEXT",
+ "notNull": false
+ },
+ {
+ "fieldPath": "isInverted",
+ "columnName": "isInverted",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "catNum",
+ "columnName": "catNum",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "columnNames": [
+ "uuid"
+ ],
+ "autoGenerate": false
+ },
+ "indices": [],
+ "foreignKeys": []
+ }
+ ],
+ "views": [],
+ "setupQueries": [
+ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '53fa623fc55b279c50d33e6263866a89')"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/api/SatelliteService.kt b/app/src/main/java/com/rtbishop/look4sat/data/api/SatelliteService.kt
deleted file mode 100644
index 3d11217e..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/api/SatelliteService.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Look4Sat. Amateur radio satellite tracker and pass predictor.
- * Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.rtbishop.look4sat.data.api
-
-import com.rtbishop.look4sat.data.model.SatTrans
-import okhttp3.ResponseBody
-import retrofit2.Response
-import retrofit2.http.GET
-import retrofit2.http.Streaming
-import retrofit2.http.Url
-
-interface SatelliteService {
-
- @Streaming
- @GET
- suspend fun fetchFileByUrl(@Url url: String): Response
-
- @GET("transmitters/")
- suspend fun fetchTransmitters(): List
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/database/RoomConverters.kt b/app/src/main/java/com/rtbishop/look4sat/data/database/RoomConverters.kt
deleted file mode 100644
index 5528a062..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/database/RoomConverters.kt
+++ /dev/null
@@ -1,53 +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 .
- */
-package com.rtbishop.look4sat.data.database
-
-import androidx.room.TypeConverter
-import com.github.amsacode.predict4java.Satellite
-import com.github.amsacode.predict4java.SatelliteFactory
-import com.github.amsacode.predict4java.TLE
-import com.squareup.moshi.JsonAdapter
-import com.squareup.moshi.Moshi
-
-object RoomConverters {
-
- private lateinit var tleAdapter: JsonAdapter
-
- fun initialize(moshi: Moshi) {
- tleAdapter = moshi.adapter(TLE::class.java)
- }
-
- @JvmStatic
- @TypeConverter
- fun tleToString(tle: TLE): String {
- return tleAdapter.toJson(tle)
- }
-
- @JvmStatic
- @TypeConverter
- fun tleFromString(string: String): TLE? {
- return tleAdapter.fromJson(string)
- }
-
- @JvmStatic
- @TypeConverter
- fun satFromString(string: String): Satellite? {
- val tle = tleAdapter.fromJson(string)
- return SatelliteFactory.createSatellite(tle)
- }
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/database/SatelliteDao.kt b/app/src/main/java/com/rtbishop/look4sat/data/database/SatelliteDao.kt
deleted file mode 100644
index e55fc2f8..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/database/SatelliteDao.kt
+++ /dev/null
@@ -1,81 +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 .
- */
-package com.rtbishop.look4sat.data.database
-
-import androidx.room.*
-import com.github.amsacode.predict4java.Satellite
-import com.rtbishop.look4sat.data.model.SatEntry
-import com.rtbishop.look4sat.data.model.SatItem
-import com.rtbishop.look4sat.data.model.SatTrans
-import kotlinx.coroutines.flow.Flow
-
-@Dao
-interface SatelliteDao {
-
- @Transaction
- @Query("SELECT catNum, name, isSelected FROM entries ORDER BY name ASC")
- fun getSatItems(): Flow>
-
- @Query("SELECT * FROM transmitters WHERE catNum = :catNum")
- fun getSatTransmitters(catNum: Int): Flow>
-
- @Query("SELECT tle FROM entries WHERE isSelected = 1")
- suspend fun getSelectedSatellites(): List
-
- @Query("SELECT catNum FROM entries WHERE isSelected = 1")
- suspend fun getSelectedCatNums(): List
-
- @Transaction
- suspend fun updateEntries(entries: List) {
- val selectedCatNums = getSelectedCatNums()
- insertEntries(entries)
- restoreEntriesSelection(selectedCatNums, true)
- }
-
- @Insert(onConflict = OnConflictStrategy.REPLACE)
- suspend fun insertEntries(entries: List)
-
- @Transaction
- suspend fun restoreEntriesSelection(catNums: List, isSelected: Boolean) {
- clearEntriesSelection()
- catNums.forEach { catNum -> updateEntrySelection(catNum, isSelected) }
- }
-
- @Query("UPDATE entries SET isSelected = 0")
- suspend fun clearEntriesSelection()
-
- @Query("UPDATE entries SET isSelected = :isSelected WHERE catNum = :catNum")
- suspend fun updateEntrySelection(catNum: Int, isSelected: Boolean)
-
- @Transaction
- suspend fun updateEntriesSelection(catNums: List, isSelected: Boolean) {
- catNums.forEach { catNum -> updateEntrySelection(catNum, isSelected) }
- }
-
- @Transaction
- suspend fun updateTransmitters(transmitters: List) {
- deleteTransmitters()
- insertTransmitters(transmitters)
- }
-
- @Query("DELETE from transmitters")
- suspend fun deleteTransmitters()
-
- @Insert(onConflict = OnConflictStrategy.REPLACE)
- suspend fun insertTransmitters(transmitters: List)
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/database/SatelliteDb.kt b/app/src/main/java/com/rtbishop/look4sat/data/database/SatelliteDb.kt
deleted file mode 100644
index 5fa8a779..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/database/SatelliteDb.kt
+++ /dev/null
@@ -1,48 +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 .
- */
-package com.rtbishop.look4sat.data.database
-
-import androidx.room.Database
-import androidx.room.RoomDatabase
-import androidx.room.TypeConverters
-import androidx.room.migration.Migration
-import androidx.sqlite.db.SupportSQLiteDatabase
-import com.rtbishop.look4sat.data.model.SatEntry
-import com.rtbishop.look4sat.data.model.SatTrans
-
-@Database(entities = [SatEntry::class, SatTrans::class], version = 3)
-@TypeConverters(RoomConverters::class)
-abstract class SatelliteDb : RoomDatabase() {
-
- abstract fun satelliteDao(): SatelliteDao
-}
-
-val MIGRATION_1_2 = object : Migration(1, 2) {
- override fun migrate(database: SupportSQLiteDatabase) {
- database.execSQL("DROP TABLE sources")
- }
-}
-
-val MIGRATION_2_3 = object : Migration(2, 3) {
- override fun migrate(database: SupportSQLiteDatabase) {
- database.execSQL("CREATE TABLE trans_backup (uuid TEXT NOT NULL, info TEXT NOT NULL, isAlive INTEGER NOT NULL, downlink INTEGER, uplink INTEGER, mode TEXT, isInverted INTEGER NOT NULL, catNum INTEGER NOT NULL, PRIMARY KEY(uuid))")
- database.execSQL("INSERT INTO trans_backup (uuid, info, isAlive, downlink, uplink, mode, isInverted, catNum) SELECT uuid, description, isAlive, downlinkLow, uplinkLow, mode, isInverted, catNum FROM transmitters")
- database.execSQL("DROP TABLE transmitters")
- database.execSQL("ALTER TABLE trans_backup RENAME TO transmitters")
- }
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/model/Result.kt b/app/src/main/java/com/rtbishop/look4sat/data/model/Result.kt
deleted file mode 100644
index 9a849352..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/model/Result.kt
+++ /dev/null
@@ -1,24 +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 .
- */
-package com.rtbishop.look4sat.data.model
-
-sealed class Result {
- data class Success(val data: T) : Result()
- data class Error(val exception: Throwable) : Result()
- object InProgress : Result()
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/model/SatEntry.kt b/app/src/main/java/com/rtbishop/look4sat/data/model/SatEntry.kt
deleted file mode 100644
index f8b4e528..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/model/SatEntry.kt
+++ /dev/null
@@ -1,30 +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 .
- */
-package com.rtbishop.look4sat.data.model
-
-import androidx.room.Entity
-import androidx.room.PrimaryKey
-import com.github.amsacode.predict4java.TLE
-
-@Entity(tableName = "entries")
-data class SatEntry(
- val tle: TLE,
- var isSelected: Boolean = false,
- @PrimaryKey val catNum: Int = tle.catnum,
- val name: String = tle.name
-)
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/model/SatItem.kt b/app/src/main/java/com/rtbishop/look4sat/data/model/SatItem.kt
deleted file mode 100644
index b5902a1f..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/model/SatItem.kt
+++ /dev/null
@@ -1,33 +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 .
- */
-package com.rtbishop.look4sat.data.model
-
-import androidx.room.Relation
-
-data class SatItem(
- val catNum: Int,
- val name: String,
- var isSelected: Boolean,
- @Relation(
- parentColumn = "catNum",
- entity = SatTrans::class,
- entityColumn = "catNum",
- projection = ["mode"]
- )
- val modes: List
-)
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/model/SatPass.kt b/app/src/main/java/com/rtbishop/look4sat/data/model/SatPass.kt
deleted file mode 100644
index b66d22c3..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/model/SatPass.kt
+++ /dev/null
@@ -1,46 +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 .
- */
-package com.rtbishop.look4sat.data.model
-
-import com.rtbishop.look4sat.utility.PassPredictor
-import java.util.*
-
-data class SatPass(
- val catNum: Int,
- val name: String,
- val isDeepSpace: Boolean,
- private val aosTime: Long,
- val aosAzimuth: Double,
- private val losTime: Long,
- val losAzimuth: Double,
- private val tcaTime: Long,
- val tcaAzimuth: Double,
- val altitude: Double,
- val maxElevation: Double,
- val predictor: PassPredictor,
- var progress: Int = 0
-) {
- val aosDate: Date
- get() = Date(aosTime)
-
- val losDate: Date
- get() = Date(losTime)
-
- val tcaDate: Date
- get() = Date(tcaTime)
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/model/SatTrans.kt b/app/src/main/java/com/rtbishop/look4sat/data/model/SatTrans.kt
deleted file mode 100644
index 2d1b42c6..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/model/SatTrans.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Look4Sat. Amateur radio satellite tracker and pass predictor.
- * Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.rtbishop.look4sat.data.model
-
-import androidx.room.Entity
-import androidx.room.PrimaryKey
-import com.squareup.moshi.Json
-
-@Entity(tableName = "transmitters")
-data class SatTrans(
- @PrimaryKey @field:Json(name = "uuid") val uuid: String,
- @field:Json(name = "description") val info: String,
- @field:Json(name = "alive") val isAlive: Boolean,
- @field:Json(name = "downlink_low") var downlink: Long?,
- @field:Json(name = "uplink_low") var uplink: Long?,
- @field:Json(name = "mode") val mode: String?,
- @field:Json(name = "invert") val isInverted: Boolean,
- @field:Json(name = "norad_cat_id") val catNum: Int
-)
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/model/SelectedSat.kt b/app/src/main/java/com/rtbishop/look4sat/data/model/SelectedSat.kt
deleted file mode 100644
index 98e8e9ec..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/model/SelectedSat.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Look4Sat. Amateur radio satellite tracker and pass predictor.
- * Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.rtbishop.look4sat.data.model
-
-import com.github.amsacode.predict4java.Position
-import com.github.amsacode.predict4java.Satellite
-import org.osmdroid.views.overlay.Overlay
-
-data class SelectedSat(
- val pass: Satellite,
- val catNum: Int,
- val name: String,
- val range: Double,
- val altitude: Double,
- val velocity: Double,
- val qthLoc: String,
- val osmPos: Position,
- val footprint: Overlay,
- val groundTrack: Overlay
-)
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/model/TleSource.kt b/app/src/main/java/com/rtbishop/look4sat/data/model/TleSource.kt
deleted file mode 100644
index 58c261df..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/model/TleSource.kt
+++ /dev/null
@@ -1,20 +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 .
- */
-package com.rtbishop.look4sat.data.model
-
-class TleSource(var url: String = String())
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/repository/SatelliteRepo.kt b/app/src/main/java/com/rtbishop/look4sat/data/repository/SatelliteRepo.kt
deleted file mode 100644
index 16cf272f..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/data/repository/SatelliteRepo.kt
+++ /dev/null
@@ -1,127 +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 .
- */
-package com.rtbishop.look4sat.data.repository
-
-import android.content.ContentResolver
-import android.net.Uri
-import com.github.amsacode.predict4java.Satellite
-import com.github.amsacode.predict4java.TLE
-import com.rtbishop.look4sat.data.api.SatelliteService
-import com.rtbishop.look4sat.data.database.SatelliteDao
-import com.rtbishop.look4sat.data.model.SatEntry
-import com.rtbishop.look4sat.data.model.SatItem
-import com.rtbishop.look4sat.data.model.SatTrans
-import com.rtbishop.look4sat.data.model.TleSource
-import com.rtbishop.look4sat.di.IoDispatcher
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.coroutineScope
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
-import java.io.InputStream
-import java.util.zip.ZipInputStream
-import javax.inject.Inject
-import javax.inject.Singleton
-
-@Singleton
-class SatelliteRepo @Inject constructor(
- private val resolver: ContentResolver,
- private val satelliteDao: SatelliteDao,
- private val satelliteService: SatelliteService,
- @IoDispatcher private val ioDispatcher: CoroutineDispatcher
-) {
-
- fun getSatItems(): Flow> {
- return satelliteDao.getSatItems()
- }
-
- fun getSatTransmitters(catNum: Int): Flow> {
- return satelliteDao.getSatTransmitters(catNum)
- }
-
- suspend fun getSelectedSatellites(): List {
- return satelliteDao.getSelectedSatellites()
- }
-
- suspend fun importSatDataFromFile(uri: Uri) {
- runCatching {
- resolver.openInputStream(uri)?.use { stream ->
- val entries = importEntriesFromStreams(listOf(stream))
- satelliteDao.updateEntries(entries)
- }
- }.onFailure { throw it }
- }
-
- suspend fun importSatDataFromWeb(sources: List) {
- coroutineScope {
- launch { importEntriesFromSources(sources) }
- launch { importTransmitters() }
- }
- }
-
- suspend fun updateEntriesSelection(catNums: List, isSelected: Boolean) {
- satelliteDao.updateEntriesSelection(catNums, isSelected)
- }
-
- private suspend fun importEntriesFromSources(sources: List) {
- val streams = getStreamsForSources(sources)
- val entries = importEntriesFromStreams(streams)
- satelliteDao.updateEntries(entries)
- }
-
- private suspend fun importTransmitters() {
- val transmitters = satelliteService.fetchTransmitters().filter { it.isAlive }
- satelliteDao.updateTransmitters(transmitters)
- }
-
- private suspend fun getStreamsForSources(sources: List): List {
- val streams = mutableListOf()
- sources.forEach { tleSource ->
- satelliteService.fetchFileByUrl(tleSource.url).body()?.byteStream()?.let { stream ->
- if (tleSource.url.contains(".zip", true)) {
- streams.add(getZipStream(stream))
- } else {
- streams.add(stream)
- }
- }
- }
- return streams
- }
-
- private suspend fun getZipStream(inputStream: InputStream): InputStream {
- var stream: InputStream
- withContext(ioDispatcher) {
- ZipInputStream(inputStream).apply {
- nextEntry
- stream = this
- }
- }
- return stream
- }
-
- private suspend fun importEntriesFromStreams(streams: List): List {
- val importedEntries = mutableListOf()
- withContext(ioDispatcher) {
- streams.forEach { stream ->
- val entries = TLE.importSat(stream).map { tle -> SatEntry(tle) }
- importedEntries.addAll(entries)
- }
- }
- return importedEntries
- }
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/di/InteractorsModule.kt b/app/src/main/java/com/rtbishop/look4sat/di/InteractorsModule.kt
new file mode 100644
index 00000000..ed445956
--- /dev/null
+++ b/app/src/main/java/com/rtbishop/look4sat/di/InteractorsModule.kt
@@ -0,0 +1,43 @@
+package com.rtbishop.look4sat.di
+
+import com.rtbishop.look4sat.domain.SatelliteRepo
+import com.rtbishop.look4sat.interactors.*
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.components.SingletonComponent
+
+@Module
+@InstallIn(SingletonComponent::class)
+object InteractorsModule {
+
+ @Provides
+ fun provideGetSatItemsUseCase(satelliteRepo: SatelliteRepo): GetSatItems {
+ return GetSatItems(satelliteRepo)
+ }
+
+ @Provides
+ fun provideGetSelectedSatellitesUseCase(satelliteRepo: SatelliteRepo): GetSelectedSatellites {
+ return GetSelectedSatellites(satelliteRepo)
+ }
+
+ @Provides
+ fun provideGetTransmittersForSatUseCase(satelliteRepo: SatelliteRepo): GetTransmittersForSat {
+ return GetTransmittersForSat(satelliteRepo)
+ }
+
+ @Provides
+ fun provideImportDataFromFileUseCase(satelliteRepo: SatelliteRepo): ImportDataFromFile {
+ return ImportDataFromFile(satelliteRepo)
+ }
+
+ @Provides
+ fun provideImportDataFromWebUseCase(satelliteRepo: SatelliteRepo): ImportDataFromWeb {
+ return ImportDataFromWeb(satelliteRepo)
+ }
+
+ @Provides
+ fun provideUpdateEntriesSelectionUseCase(satelliteRepo: SatelliteRepo): UpdateEntriesSelection {
+ return UpdateEntriesSelection(satelliteRepo)
+ }
+}
diff --git a/app/src/main/java/com/rtbishop/look4sat/di/RepositoryModule.kt b/app/src/main/java/com/rtbishop/look4sat/di/LocalSourceModule.kt
similarity index 57%
rename from app/src/main/java/com/rtbishop/look4sat/di/RepositoryModule.kt
rename to app/src/main/java/com/rtbishop/look4sat/di/LocalSourceModule.kt
index f9b50b86..c9110b21 100644
--- a/app/src/main/java/com/rtbishop/look4sat/di/RepositoryModule.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/di/LocalSourceModule.kt
@@ -19,29 +19,55 @@ package com.rtbishop.look4sat.di
import android.content.Context
import androidx.room.Room
-import com.rtbishop.look4sat.data.database.*
+import com.rtbishop.look4sat.data.DefaultSatelliteRepo
+import com.rtbishop.look4sat.data.LocalDataSource
+import com.rtbishop.look4sat.data.RemoteDataSource
+import com.rtbishop.look4sat.domain.SatelliteRepo
+import com.rtbishop.look4sat.framework.db.RoomConverters
+import com.rtbishop.look4sat.framework.db.RoomDataSource
+import com.rtbishop.look4sat.framework.db.SatelliteDao
+import com.rtbishop.look4sat.framework.db.SatelliteDb
import com.squareup.moshi.Moshi
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
+import kotlinx.coroutines.CoroutineDispatcher
+import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
-object RepositoryModule {
-
+object LocalSourceModule {
+
+ @Provides
+ fun provideLocalDataSource(satelliteDao: SatelliteDao): LocalDataSource {
+ return RoomDataSource(satelliteDao)
+ }
+
+ @Provides
+ @Singleton
+ fun provideDefaultRepository(
+ localSource: LocalDataSource,
+ remoteSource: RemoteDataSource,
+ @IoDispatcher ioDispatcher: CoroutineDispatcher
+ ): SatelliteRepo {
+ return DefaultSatelliteRepo(localSource, remoteSource, ioDispatcher)
+ }
+
+ @Provides
+ fun provideMoshi(): Moshi {
+ return Moshi.Builder().build()
+ }
+
@Provides
fun provideSatDataDao(db: SatelliteDb): SatelliteDao {
return db.satelliteDao()
}
-
+
@Provides
fun provideSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
RoomConverters.initialize(moshi)
- return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb")
- .addMigrations(MIGRATION_1_2)
- .addMigrations(MIGRATION_2_3)
- .build()
+ return Room.databaseBuilder(context, SatelliteDb::class.java, "SatelliteDb").build()
}
}
diff --git a/app/src/main/java/com/rtbishop/look4sat/di/NetworkModule.kt b/app/src/main/java/com/rtbishop/look4sat/di/RemoteSourceModule.kt
similarity index 80%
rename from app/src/main/java/com/rtbishop/look4sat/di/NetworkModule.kt
rename to app/src/main/java/com/rtbishop/look4sat/di/RemoteSourceModule.kt
index e4340bdb..e7a98b2e 100644
--- a/app/src/main/java/com/rtbishop/look4sat/di/NetworkModule.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/di/RemoteSourceModule.kt
@@ -17,8 +17,9 @@
*/
package com.rtbishop.look4sat.di
-import com.rtbishop.look4sat.data.api.SatelliteService
-import com.squareup.moshi.Moshi
+import com.rtbishop.look4sat.data.RemoteDataSource
+import com.rtbishop.look4sat.framework.api.NetworkDataSource
+import com.rtbishop.look4sat.framework.api.SatelliteService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -28,13 +29,13 @@ import retrofit2.converter.moshi.MoshiConverterFactory
@Module
@InstallIn(SingletonComponent::class)
-object NetworkModule {
-
+object RemoteSourceModule {
+
@Provides
- fun provideMoshi(): Moshi {
- return Moshi.Builder().build()
+ fun provideRemoteDataSource(satelliteService: SatelliteService): RemoteDataSource {
+ return NetworkDataSource(satelliteService)
}
-
+
@Provides
fun provideSatDataService(): SatelliteService {
return Retrofit.Builder()
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/api/RetrofitDataSource.kt b/app/src/main/java/com/rtbishop/look4sat/framework/api/NetworkDataSource.kt
similarity index 68%
rename from app/src/main/java/com/rtbishop/look4sat/framework/api/RetrofitDataSource.kt
rename to app/src/main/java/com/rtbishop/look4sat/framework/api/NetworkDataSource.kt
index 3852fbce..c71f5bd6 100644
--- a/app/src/main/java/com/rtbishop/look4sat/framework/api/RetrofitDataSource.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/framework/api/NetworkDataSource.kt
@@ -4,14 +4,14 @@ import com.rtbishop.look4sat.data.RemoteDataSource
import com.rtbishop.look4sat.domain.model.SatTrans
import java.io.InputStream
-class RetrofitDataSource(private val satelliteService: SatelliteService) : RemoteDataSource {
+class NetworkDataSource(private val api: SatelliteService) : RemoteDataSource {
override suspend fun fetchFileStream(url: String): InputStream? {
- return satelliteService.fetchFileByUrl(url).body()?.byteStream()
+ return api.fetchFileByUrl(url).body()?.byteStream()
}
override suspend fun fetchTransmitters(): List {
- return satelliteService.fetchTransmitters().map { trans ->
+ return api.fetchTransmitters().map { trans ->
SatTrans(
trans.uuid, trans.info, trans.isAlive, trans.downlink,
trans.uplink, trans.mode, trans.isInverted, trans.catNum
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomConverters.kt b/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomConverters.kt
index 29948ae3..c510a02a 100644
--- a/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomConverters.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomConverters.kt
@@ -18,8 +18,8 @@
package com.rtbishop.look4sat.framework.db
import androidx.room.TypeConverter
-import com.rtbishop.look4sat.predict4kotlin.Satellite
-import com.rtbishop.look4sat.predict4kotlin.TLE
+import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
+import com.rtbishop.look4sat.domain.predict4kotlin.TLE
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomDataSource.kt b/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomDataSource.kt
index 1036c718..39dee5da 100644
--- a/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomDataSource.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/framework/db/RoomDataSource.kt
@@ -4,7 +4,7 @@ import com.rtbishop.look4sat.data.LocalDataSource
import com.rtbishop.look4sat.domain.model.SatEntry
import com.rtbishop.look4sat.domain.model.SatItem
import com.rtbishop.look4sat.domain.model.SatTrans
-import com.rtbishop.look4sat.predict4kotlin.Satellite
+import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
import com.rtbishop.look4sat.utility.DataMapper
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
@@ -38,4 +38,4 @@ class RoomDataSource(private val satelliteDao: SatelliteDao) : LocalDataSource {
val satTransList = DataMapper.domainTransListToSatTransList(satelliteTrans)
satelliteDao.updateTransmitters(satTransList)
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/db/SatelliteDao.kt b/app/src/main/java/com/rtbishop/look4sat/framework/db/SatelliteDao.kt
index 0e84875e..443e02cf 100644
--- a/app/src/main/java/com/rtbishop/look4sat/framework/db/SatelliteDao.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/framework/db/SatelliteDao.kt
@@ -21,7 +21,7 @@ import androidx.room.*
import com.rtbishop.look4sat.framework.model.SatEntry
import com.rtbishop.look4sat.framework.model.SatItem
import com.rtbishop.look4sat.framework.model.SatTrans
-import com.rtbishop.look4sat.predict4kotlin.Satellite
+import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
import kotlinx.coroutines.flow.Flow
@Dao
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/model/SatEntry.kt b/app/src/main/java/com/rtbishop/look4sat/framework/model/SatEntry.kt
index 4d7aec2a..04ecf80e 100644
--- a/app/src/main/java/com/rtbishop/look4sat/framework/model/SatEntry.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/framework/model/SatEntry.kt
@@ -19,7 +19,7 @@ package com.rtbishop.look4sat.framework.model
import androidx.room.Entity
import androidx.room.PrimaryKey
-import com.rtbishop.look4sat.predict4kotlin.TLE
+import com.rtbishop.look4sat.domain.predict4kotlin.TLE
@Entity(tableName = "entries")
data class SatEntry(
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/model/SatPass.kt b/app/src/main/java/com/rtbishop/look4sat/framework/model/SatPass.kt
deleted file mode 100644
index 6d99ce58..00000000
--- a/app/src/main/java/com/rtbishop/look4sat/framework/model/SatPass.kt
+++ /dev/null
@@ -1,46 +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 .
- */
-package com.rtbishop.look4sat.framework.model
-
-import com.rtbishop.look4sat.utility.PassPredictor
-import java.util.*
-
-data class SatPass(
- val catNum: Int,
- val name: String,
- val isDeepSpace: Boolean,
- private val aosTime: Long,
- val aosAzimuth: Double,
- private val losTime: Long,
- val losAzimuth: Double,
- private val tcaTime: Long,
- val tcaAzimuth: Double,
- val altitude: Double,
- val maxElevation: Double,
- val predictor: PassPredictor,
- var progress: Int = 0
-) {
- val aosDate: Date
- get() = Date(aosTime)
-
- val losDate: Date
- get() = Date(losTime)
-
- val tcaDate: Date
- get() = Date(tcaTime)
-}
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/model/SelectedSat.kt b/app/src/main/java/com/rtbishop/look4sat/framework/model/SelectedSat.kt
index 5b47ff91..df94382b 100644
--- a/app/src/main/java/com/rtbishop/look4sat/framework/model/SelectedSat.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/framework/model/SelectedSat.kt
@@ -17,8 +17,8 @@
*/
package com.rtbishop.look4sat.framework.model
-import com.github.amsacode.predict4java.Position
-import com.github.amsacode.predict4java.Satellite
+import com.rtbishop.look4sat.domain.predict4kotlin.Position
+import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
import org.osmdroid.views.overlay.Overlay
data class SelectedSat(
diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesAdapter.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesAdapter.kt
index 080bc891..5ed24f13 100644
--- a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesAdapter.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesAdapter.kt
@@ -22,8 +22,8 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
-import com.rtbishop.look4sat.data.model.SatItem
import com.rtbishop.look4sat.databinding.SatItemBinding
+import com.rtbishop.look4sat.domain.model.SatItem
class EntriesAdapter : RecyclerView.Adapter() {
diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragment.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragment.kt
index 8e25b1a9..8f0c6e70 100644
--- a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragment.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragment.kt
@@ -27,10 +27,10 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.SimpleItemAnimator
import com.google.android.material.snackbar.Snackbar
import com.rtbishop.look4sat.R
-import com.rtbishop.look4sat.data.model.Result
-import com.rtbishop.look4sat.data.model.SatItem
-import com.rtbishop.look4sat.data.model.TleSource
+import com.rtbishop.look4sat.framework.model.Result
import com.rtbishop.look4sat.databinding.FragmentEntriesBinding
+import com.rtbishop.look4sat.domain.model.SatItem
+import com.rtbishop.look4sat.framework.model.TleSource
import com.rtbishop.look4sat.utility.RecyclerDivider
import com.rtbishop.look4sat.utility.getNavResult
import com.rtbishop.look4sat.utility.navigateSafe
diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesViewModel.kt
index 9ce948da..37923f3e 100644
--- a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesViewModel.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesViewModel.kt
@@ -17,6 +17,7 @@
*/
package com.rtbishop.look4sat.presentation.entriesScreen
+import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import android.widget.SearchView
@@ -24,10 +25,13 @@ import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.*
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.rtbishop.look4sat.R
-import com.rtbishop.look4sat.data.model.Result
-import com.rtbishop.look4sat.data.model.SatItem
-import com.rtbishop.look4sat.data.model.TleSource
-import com.rtbishop.look4sat.data.repository.SatelliteRepo
+import com.rtbishop.look4sat.domain.model.SatItem
+import com.rtbishop.look4sat.framework.model.Result
+import com.rtbishop.look4sat.framework.model.TleSource
+import com.rtbishop.look4sat.interactors.GetSatItems
+import com.rtbishop.look4sat.interactors.ImportDataFromFile
+import com.rtbishop.look4sat.interactors.ImportDataFromWeb
+import com.rtbishop.look4sat.interactors.UpdateEntriesSelection
import com.rtbishop.look4sat.utility.PrefsManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collect
@@ -40,13 +44,17 @@ import kotlin.system.measureTimeMillis
@HiltViewModel
class EntriesViewModel @Inject constructor(
private val prefsManager: PrefsManager,
- private val satelliteRepo: SatelliteRepo
+ private val resolver: ContentResolver,
+ private val getSatItems: GetSatItems,
+ private val importDataFromFile: ImportDataFromFile,
+ private val importDataFromWeb: ImportDataFromWeb,
+ private val updateEntriesSelection: UpdateEntriesSelection,
) : ViewModel(), EntriesAdapter.EntriesClickListener, SearchView.OnQueryTextListener {
private val transModes = MutableLiveData(prefsManager.loadModesSelection())
private val currentQuery = MutableLiveData(String())
private val itemsWithModes = transModes.switchMap { modes ->
- liveData { satelliteRepo.getSatItems().collect { emit(filterByModes(it, modes)) } }
+ liveData { getSatItems().collect { emit(filterByModes(it, modes)) } }
}
private val itemsWithQuery = currentQuery.switchMap { query ->
itemsWithModes.map { items -> Result.Success(filterByQuery(items, query)) }
@@ -60,11 +68,11 @@ class EntriesViewModel @Inject constructor(
fun importSatDataFromFile(uri: Uri) {
viewModelScope.launch {
_satData.value = Result.InProgress
- try {
- satelliteRepo.importSatDataFromFile(uri)
- } catch (exception: Exception) {
- _satData.value = Result.Error(exception)
- }
+ runCatching {
+ resolver.openInputStream(uri)?.use { stream ->
+ importDataFromFile(stream)
+ }
+ }.onFailure { _satData.value = Result.Error(it) }
}
}
@@ -76,9 +84,10 @@ class EntriesViewModel @Inject constructor(
val updateMillis = measureTimeMillis {
try {
prefsManager.saveTleSources(satSources)
- satelliteRepo.importSatDataFromWeb(satSources)
+ importDataFromWeb(satSources.map { it.url })
} catch (exception: Exception) {
_satData.value = Result.Error(exception)
+ Timber.d(exception)
}
}
Timber.d("Update from WEB took $updateMillis ms")
@@ -133,7 +142,7 @@ class EntriesViewModel @Inject constructor(
}
override fun updateSelection(catNums: List, isSelected: Boolean) {
- viewModelScope.launch { satelliteRepo.updateEntriesSelection(catNums, isSelected) }
+ viewModelScope.launch { updateEntriesSelection(catNums, isSelected) }
}
private fun filterByModes(items: List, modes: List): List {
diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapFragment.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapFragment.kt
index 3d57611b..071fbccd 100644
--- a/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapFragment.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapFragment.kt
@@ -25,11 +25,11 @@ import android.view.View
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
-import com.github.amsacode.predict4java.Position
-import com.github.amsacode.predict4java.Satellite
import com.rtbishop.look4sat.R
-import com.rtbishop.look4sat.data.model.SelectedSat
import com.rtbishop.look4sat.databinding.FragmentMapBinding
+import com.rtbishop.look4sat.framework.model.SelectedSat
+import com.rtbishop.look4sat.domain.predict4kotlin.Position
+import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
import com.rtbishop.look4sat.utility.PrefsManager
import dagger.hilt.android.AndroidEntryPoint
import org.osmdroid.config.Configuration
diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapViewModel.kt
index 3d6f160f..b4bb3a3b 100644
--- a/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapViewModel.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/mapScreen/MapViewModel.kt
@@ -20,11 +20,11 @@ package com.rtbishop.look4sat.presentation.mapScreen
import android.graphics.Color
import android.graphics.Paint
import androidx.lifecycle.*
-import com.github.amsacode.predict4java.Position
-import com.github.amsacode.predict4java.SatPos
-import com.github.amsacode.predict4java.Satellite
-import com.rtbishop.look4sat.data.model.SelectedSat
-import com.rtbishop.look4sat.data.repository.SatelliteRepo
+import com.rtbishop.look4sat.framework.model.SelectedSat
+import com.rtbishop.look4sat.interactors.GetSelectedSatellites
+import com.rtbishop.look4sat.domain.predict4kotlin.Position
+import com.rtbishop.look4sat.domain.predict4kotlin.SatPos
+import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
import com.rtbishop.look4sat.utility.*
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.*
@@ -39,9 +39,9 @@ import javax.inject.Inject
@HiltViewModel
class MapViewModel @Inject constructor(
- prefsManager: PrefsManager,
- private val satelliteRepo: SatelliteRepo,
- private val qthConverter: QthConverter
+ private val getSelectedSatellites: GetSelectedSatellites,
+ private val qthConverter: QthConverter,
+ prefsManager: PrefsManager
) : ViewModel() {
private val dateNow = Date()
@@ -71,12 +71,12 @@ class MapViewModel @Inject constructor(
fun getSatMarkers(): LiveData