Simplified transmitters, added database migration

This commit is contained in:
Arty Bishop committed 2021-03-23 10:28:51 +00:00
1 parent a882a73b8e
commit 6f8db0b9b1
6 files changed
+145 -38

No files matched your search

@@ -2,7 +2,7 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 2, "version": 2,
"identityHash": "ae51481b0cb1f66d055cd7487e79ad2c", "identityHash": "24170ecaf2ab85adb66aa3b557134997",
"entities": [ "entities": [
{ {
"tableName": "entries", "tableName": "entries",
@@ -44,7 +44,7 @@
}, },
{ {
"tableName": "transmitters", "tableName": "transmitters",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `description` TEXT NOT NULL, `isAlive` INTEGER NOT NULL, `uplinkLow` INTEGER, `uplinkHigh` INTEGER, `downlinkLow` INTEGER, `downlinkHigh` INTEGER, `mode` TEXT, `isInverted` INTEGER NOT NULL, `catNum` INTEGER NOT NULL, PRIMARY KEY(`uuid`))", "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `description` TEXT NOT NULL, `isAlive` INTEGER NOT NULL, `uplink` INTEGER, `downlink` INTEGER, `mode` TEXT, `isInverted` INTEGER NOT NULL, `catNum` INTEGER NOT NULL, PRIMARY KEY(`uuid`))",
"fields": [ "fields": [
{ {
"fieldPath": "uuid", "fieldPath": "uuid",
@@ -65,26 +65,14 @@
"notNull": true "notNull": true
}, },
{ {
"fieldPath": "uplinkLow", "fieldPath": "uplink",
"columnName": "uplinkLow", "columnName": "uplink",
"affinity": "INTEGER", "affinity": "INTEGER",
"notNull": false "notNull": false
}, },
{ {
"fieldPath": "uplinkHigh", "fieldPath": "downlink",
"columnName": "uplinkHigh", "columnName": "downlink",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "downlinkLow",
"columnName": "downlinkLow",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "downlinkHigh",
"columnName": "downlinkHigh",
"affinity": "INTEGER", "affinity": "INTEGER",
"notNull": false "notNull": false
}, },
@@ -120,7 +108,7 @@
"views": [], "views": [],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "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, 'ae51481b0cb1f66d055cd7487e79ad2c')" "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '24170ecaf2ab85adb66aa3b557134997')"
] ]
} }
} }
@@ -0,0 +1,114 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "53fa623fc55b279c50d33e6263866a89",
"entities": [
{
"tableName": "entries",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`tle` TEXT NOT NULL, `isSelected` INTEGER NOT NULL, `catNum` INTEGER NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY(`catNum`))",
"fields": [
{
"fieldPath": "tle",
"columnName": "tle",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isSelected",
"columnName": "isSelected",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "catNum",
"columnName": "catNum",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"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')"
]
}
}
@@ -25,7 +25,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import com.rtbishop.look4sat.data.model.SatEntry import com.rtbishop.look4sat.data.model.SatEntry
import com.rtbishop.look4sat.data.model.SatTrans import com.rtbishop.look4sat.data.model.SatTrans
@Database(entities = [SatEntry::class, SatTrans::class], version = 2) @Database(entities = [SatEntry::class, SatTrans::class], version = 3)
@TypeConverters(RoomConverters::class) @TypeConverters(RoomConverters::class)
abstract class SatelliteDb : RoomDatabase() { abstract class SatelliteDb : RoomDatabase() {
@@ -37,3 +37,12 @@ val MIGRATION_1_2 = object : Migration(1, 2) {
database.execSQL("DROP TABLE sources") 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")
}
}
@@ -24,12 +24,10 @@ import com.squareup.moshi.Json
@Entity(tableName = "transmitters") @Entity(tableName = "transmitters")
class SatTrans( class SatTrans(
@PrimaryKey @field:Json(name = "uuid") val uuid: String, @PrimaryKey @field:Json(name = "uuid") val uuid: String,
@field:Json(name = "description") val description: String, @field:Json(name = "description") val info: String,
@field:Json(name = "alive") val isAlive: Boolean, @field:Json(name = "alive") val isAlive: Boolean,
@field:Json(name = "uplink_low") val uplinkLow: Long?, @field:Json(name = "downlink_low") val downlink: Long?,
@field:Json(name = "uplink_high") val uplinkHigh: Long?, @field:Json(name = "uplink_low") val uplink: Long?,
@field:Json(name = "downlink_low") val downlinkLow: Long?,
@field:Json(name = "downlink_high") val downlinkHigh: Long?,
@field:Json(name = "mode") val mode: String?, @field:Json(name = "mode") val mode: String?,
@field:Json(name = "invert") val isInverted: Boolean, @field:Json(name = "invert") val isInverted: Boolean,
@field:Json(name = "norad_cat_id") val catNum: Int @field:Json(name = "norad_cat_id") val catNum: Int
@@ -19,10 +19,7 @@ package com.rtbishop.look4sat.di
import android.content.Context import android.content.Context
import androidx.room.Room import androidx.room.Room
import com.rtbishop.look4sat.data.database.MIGRATION_1_2 import com.rtbishop.look4sat.data.database.*
import com.rtbishop.look4sat.data.database.RoomConverters
import com.rtbishop.look4sat.data.database.SatelliteDao
import com.rtbishop.look4sat.data.database.SatelliteDb
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
@@ -44,6 +41,7 @@ object RepositoryModule {
RoomConverters.initialize(moshi) RoomConverters.initialize(moshi)
return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb") return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb")
.addMigrations(MIGRATION_1_2) .addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.build() .build()
} }
} }
@@ -67,7 +67,7 @@ class TransAdapter(private val pass: SatPass) : RecyclerView.Adapter<TransAdapte
private val isInverted = itemView.context.getString(R.string.trans_inverted) private val isInverted = itemView.context.getString(R.string.trans_inverted)
fun bind(satTrans: SatTrans, satPass: SatPass) { fun bind(satTrans: SatTrans, satPass: SatPass) {
binding.description.text = satTrans.description binding.description.text = satTrans.info
if (satPass.isDeepSpace) setRegularFreq(satTrans) if (satPass.isDeepSpace) setRegularFreq(satTrans)
else setDopplerFreq(satTrans, satPass.predictor) else setDopplerFreq(satTrans, satPass.predictor)
@@ -80,25 +80,25 @@ class TransAdapter(private val pass: SatPass) : RecyclerView.Adapter<TransAdapte
} }
private fun setRegularFreq(satTrans: SatTrans) { private fun setRegularFreq(satTrans: SatTrans) {
if (satTrans.downlinkLow != null) { if (satTrans.downlink != null) {
val downFreq = satTrans.downlinkLow / divider val downFreq = satTrans.downlink / divider
binding.downlink.text = String.format(Locale.ENGLISH, formatLink, downFreq) binding.downlink.text = String.format(Locale.ENGLISH, formatLink, downFreq)
} else binding.downlink.text = formatLinkNull } else binding.downlink.text = formatLinkNull
if (satTrans.uplinkLow != null) { if (satTrans.uplink != null) {
val upFreq = satTrans.uplinkLow / divider val upFreq = satTrans.uplink / divider
binding.uplink.text = String.format(Locale.ENGLISH, formatLink, upFreq) binding.uplink.text = String.format(Locale.ENGLISH, formatLink, upFreq)
} else binding.uplink.text = formatLinkNull } else binding.uplink.text = formatLinkNull
} }
private fun setDopplerFreq(satTrans: SatTrans, predictor: PassPredictor) { private fun setDopplerFreq(satTrans: SatTrans, predictor: PassPredictor) {
if (satTrans.downlinkLow != null) { if (satTrans.downlink != null) {
val downlink = predictor.getDownlinkFreq(satTrans.downlinkLow, dateNow) / divider val downlink = predictor.getDownlinkFreq(satTrans.downlink, dateNow) / divider
binding.downlink.text = String.format(Locale.ENGLISH, formatLink, downlink) binding.downlink.text = String.format(Locale.ENGLISH, formatLink, downlink)
} else binding.downlink.text = formatLinkNull } else binding.downlink.text = formatLinkNull
if (satTrans.uplinkLow != null) { if (satTrans.uplink != null) {
val uplink = predictor.getUplinkFreq(satTrans.uplinkLow, dateNow) / divider val uplink = predictor.getUplinkFreq(satTrans.uplink, dateNow) / divider
binding.uplink.text = String.format(Locale.ENGLISH, formatLink, uplink) binding.uplink.text = String.format(Locale.ENGLISH, formatLink, uplink)
} else binding.uplink.text = formatLinkNull } else binding.uplink.text = formatLinkNull
} }