mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-03 11:37:24 +00:00
Simplified transmitters, added database migration
This commit is contained in:
1 parent
a882a73b8e
commit
6f8db0b9b1
6 files changed
+146
-39
No files matched your search
@@ -25,10 +25,10 @@ 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 = 2)
|
||||
@Database(entities = [SatEntry::class, SatTrans::class], version = 3)
|
||||
@TypeConverters(RoomConverters::class)
|
||||
abstract class SatelliteDb : RoomDatabase() {
|
||||
|
||||
|
||||
abstract fun satelliteDao(): SatelliteDao
|
||||
}
|
||||
|
||||
@@ -37,3 +37,12 @@ val MIGRATION_1_2 = object : Migration(1, 2) {
|
||||
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")
|
||||
class SatTrans(
|
||||
@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 = "uplink_low") val uplinkLow: Long?,
|
||||
@field:Json(name = "uplink_high") val uplinkHigh: Long?,
|
||||
@field:Json(name = "downlink_low") val downlinkLow: Long?,
|
||||
@field:Json(name = "downlink_high") val downlinkHigh: Long?,
|
||||
@field:Json(name = "downlink_low") val downlink: Long?,
|
||||
@field:Json(name = "uplink_low") val 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
|
||||
|
||||
@@ -19,10 +19,7 @@ package com.rtbishop.look4sat.di
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import com.rtbishop.look4sat.data.database.MIGRATION_1_2
|
||||
import com.rtbishop.look4sat.data.database.RoomConverters
|
||||
import com.rtbishop.look4sat.data.database.SatelliteDao
|
||||
import com.rtbishop.look4sat.data.database.SatelliteDb
|
||||
import com.rtbishop.look4sat.data.database.*
|
||||
import com.squareup.moshi.Moshi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
@@ -44,6 +41,7 @@ object RepositoryModule {
|
||||
RoomConverters.initialize(moshi)
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb")
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_2_3)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class TransAdapter(private val pass: SatPass) : RecyclerView.Adapter<TransAdapte
|
||||
private val isInverted = itemView.context.getString(R.string.trans_inverted)
|
||||
|
||||
fun bind(satTrans: SatTrans, satPass: SatPass) {
|
||||
binding.description.text = satTrans.description
|
||||
binding.description.text = satTrans.info
|
||||
|
||||
if (satPass.isDeepSpace) setRegularFreq(satTrans)
|
||||
else setDopplerFreq(satTrans, satPass.predictor)
|
||||
@@ -80,25 +80,25 @@ class TransAdapter(private val pass: SatPass) : RecyclerView.Adapter<TransAdapte
|
||||
}
|
||||
|
||||
private fun setRegularFreq(satTrans: SatTrans) {
|
||||
if (satTrans.downlinkLow != null) {
|
||||
val downFreq = satTrans.downlinkLow / divider
|
||||
if (satTrans.downlink != null) {
|
||||
val downFreq = satTrans.downlink / divider
|
||||
binding.downlink.text = String.format(Locale.ENGLISH, formatLink, downFreq)
|
||||
} else binding.downlink.text = formatLinkNull
|
||||
|
||||
if (satTrans.uplinkLow != null) {
|
||||
val upFreq = satTrans.uplinkLow / divider
|
||||
if (satTrans.uplink != null) {
|
||||
val upFreq = satTrans.uplink / divider
|
||||
binding.uplink.text = String.format(Locale.ENGLISH, formatLink, upFreq)
|
||||
} else binding.uplink.text = formatLinkNull
|
||||
}
|
||||
|
||||
private fun setDopplerFreq(satTrans: SatTrans, predictor: PassPredictor) {
|
||||
if (satTrans.downlinkLow != null) {
|
||||
val downlink = predictor.getDownlinkFreq(satTrans.downlinkLow, dateNow) / divider
|
||||
if (satTrans.downlink != null) {
|
||||
val downlink = predictor.getDownlinkFreq(satTrans.downlink, dateNow) / divider
|
||||
binding.downlink.text = String.format(Locale.ENGLISH, formatLink, downlink)
|
||||
} else binding.downlink.text = formatLinkNull
|
||||
|
||||
if (satTrans.uplinkLow != null) {
|
||||
val uplink = predictor.getUplinkFreq(satTrans.uplinkLow, dateNow) / divider
|
||||
if (satTrans.uplink != null) {
|
||||
val uplink = predictor.getUplinkFreq(satTrans.uplink, dateNow) / divider
|
||||
binding.uplink.text = String.format(Locale.ENGLISH, formatLink, uplink)
|
||||
} else binding.uplink.text = formatLinkNull
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user