mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added room type converter for Satellite objects
This commit is contained in:
1 parent
4705ff6915
commit
0dfd7e6250
4 files changed
+24
-15
No files matched your search
@@ -21,6 +21,7 @@ package com.rtbishop.look4sat.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.SatEntry
|
||||
import com.rtbishop.look4sat.data.SatItem
|
||||
@@ -46,8 +47,8 @@ class SatelliteRepo @Inject constructor(
|
||||
return satelliteDao.getSatItems()
|
||||
}
|
||||
|
||||
suspend fun getSelectedEntries(): List<SatEntry> {
|
||||
return satelliteDao.getSelectedEntries()
|
||||
suspend fun getSelectedSatellites(): List<Satellite> {
|
||||
return satelliteDao.getSelectedSatellites()
|
||||
}
|
||||
|
||||
suspend fun updateEntriesSelection(catNums: List<Int>) {
|
||||
|
||||
@@ -20,6 +20,8 @@ You should have received a copy of the GNU General Public License along
|
||||
package com.rtbishop.look4sat.repository.localData
|
||||
|
||||
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
|
||||
@@ -43,4 +45,11 @@ object RoomConverters {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
package com.rtbishop.look4sat.repository.localData
|
||||
|
||||
import androidx.room.*
|
||||
import com.github.amsacode.predict4java.Satellite
|
||||
import com.rtbishop.look4sat.data.SatEntry
|
||||
import com.rtbishop.look4sat.data.SatItem
|
||||
import com.rtbishop.look4sat.data.SatTrans
|
||||
@@ -37,8 +38,8 @@ interface SatelliteDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertEntries(entries: List<SatEntry>)
|
||||
|
||||
@Query("SELECT * FROM entries WHERE isSelected = 1 ORDER BY name ASC")
|
||||
suspend fun getSelectedEntries(): List<SatEntry>
|
||||
@Query("SELECT tle FROM entries WHERE isSelected = 1")
|
||||
suspend fun getSelectedSatellites(): List<Satellite>
|
||||
|
||||
@Query("SELECT catNum FROM entries WHERE isSelected = 1")
|
||||
suspend fun getSelectedCatNums(): List<Int>
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.rtbishop.look4sat.ui
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.*
|
||||
import com.github.amsacode.predict4java.SatelliteFactory
|
||||
import com.github.amsacode.predict4java.Satellite
|
||||
import com.rtbishop.look4sat.data.*
|
||||
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||
import com.rtbishop.look4sat.repository.SatelliteRepo
|
||||
@@ -68,8 +68,8 @@ class SharedViewModel @Inject constructor(
|
||||
_passes.value = Result.InProgress
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
val passes = mutableListOf<SatPass>()
|
||||
satelliteRepo.getSelectedEntries().forEach { entry ->
|
||||
passes.addAll(getPasses(entry, dateNow))
|
||||
satelliteRepo.getSelectedSatellites().forEach { satellite ->
|
||||
passes.addAll(getPasses(satellite, dateNow))
|
||||
}
|
||||
val filteredPasses = sortList(passes, dateNow)
|
||||
_passes.postValue(Result.Success(filteredPasses))
|
||||
@@ -112,16 +112,14 @@ class SharedViewModel @Inject constructor(
|
||||
private fun postAppEvent(event: Event<Int>) {
|
||||
_appEvent.value = event
|
||||
}
|
||||
|
||||
private fun getPasses(entry: SatEntry, dateNow: Date): MutableList<SatPass> {
|
||||
val gsp = prefsRepo.getStationPosition()
|
||||
val predictor = SatelliteFactory.createSatellite(entry.tle).getPredictor(gsp)
|
||||
val hoursAhead = prefsRepo.getHoursAhead()
|
||||
val passes = predictor.getPasses(dateNow, hoursAhead, true)
|
||||
val passList = passes.map { SatPass(entry.tle, predictor, it) }
|
||||
|
||||
private fun getPasses(satellite: Satellite, dateNow: Date): MutableList<SatPass> {
|
||||
val predictor = satellite.getPredictor(prefsRepo.getStationPosition())
|
||||
val passes = predictor.getPasses(dateNow, prefsRepo.getHoursAhead(), true)
|
||||
val passList = passes.map { SatPass(satellite.tle, predictor, it) }
|
||||
return passList as MutableList<SatPass>
|
||||
}
|
||||
|
||||
|
||||
private fun sortList(passes: MutableList<SatPass>, dateNow: Date): MutableList<SatPass> {
|
||||
val hoursAhead = prefsRepo.getHoursAhead()
|
||||
val dateFuture = Calendar.getInstance().apply {
|
||||
|
||||
Reference in new issue
Block a user