mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-03 03:17:21 +00:00
Renamed and refactored several predict4kotlin classes
This commit is contained in:
1 parent
c38fe8b10f
commit
9a4de03cac
27 files changed
+315
-232
No files matched your search
@@ -23,7 +23,7 @@ import android.location.LocationManager
|
||||
import androidx.core.content.edit
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.QthConverter
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.StationPosition
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.StationPos
|
||||
import com.rtbishop.look4sat.utility.round
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
@@ -89,19 +89,19 @@ class PreferencesProvider @Inject constructor(
|
||||
return qthConverter.positionToQTH(lat, lon)
|
||||
}
|
||||
|
||||
override fun loadStationPosition(): StationPosition {
|
||||
override fun loadStationPosition(): StationPos {
|
||||
val defaultSP = "0.0"
|
||||
val latitude = preferences.getString(keyLatitude, null) ?: defaultSP
|
||||
val longitude = preferences.getString(keyLongitude, null) ?: defaultSP
|
||||
val altitude = preferences.getString(keyAltitude, null) ?: defaultSP
|
||||
return StationPosition(latitude.toDouble(), longitude.toDouble(), altitude.toDouble())
|
||||
return StationPos(latitude.toDouble(), longitude.toDouble(), altitude.toDouble())
|
||||
}
|
||||
|
||||
override fun saveStationPosition(position: StationPosition) {
|
||||
override fun saveStationPosition(pos: StationPos) {
|
||||
preferences.edit {
|
||||
putString(keyLatitude, position.latitude.toString())
|
||||
putString(keyLongitude, position.longitude.toString())
|
||||
putString(keyAltitude, position.altitude.toString())
|
||||
putString(keyLatitude, pos.latitude.toString())
|
||||
putString(keyLongitude, pos.longitude.toString())
|
||||
putString(keyAltitude, pos.altitude.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class PreferencesProvider @Inject constructor(
|
||||
val latitude = location.latitude.round(4)
|
||||
val longitude = location.longitude.round(4)
|
||||
val altitude = location.altitude.round(1)
|
||||
val stationPosition = StationPosition(latitude, longitude, altitude)
|
||||
val stationPosition = StationPos(latitude, longitude, altitude)
|
||||
saveStationPosition(stationPosition)
|
||||
return true
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class PreferencesProvider @Inject constructor(
|
||||
|
||||
override fun updatePositionFromQTH(qthString: String): Boolean {
|
||||
val position = qthConverter.qthToPosition(qthString) ?: return false
|
||||
val stationPosition = StationPosition(position.latitude, position.longitude, 0.0)
|
||||
val stationPosition = StationPos(position.latitude, position.longitude, 0.0)
|
||||
saveStationPosition(stationPosition)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package com.rtbishop.look4sat.framework.db
|
||||
import androidx.room.TypeConverter
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.TLE
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.createSat
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
package com.rtbishop.look4sat.framework.model
|
||||
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Position
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.GeoPos
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
|
||||
|
||||
data class SatData(
|
||||
@@ -28,5 +28,5 @@ data class SatData(
|
||||
val altitude: Double,
|
||||
val velocity: Double,
|
||||
val qthLoc: String,
|
||||
val osmPos: Position
|
||||
)
|
||||
val osmPos: GeoPos
|
||||
)
|
||||
@@ -29,7 +29,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.databinding.FragmentMapBinding
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Position
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.GeoPos
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
|
||||
import com.rtbishop.look4sat.framework.model.SatData
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -96,7 +96,7 @@ class SatMapFragment : Fragment(R.layout.fragment_map) {
|
||||
viewModel.satData.observe(viewLifecycleOwner, { renderSatData(it, binding) })
|
||||
}
|
||||
|
||||
private fun renderStationPos(stationPos: Position, binding: FragmentMapBinding) {
|
||||
private fun renderStationPos(stationPos: GeoPos, binding: FragmentMapBinding) {
|
||||
binding.apply {
|
||||
Marker(mapView).apply {
|
||||
setInfoWindow(null)
|
||||
@@ -109,7 +109,7 @@ class SatMapFragment : Fragment(R.layout.fragment_map) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderSatPositions(posMap: Map<Satellite, Position>, binding: FragmentMapBinding) {
|
||||
private fun renderSatPositions(posMap: Map<Satellite, GeoPos>, binding: FragmentMapBinding) {
|
||||
binding.apply {
|
||||
val markers = FolderOverlay()
|
||||
posMap.entries.forEach {
|
||||
@@ -120,7 +120,7 @@ class SatMapFragment : Fragment(R.layout.fragment_map) {
|
||||
textLabelBackgroundColor = Color.TRANSPARENT
|
||||
textLabelForegroundColor =
|
||||
ContextCompat.getColor(requireContext(), R.color.themeLight)
|
||||
setTextIcon(it.key.tle.name)
|
||||
setTextIcon(it.key.params.name)
|
||||
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
|
||||
try {
|
||||
position = GeoPoint(it.value.latitude, it.value.longitude)
|
||||
@@ -156,7 +156,7 @@ class SatMapFragment : Fragment(R.layout.fragment_map) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderSatTrack(satTrack: List<List<Position>>, binding: FragmentMapBinding) {
|
||||
private fun renderSatTrack(satTrack: List<List<GeoPos>>, binding: FragmentMapBinding) {
|
||||
val trackOverlay = FolderOverlay()
|
||||
satTrack.forEach { track ->
|
||||
val trackPoints = track.map { GeoPoint(it.latitude, it.longitude) }
|
||||
@@ -169,7 +169,7 @@ class SatMapFragment : Fragment(R.layout.fragment_map) {
|
||||
binding.mapView.overlays[1] = trackOverlay
|
||||
}
|
||||
|
||||
private fun renderSatFootprint(satFootprint: List<Position>, binding: FragmentMapBinding) {
|
||||
private fun renderSatFootprint(satFootprint: List<GeoPos>, binding: FragmentMapBinding) {
|
||||
val footprintPoints = satFootprint.map { GeoPoint(it.latitude, it.longitude) }
|
||||
val footprintOverlay = Polygon().apply {
|
||||
fillPaint.set(footprintPaint)
|
||||
|
||||
+25
-26
@@ -20,10 +20,9 @@ package com.rtbishop.look4sat.presentation.satMapScreen
|
||||
import androidx.lifecycle.*
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.SatDataRepository
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Position
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.GeoPos
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.StationPosition
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.getRangeCircle
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.StationPos
|
||||
import com.rtbishop.look4sat.framework.model.SatData
|
||||
import com.rtbishop.look4sat.injection.DefaultDispatcher
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -49,20 +48,20 @@ class SatMapViewModel @Inject constructor(
|
||||
val stationPos = liveData {
|
||||
val osmLat = clipLat(gsp.latitude)
|
||||
val osmLon = clipLon(gsp.longitude)
|
||||
emit(Position(osmLat, osmLon))
|
||||
emit(GeoPos(osmLat, osmLon))
|
||||
}
|
||||
|
||||
private val _satTrack = MutableLiveData<List<List<Position>>>()
|
||||
val satTrack: LiveData<List<List<Position>>> = _satTrack
|
||||
private val _satTrack = MutableLiveData<List<List<GeoPos>>>()
|
||||
val satTrack: LiveData<List<List<GeoPos>>> = _satTrack
|
||||
|
||||
private val _satFootprint = MutableLiveData<List<Position>>()
|
||||
val satFootprint: LiveData<List<Position>> = _satFootprint
|
||||
private val _satFootprint = MutableLiveData<List<GeoPos>>()
|
||||
val satFootprint: LiveData<List<GeoPos>> = _satFootprint
|
||||
|
||||
private val _satData = MutableLiveData<SatData>()
|
||||
val satData: LiveData<SatData> = this._satData
|
||||
|
||||
private val _satPositions = MutableLiveData<Map<Satellite, Position>>()
|
||||
val satPositions: LiveData<Map<Satellite, Position>> = _satPositions
|
||||
private val _satPositions = MutableLiveData<Map<Satellite, GeoPos>>()
|
||||
val satPositions: LiveData<Map<Satellite, GeoPos>> = _satPositions
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
@@ -110,38 +109,38 @@ class SatMapViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun setSatPositions(list: List<Satellite>, gsp: StationPosition, date: Date) {
|
||||
private suspend fun setSatPositions(list: List<Satellite>, gsp: StationPos, date: Date) {
|
||||
withContext(defaultDispatcher) {
|
||||
val satPositions = mutableMapOf<Satellite, Position>()
|
||||
val satPositions = mutableMapOf<Satellite, GeoPos>()
|
||||
list.forEach { satellite ->
|
||||
val satPos = satellite.getPredictor(gsp).getSatPos(date)
|
||||
val osmLat = clipLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = clipLon(Math.toDegrees(satPos.longitude))
|
||||
satPositions[satellite] = Position(osmLat, osmLon)
|
||||
satPositions[satellite] = GeoPos(osmLat, osmLon)
|
||||
}
|
||||
_satPositions.postValue(satPositions)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun setSelectedSatTrack(sat: Satellite, gsp: StationPosition, date: Date) {
|
||||
private suspend fun setSelectedSatTrack(sat: Satellite, gsp: StationPos, date: Date) {
|
||||
withContext(defaultDispatcher) {
|
||||
val satTracks = mutableListOf<List<Position>>()
|
||||
val currentTrack = mutableListOf<Position>()
|
||||
val satTracks = mutableListOf<List<GeoPos>>()
|
||||
val currentTrack = mutableListOf<GeoPos>()
|
||||
var oldLongitude = 0.0
|
||||
sat.getPredictor(gsp).getPositions(date, 15, 0, 2.4).forEach { satPos ->
|
||||
val osmLat = clipLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = clipLon(Math.toDegrees(satPos.longitude))
|
||||
val currentPosition = Position(osmLat, osmLon)
|
||||
val currentPosition = GeoPos(osmLat, osmLon)
|
||||
if (oldLongitude < -170.0 && currentPosition.longitude > 170.0) {
|
||||
// adding left terminal position
|
||||
currentTrack.add(Position(osmLat, -180.0))
|
||||
val finishedTrack = mutableListOf<Position>().apply { addAll(currentTrack) }
|
||||
currentTrack.add(GeoPos(osmLat, -180.0))
|
||||
val finishedTrack = mutableListOf<GeoPos>().apply { addAll(currentTrack) }
|
||||
satTracks.add(finishedTrack)
|
||||
currentTrack.clear()
|
||||
} else if (oldLongitude > 170.0 && currentPosition.longitude < -170.0) {
|
||||
// adding right terminal position
|
||||
currentTrack.add(Position(osmLat, 180.0))
|
||||
val finishedTrack = mutableListOf<Position>().apply { addAll(currentTrack) }
|
||||
currentTrack.add(GeoPos(osmLat, 180.0))
|
||||
val finishedTrack = mutableListOf<GeoPos>().apply { addAll(currentTrack) }
|
||||
satTracks.add(finishedTrack)
|
||||
currentTrack.clear()
|
||||
}
|
||||
@@ -153,28 +152,28 @@ class SatMapViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun setSelectedSatFootprint(sat: Satellite, gsp: StationPosition, date: Date) {
|
||||
private suspend fun setSelectedSatFootprint(sat: Satellite, gsp: StationPos, date: Date) {
|
||||
withContext(defaultDispatcher) {
|
||||
val satFootprint = sat.getPosition(gsp, date).getRangeCircle().map { rangePos ->
|
||||
val osmLat = clipLat(rangePos.latitude)
|
||||
val osmLon = clipLon(rangePos.longitude)
|
||||
Position(osmLat, osmLon)
|
||||
GeoPos(osmLat, osmLon)
|
||||
}
|
||||
_satFootprint.postValue(satFootprint)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun setSelectedSatData(sat: Satellite, gsp: StationPosition, date: Date) {
|
||||
private suspend fun setSelectedSatData(sat: Satellite, gsp: StationPos, date: Date) {
|
||||
withContext(defaultDispatcher) {
|
||||
val satPos = sat.getPredictor(gsp).getSatPos(date)
|
||||
val osmLat = clipLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = clipLon(Math.toDegrees(satPos.longitude))
|
||||
val osmPos = Position(osmLat, osmLon)
|
||||
val osmPos = GeoPos(osmLat, osmLon)
|
||||
val qthLoc =
|
||||
preferencesSource.positionToQTH(osmPos.latitude, osmPos.longitude) ?: "-- --"
|
||||
val velocity = getOrbitalVelocity(satPos.altitude)
|
||||
val satData = SatData(
|
||||
sat, sat.tle.catnum, sat.tle.name, satPos.range,
|
||||
sat, sat.params.catnum, sat.params.name, satPos.range,
|
||||
satPos.altitude, velocity, qthLoc, osmPos
|
||||
)
|
||||
this@SatMapViewModel._satData.postValue(satData)
|
||||
|
||||
+4
-4
@@ -119,13 +119,13 @@ class PassInfoFragment : Fragment(R.layout.fragment_polar) {
|
||||
binding.satName.text = satPass.name
|
||||
|
||||
if (!satPass.isDeepSpace) {
|
||||
if (dateNow.before(satPass.aosDate)) {
|
||||
val millisBeforeStart = satPass.aosDate.time.minus(timeNow)
|
||||
if (dateNow.time < satPass.aosTime) {
|
||||
val millisBeforeStart = satPass.aosTime.minus(timeNow)
|
||||
binding.polarTimer.text = millisBeforeStart.toTimerString()
|
||||
} else {
|
||||
val millisBeforeEnd = satPass.losDate.time.minus(timeNow)
|
||||
val millisBeforeEnd = satPass.losTime.minus(timeNow)
|
||||
binding.polarTimer.text = millisBeforeEnd.toTimerString()
|
||||
if (dateNow.after(satPass.losDate)) {
|
||||
if (dateNow.time > satPass.losTime) {
|
||||
binding.polarTimer.text = 0L.toTimerString()
|
||||
findNavController().navigateSafe(R.id.action_polar_to_passes)
|
||||
}
|
||||
|
||||
+5
-5
@@ -200,17 +200,17 @@ class PassInfoView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
private fun createPassTrajectory(satPass: SatPass) {
|
||||
val currentTime = satPass.aosDate
|
||||
while (currentTime.before(satPass.losDate)) {
|
||||
val satPos = satPass.predictor.getSatPos(currentTime)
|
||||
var currentTime = satPass.aosTime
|
||||
while (currentTime < satPass.losTime) {
|
||||
val satPos = satPass.predictor.getSatPos(Date(currentTime))
|
||||
val passX = sph2CartX(satPos.azimuth, satPos.elevation, radarRadius.toDouble())
|
||||
val passY = sph2CartY(satPos.azimuth, satPos.elevation, radarRadius.toDouble())
|
||||
if (currentTime.compareTo(satPass.aosDate) == 0) {
|
||||
if (currentTime == satPass.aosTime) {
|
||||
trackPath.moveTo(passX, -passY)
|
||||
} else {
|
||||
trackPath.lineTo(passX, -passY)
|
||||
}
|
||||
currentTime.time += 15000
|
||||
currentTime += 15000
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class PassInfoViewModel @Inject constructor(
|
||||
|
||||
fun getPass(catNum: Int, aosTime: Long) = liveData {
|
||||
satPassRepository.passes.collect { passes ->
|
||||
val pass = passes.find { it.catNum == catNum && it.aosDate.time == aosTime }
|
||||
val pass = passes.find { it.catNum == catNum && it.aosTime == aosTime }
|
||||
pass?.let { satPass ->
|
||||
processTransmitters(satPass)
|
||||
initRotatorControl(satPass)
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@ class SatPassAdapter(private val isUTC: Boolean, private val clickListener: Pass
|
||||
|
||||
private val diffCallback = object : DiffUtil.ItemCallback<SatPass>() {
|
||||
override fun areItemsTheSame(oldItem: SatPass, newItem: SatPass): Boolean {
|
||||
return oldItem.catNum == newItem.catNum && oldItem.aosDate == newItem.aosDate
|
||||
return oldItem.catNum == newItem.catNum && oldItem.aosTime == newItem.aosTime
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: SatPass, newItem: SatPass): Boolean {
|
||||
@@ -99,9 +99,9 @@ class SatPassAdapter(private val isUTC: Boolean, private val clickListener: Pass
|
||||
passLeoAosAz.text = String.format(aosAzFormat, satPass.aosAzimuth)
|
||||
passLeoMaxEl.text = String.format(maxElFormat, satPass.maxElevation)
|
||||
passLeoLosAz.text = String.format(losAzFormat, satPass.losAzimuth)
|
||||
passLeoStart.text = startFormat.format(satPass.aosDate)
|
||||
passLeoStart.text = startFormat.format(Date(satPass.aosTime))
|
||||
passLeoTcaAz.text = String.format(tcaAzFormat, satPass.tcaAzimuth)
|
||||
passLeoEnd.text = endFormat.format(satPass.losDate)
|
||||
passLeoEnd.text = endFormat.format(Date(satPass.losTime))
|
||||
passLeoProgress.progress = satPass.progress
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -110,12 +110,12 @@ class SatPassFragment : Fragment(R.layout.fragment_passes), SatPassAdapter.Passe
|
||||
if (passes.isNotEmpty()) {
|
||||
val timeNow = System.currentTimeMillis()
|
||||
try {
|
||||
val nextPass = passes.first { it.aosDate.time.minus(timeNow) > 0 }
|
||||
val millisBeforeStart = nextPass.aosDate.time.minus(timeNow)
|
||||
val nextPass = passes.first { it.aosTime.minus(timeNow) > 0 }
|
||||
val millisBeforeStart = nextPass.aosTime.minus(timeNow)
|
||||
binding.passesTimer.text = millisBeforeStart.toTimerString()
|
||||
} catch (e: NoSuchElementException) {
|
||||
val lastPass = passes.last()
|
||||
val millisBeforeEnd = lastPass.losDate.time.minus(timeNow)
|
||||
val millisBeforeEnd = lastPass.losTime.minus(timeNow)
|
||||
binding.passesTimer.text = millisBeforeEnd.toTimerString()
|
||||
}
|
||||
} else {
|
||||
@@ -125,7 +125,7 @@ class SatPassFragment : Fragment(R.layout.fragment_passes), SatPassAdapter.Passe
|
||||
|
||||
override fun navigateToPass(satPass: SatPass) {
|
||||
if (satPass.progress < 100) {
|
||||
val bundle = bundleOf("catNum" to satPass.catNum, "aosTime" to satPass.aosDate.time)
|
||||
val bundle = bundleOf("catNum" to satPass.catNum, "aosTime" to satPass.aosTime)
|
||||
findNavController().navigateSafe(R.id.action_passes_to_polar, bundle)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -92,10 +92,10 @@ class SatPassViewModel @Inject constructor(
|
||||
val timeNow = System.currentTimeMillis()
|
||||
currentPasses.forEach { pass ->
|
||||
if (!pass.isDeepSpace) {
|
||||
val timeStart = pass.aosDate.time
|
||||
val timeStart = pass.aosTime
|
||||
if (timeNow > timeStart) {
|
||||
val deltaNow = timeNow.minus(timeStart).toFloat()
|
||||
val deltaTotal = pass.losDate.time.minus(timeStart).toFloat()
|
||||
val deltaTotal = pass.losTime.minus(timeStart).toFloat()
|
||||
pass.progress = ((deltaNow / deltaTotal) * 100).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user