kopia lustrzana https://github.com/rt-bishop/Look4Sat
Added more satellite parameters to the map screen
rodzic
488fe352cd
commit
ec553bf429
app/src/main
java/com/rtbishop/look4sat/presentation/mapScreen
res
base/src/main/java/com/rtbishop/look4sat/domain
|
@ -24,6 +24,9 @@ data class MapData(
|
|||
val pass: Satellite,
|
||||
val catNum: Int,
|
||||
val name: String,
|
||||
val aosTime: String,
|
||||
val azimuth: Double,
|
||||
val elevation: Double,
|
||||
val range: Double,
|
||||
val altitude: Double,
|
||||
val velocity: Double,
|
||||
|
|
|
@ -198,7 +198,9 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
|||
|
||||
private fun handleMapData(mapData: MapData) {
|
||||
binding.apply {
|
||||
mapTitle.text = mapData.name
|
||||
mapTimer.text = mapData.aosTime
|
||||
mapAzimuth.text = String.format(getString(R.string.map_azimuth), mapData.azimuth)
|
||||
mapElevation.text = String.format(getString(R.string.map_elevation), mapData.elevation)
|
||||
mapDataId.text = String.format(getString(R.string.map_sat_id), mapData.catNum)
|
||||
mapDataQth.text = String.format(getString(R.string.map_qth), mapData.qthLoc)
|
||||
mapDataAlt.text = String.format(getString(R.string.map_altitude), mapData.altitude)
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.rtbishop.look4sat.domain.predict.SatPos
|
|||
import com.rtbishop.look4sat.domain.predict.Satellite
|
||||
import com.rtbishop.look4sat.utility.QthConverter
|
||||
import com.rtbishop.look4sat.utility.toDegrees
|
||||
import com.rtbishop.look4sat.utility.toTimerString
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.*
|
||||
import java.util.*
|
||||
|
@ -41,9 +42,10 @@ class MapViewModel @Inject constructor(
|
|||
) : ViewModel() {
|
||||
|
||||
private val stationPosition = settings.loadStationPosition()
|
||||
private var allPasses = satelliteManager.getPasses()
|
||||
private var allSatellites = listOf<Satellite>()
|
||||
private var dataUpdateJob: Job? = null
|
||||
private var dataUpdateRate = 2000L
|
||||
private var dataUpdateRate = 1000L
|
||||
private lateinit var selectedSatellite: Satellite
|
||||
|
||||
val stationPos = liveData {
|
||||
|
@ -84,7 +86,8 @@ class MapViewModel @Inject constructor(
|
|||
if (satellites.isNotEmpty()) {
|
||||
allSatellites = satellites
|
||||
if (catnum == -1) {
|
||||
selectSatellite(satellites.first())
|
||||
allPasses.find { pass -> pass.progress < 100 && !pass.isDeepSpace }
|
||||
?.let { pass -> selectSatellite(pass.satellite) }
|
||||
} else {
|
||||
satellites.find { it.data.catnum == catnum }?.let { selectSatellite(it) }
|
||||
}
|
||||
|
@ -156,8 +159,23 @@ class MapViewModel @Inject constructor(
|
|||
_footprint.postValue(satPos)
|
||||
}
|
||||
|
||||
private suspend fun getSatData(satellite: Satellite, pos: GeoPos, date: Date) {
|
||||
val satPos = satelliteManager.getPosition(satellite, pos, date.time)
|
||||
private suspend fun getSatData(sat: Satellite, pos: GeoPos, date: Date) {
|
||||
var aosTime = 0L.toTimerString()
|
||||
allPasses.find { pass -> pass.catNum == sat.data.catnum && pass.progress < 100 }
|
||||
?.let { satPass ->
|
||||
if (!satPass.isDeepSpace) {
|
||||
aosTime = if (date.time < satPass.aosTime) {
|
||||
val millisBeforeStart = satPass.aosTime.minus(date.time)
|
||||
millisBeforeStart.toTimerString()
|
||||
} else {
|
||||
val millisBeforeEnd = satPass.losTime.minus(date.time)
|
||||
millisBeforeEnd.toTimerString()
|
||||
}
|
||||
}
|
||||
}
|
||||
val satPos = satelliteManager.getPosition(sat, pos, date.time)
|
||||
val azimuth = satPos.azimuth.toDegrees()
|
||||
val elevation = satPos.elevation.toDegrees()
|
||||
val osmLat = clipLat(satPos.latitude.toDegrees())
|
||||
val osmLon = clipLon(satPos.longitude.toDegrees())
|
||||
val osmPos = GeoPos(osmLat, osmLon)
|
||||
|
@ -165,7 +183,7 @@ class MapViewModel @Inject constructor(
|
|||
val phase = satPos.phase.toDegrees()
|
||||
val visibility = satPos.eclipsed
|
||||
val satData = MapData(
|
||||
satellite, satellite.data.catnum, satellite.data.name, satPos.distance,
|
||||
sat, sat.data.catnum, sat.data.name, aosTime, azimuth, elevation, satPos.distance,
|
||||
satPos.altitude, satPos.getOrbitalVelocity(), qthLoc, osmPos, phase, visibility
|
||||
)
|
||||
_mapData.postValue(satData)
|
||||
|
|
|
@ -21,15 +21,8 @@
|
|||
android:src="@drawable/ic_back" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_title"
|
||||
style="@style/ToolbarTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="52dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginEnd="52dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:text="@string/map_title" />
|
||||
android:id="@+id/map_timer"
|
||||
style="@style/ToolbarTimer" />
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
|
@ -66,7 +59,7 @@
|
|||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:text="@string/map_copyright"
|
||||
android:textColor="@color/textDisabled"
|
||||
android:textColor="@color/textMain"
|
||||
android:textSize="@dimen/text_size_copyright"
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_card"
|
||||
app:layout_constraintStart_toStartOf="@+id/map_card"
|
||||
|
@ -88,6 +81,66 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_azimuth"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/map_azimuth"
|
||||
app:layout_constraintBottom_toTopOf="@+id/map_data_alt"
|
||||
app:layout_constraintStart_toStartOf="@+id/map_data_visibility"
|
||||
app:layout_constraintTop_toBottomOf="@+id/map_data_visibility" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_lat"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/map_latitude"
|
||||
app:layout_constraintBottom_toTopOf="@+id/map_data_qth"
|
||||
app:layout_constraintStart_toStartOf="@+id/map_data_alt"
|
||||
app:layout_constraintTop_toBottomOf="@+id/map_data_alt" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_lon"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/map_longitude"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/map_data_lat"
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_data_dst" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_alt"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/map_altitude"
|
||||
app:layout_constraintBottom_toTopOf="@+id/map_data_lat"
|
||||
app:layout_constraintStart_toStartOf="@+id/map_azimuth"
|
||||
app:layout_constraintTop_toBottomOf="@+id/map_azimuth" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_dst"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/map_distance"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/map_data_alt"
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_elevation" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_elevation"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/map_elevation"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/map_azimuth"
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_data_phase" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_visibility"
|
||||
style="@style/WorldMapText"
|
||||
|
@ -96,6 +149,7 @@
|
|||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/map_visibility"
|
||||
app:layout_constraintBottom_toTopOf="@+id/map_azimuth"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
@ -109,55 +163,17 @@
|
|||
app:layout_constraintBaseline_toBaselineOf="@+id/map_data_visibility"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_lat"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/map_latitude"
|
||||
app:layout_constraintStart_toStartOf="@+id/map_data_visibility"
|
||||
app:layout_constraintTop_toBottomOf="@+id/map_data_visibility" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_lon"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/map_longitude"
|
||||
app:layout_constraintStart_toStartOf="@+id/map_data_lat"
|
||||
app:layout_constraintTop_toBottomOf="@+id/map_data_lat" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_qth"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/map_qth"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@+id/map_data_lon"
|
||||
app:layout_constraintTop_toBottomOf="@+id/map_data_lon" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_alt"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/map_altitude"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/map_data_lat"
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_data_phase" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_dst"
|
||||
style="@style/WorldMapText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/map_distance"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/map_data_lon"
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_data_alt" />
|
||||
app:layout_constraintStart_toStartOf="@+id/map_data_lat"
|
||||
app:layout_constraintTop_toBottomOf="@+id/map_data_lat" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/map_data_vel"
|
||||
|
@ -166,7 +182,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/map_velocity"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/map_data_qth"
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_data_dst" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/map_data_lon" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
|
@ -101,6 +101,8 @@
|
|||
<string name="map_title">Карта Мира</string>
|
||||
<string name="map_sat_name">%s</string>
|
||||
<string name="map_sat_id">Id:%d</string>
|
||||
<string name="map_azimuth">Азимут: %.1f°</string>
|
||||
<string name="map_elevation">Элевация: %.1f°</string>
|
||||
<string name="map_latitude">Широта: %.1f°</string>
|
||||
<string name="map_longitude">Долгота: %.1f°</string>
|
||||
<string name="map_qth">QTH Локатор: %s</string>
|
||||
|
|
|
@ -102,6 +102,8 @@
|
|||
<string name="map_title">World Map</string>
|
||||
<string name="map_sat_name">%s</string>
|
||||
<string name="map_sat_id">Id:%d</string>
|
||||
<string name="map_azimuth">Azimuth: %.1f°</string>
|
||||
<string name="map_elevation">Elevation: %.1f°</string>
|
||||
<string name="map_latitude">Latitude: %.1f°</string>
|
||||
<string name="map_longitude">Longitude: %.1f°</string>
|
||||
<string name="map_qth">QTH Locator: %s</string>
|
||||
|
|
|
@ -11,6 +11,8 @@ interface ISatelliteManager {
|
|||
|
||||
val calculatedPasses: SharedFlow<List<SatPass>>
|
||||
|
||||
fun getPasses(): List<SatPass>
|
||||
|
||||
suspend fun getPosition(sat: Satellite, pos: GeoPos, time: Long): SatPos
|
||||
|
||||
suspend fun getTrack(sat: Satellite, pos: GeoPos, start: Long, end: Long): List<SatPos>
|
||||
|
|
|
@ -27,9 +27,12 @@ import kotlinx.coroutines.withContext
|
|||
|
||||
class SatelliteManager(private val defaultDispatcher: CoroutineDispatcher) : ISatelliteManager {
|
||||
|
||||
private var passes = listOf<SatPass>()
|
||||
private val _calculatedPasses = MutableSharedFlow<List<SatPass>>(replay = 1)
|
||||
override val calculatedPasses: SharedFlow<List<SatPass>> = _calculatedPasses
|
||||
|
||||
override fun getPasses(): List<SatPass> = passes
|
||||
|
||||
override suspend fun getPosition(sat: Satellite, pos: GeoPos, time: Long): SatPos {
|
||||
return withContext(defaultDispatcher) { sat.getPosition(pos, time) }
|
||||
}
|
||||
|
@ -96,14 +99,18 @@ class SatelliteManager(private val defaultDispatcher: CoroutineDispatcher) : ISa
|
|||
minElevation: Double
|
||||
) {
|
||||
if (satList.isEmpty()) {
|
||||
_calculatedPasses.emit(emptyList())
|
||||
val newPasses = emptyList<SatPass>()
|
||||
passes = newPasses
|
||||
_calculatedPasses.emit(newPasses)
|
||||
} else {
|
||||
withContext(defaultDispatcher) {
|
||||
val allPasses = mutableListOf<SatPass>()
|
||||
satList.forEach { satellite ->
|
||||
allPasses.addAll(satellite.getPasses(pos, time, hoursAhead))
|
||||
}
|
||||
_calculatedPasses.emit(allPasses.filter(time, hoursAhead, minElevation))
|
||||
val newPasses = allPasses.filter(time, hoursAhead, minElevation)
|
||||
passes = newPasses
|
||||
_calculatedPasses.emit(newPasses)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue