mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added several tweaks to Radar and RadioControl screens
This commit is contained in:
1 parent
aadc285d7f
commit
4a3a01729b
5 files changed
+116
-125
No files matched your search
@@ -37,9 +37,9 @@ import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -89,19 +89,23 @@ fun NavGraphBuilder.radarDestination(
|
||||
composable(radarRoute, radarArgs) {
|
||||
val viewModel = viewModel(RadarViewModel::class.java, factory = RadarViewModel.Factory)
|
||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
RadarScreen(uiState, navigateUp, navigateToRadioControl)
|
||||
RadarScreen(uiState, viewModel::onAction, navigateUp, navigateToRadioControl)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RadarScreen(
|
||||
uiState: RadarState,
|
||||
onAction: (RadarAction) -> Unit,
|
||||
navigateUp: () -> Unit,
|
||||
navigateToRadioControl: (Int, Long) -> Unit
|
||||
) {
|
||||
val upcomingPass = uiState.currentPass ?: getDefaultPass()
|
||||
if (upcomingPass.losTime < System.currentTimeMillis()) navigateUp()
|
||||
|
||||
val addToCalendar: () -> Unit = {
|
||||
uiState.currentPass?.let { pass ->
|
||||
uiState.sendAction(RadarAction.AddToCalendar(pass.name, pass.aosTime, pass.losTime))
|
||||
onAction(RadarAction.AddToCalendar(pass.name, pass.aosTime, pass.losTime))
|
||||
}
|
||||
}
|
||||
val openRadioControl: () -> Unit = {
|
||||
@@ -109,8 +113,6 @@ private fun RadarScreen(
|
||||
navigateToRadioControl(pass.catNum, pass.aosTime)
|
||||
}
|
||||
}
|
||||
val upcomingPass = uiState.currentPass ?: getDefaultPass()
|
||||
if (upcomingPass.losTime < System.currentTimeMillis()) navigateUp()
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.layoutPadding()
|
||||
@@ -120,28 +122,26 @@ private fun RadarScreen(
|
||||
val isVertical = isVerticalLayout()
|
||||
if (isVertical) {
|
||||
TopBar {
|
||||
IconCard(action = navigateUp, resId = R.drawable.ic_back)
|
||||
IconCard(action = addToCalendar, resId = R.drawable.ic_calendar)
|
||||
TimerRow(timeString = uiState.currentTime, isTimeAos = uiState.isCurrentTimeAos)
|
||||
IconCard(action = openRadioControl, resId = R.drawable.ic_radios)
|
||||
IconCard(action = addToCalendar, resId = R.drawable.ic_calendar)
|
||||
}
|
||||
TopBar { NextPassRow(pass = upcomingPass, isUtc = uiState.isUtc) }
|
||||
} else {
|
||||
TopBar {
|
||||
IconCard(action = navigateUp, resId = R.drawable.ic_back)
|
||||
IconCard(action = addToCalendar, resId = R.drawable.ic_calendar)
|
||||
TimerRow(timeString = uiState.currentTime, isTimeAos = uiState.isCurrentTimeAos)
|
||||
NextPassRow(pass = upcomingPass, modifier = Modifier.weight(1f), isUtc = uiState.isUtc)
|
||||
IconCard(action = openRadioControl, resId = R.drawable.ic_radios)
|
||||
IconCard(action = addToCalendar, resId = R.drawable.ic_calendar)
|
||||
}
|
||||
}
|
||||
if (isVertical) {
|
||||
RadarCard(uiState, Modifier.weight(1f))
|
||||
TransmittersCard(uiState, Modifier.weight(1f))
|
||||
TransmittersCard(uiState.transmitters, uiState.selectedTransmitterUuid, onAction, Modifier.weight(1f))
|
||||
} else {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
RadarCard(uiState, Modifier.weight(1f))
|
||||
TransmittersCard(uiState, Modifier.weight(1f))
|
||||
TransmittersCard(uiState.transmitters, uiState.selectedTransmitterUuid, onAction, Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,17 +255,22 @@ private fun RadarLabel(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TransmittersCard(uiState: RadarState, modifier: Modifier = Modifier) {
|
||||
private fun TransmittersCard(
|
||||
transmitters: List<SatRadio>,
|
||||
selectedUuid: String?,
|
||||
onAction: (RadarAction) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
ElevatedCard(modifier = modifier) {
|
||||
if (uiState.transmitters.isEmpty()) {
|
||||
if (transmitters.isEmpty()) {
|
||||
EmptyTransmittersContent()
|
||||
} else {
|
||||
TransmittersList(
|
||||
transmitters = uiState.transmitters,
|
||||
selectedUuid = uiState.selectedTransmitterUuid,
|
||||
transmitters = transmitters,
|
||||
selectedUuid = selectedUuid,
|
||||
onSelect = { uuid ->
|
||||
if (uiState.selectedTransmitterUuid != null) {
|
||||
uiState.sendAction(RadarAction.SelectTransmitter(uuid))
|
||||
if (selectedUuid != null) {
|
||||
onAction(RadarAction.SelectTransmitter(uuid))
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -324,7 +329,6 @@ private fun TransmitterItemPreview() {
|
||||
MainTheme { TransmitterItem(transmitter, isClickable = true, isSelected = true, onClick = {}) }
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun TransmitterItem(
|
||||
radio: SatRadio,
|
||||
@@ -334,42 +338,42 @@ private fun TransmitterItem(
|
||||
) {
|
||||
val title = if (radio.isInverted) "INVERTED: ${radio.info}" else radio.info
|
||||
val fullTitle = "$title - (${radio.downlinkMode ?: "--"}/${radio.uplinkMode ?: "--"})"
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.background,
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.then(if (isClickable) Modifier.clickable { onClick() } else Modifier)
|
||||
) {
|
||||
Surface(modifier = Modifier.padding(bottom = 2.dp)) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(horizontal = 8.dp, vertical = 6.dp)
|
||||
) {
|
||||
Box {
|
||||
Text(
|
||||
text = fullTitle,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 6.dp)
|
||||
.infiniteMarquee()
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(horizontal = 8.dp, vertical = 6.dp)
|
||||
) {
|
||||
Box {
|
||||
Text(
|
||||
text = fullTitle,
|
||||
textAlign = TextAlign.Center,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 6.dp)
|
||||
.infiniteMarquee()
|
||||
)
|
||||
if (isSelected) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_radios),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.background(color = MaterialTheme.colorScheme.surface)
|
||||
)
|
||||
if (isSelected) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_radios),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.background(color = MaterialTheme.colorScheme.surface)
|
||||
)
|
||||
}
|
||||
}
|
||||
FrequencyRow(radio = radio, isDownlink = true)
|
||||
FrequencyRow(radio = radio, isDownlink = false)
|
||||
}
|
||||
FrequencyRow(radio = radio, isDownlink = true)
|
||||
FrequencyRow(radio = radio, isDownlink = false)
|
||||
}
|
||||
HorizontalDivider(thickness = 2.dp, color = MaterialTheme.colorScheme.background)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,19 +22,18 @@ import com.rtbishop.look4sat.core.domain.predict.OrbitalPass
|
||||
import com.rtbishop.look4sat.core.domain.predict.OrbitalPos
|
||||
|
||||
data class RadarState(
|
||||
val currentPass: OrbitalPass?,
|
||||
val currentTime: String,
|
||||
val isCurrentTimeAos: Boolean,
|
||||
val isUtc: Boolean,
|
||||
val orientationValues: Pair<Float, Float>,
|
||||
val orbitalPos: OrbitalPos?,
|
||||
val satTrack: List<OrbitalPos>,
|
||||
val shouldShowSweep: Boolean,
|
||||
val shouldUseCompass: Boolean,
|
||||
val transmitters: List<SatRadio>,
|
||||
val selectedTransmitterUuid: String?,
|
||||
val selectedFrequency: Long?,
|
||||
val sendAction: (RadarAction) -> Unit
|
||||
val currentPass: OrbitalPass? = null,
|
||||
val currentTime: String = "00:00:00",
|
||||
val isCurrentTimeAos: Boolean = true,
|
||||
val isUtc: Boolean = false,
|
||||
val orientationValues: Pair<Float, Float> = 0f to 0f,
|
||||
val orbitalPos: OrbitalPos? = null,
|
||||
val satTrack: List<OrbitalPos> = emptyList(),
|
||||
val shouldShowSweep: Boolean = false,
|
||||
val shouldUseCompass: Boolean = false,
|
||||
val transmitters: List<SatRadio> = emptyList(),
|
||||
val selectedTransmitterUuid: String? = null,
|
||||
val selectedFrequency: Long? = null
|
||||
)
|
||||
|
||||
sealed class RadarAction {
|
||||
|
||||
@@ -54,25 +54,16 @@ class RadarViewModel(
|
||||
private val addToCalendar: IAddToCalendar
|
||||
) : ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(
|
||||
RadarState(
|
||||
currentPass = null,
|
||||
currentTime = "00:00:00",
|
||||
isCurrentTimeAos = true,
|
||||
isUtc = settingsRepo.otherSettings.value.stateOfUtc,
|
||||
orientationValues = sensorsRepo.orientation.value,
|
||||
orbitalPos = null,
|
||||
satTrack = emptyList(),
|
||||
shouldShowSweep = settingsRepo.otherSettings.value.stateOfSweep,
|
||||
shouldUseCompass = settingsRepo.otherSettings.value.stateOfSensors,
|
||||
selectedTransmitterUuid = null,
|
||||
selectedFrequency = null,
|
||||
transmitters = emptyList(),
|
||||
sendAction = ::handleAction,
|
||||
)
|
||||
)
|
||||
private val stationPos = settingsRepo.stationPosition.value
|
||||
private val magDeclination = sensorsRepo.getMagDeclination(stationPos)
|
||||
private val _uiState = MutableStateFlow(
|
||||
RadarState(
|
||||
isUtc = settingsRepo.otherSettings.value.stateOfUtc,
|
||||
orientationValues = sensorsRepo.orientation.value,
|
||||
shouldShowSweep = settingsRepo.otherSettings.value.stateOfSweep,
|
||||
shouldUseCompass = settingsRepo.otherSettings.value.stateOfSensors
|
||||
)
|
||||
)
|
||||
val uiState: StateFlow<RadarState> = _uiState
|
||||
|
||||
init {
|
||||
@@ -81,7 +72,7 @@ class RadarViewModel(
|
||||
viewModelScope.launch {
|
||||
sensorsRepo.enableSensor()
|
||||
sensorsRepo.orientation.collect { data ->
|
||||
val orientationValues = Pair(data.first + magDeclination, data.second)
|
||||
val orientationValues = (data.first + magDeclination) to data.second
|
||||
_uiState.update { it.copy(orientationValues = orientationValues) }
|
||||
}
|
||||
}
|
||||
@@ -92,41 +83,29 @@ class RadarViewModel(
|
||||
_uiState.update { it.copy(isUtc = settings.stateOfUtc) }
|
||||
}
|
||||
}
|
||||
// Resolve which pass we're tracking
|
||||
// Resolve which pass we're tracking and start the tick loop
|
||||
viewModelScope.launch {
|
||||
val catNum = savedStateHandle.get<Int>("catNum") ?: 0
|
||||
val aosTime = savedStateHandle.get<Long>("aosTime") ?: 0L
|
||||
val passes = satelliteRepo.passes.value
|
||||
val pass = passes.find { pass -> pass.catNum == catNum && pass.aosTime == aosTime }
|
||||
val currentPass = pass ?: passes.firstOrNull()
|
||||
val currentPass = passes.find { it.catNum == catNum && it.aosTime == aosTime }
|
||||
?: passes.firstOrNull()
|
||||
currentPass?.let { satPass ->
|
||||
_uiState.update { it.copy(currentPass = satPass) }
|
||||
val transmitters = satelliteRepo.getRadiosWithId(satPass.catNum)
|
||||
// Compute track once (it doesn't change)
|
||||
// Compute track once (it doesn't change for a given pass)
|
||||
if (!satPass.isDeepSpace) {
|
||||
val track = satelliteRepo.getTrack(
|
||||
satPass.orbitalObject, stationPos, satPass.aosTime, satPass.losTime
|
||||
)
|
||||
_uiState.update { it.copy(satTrack = track) }
|
||||
}
|
||||
// Local tick loop — computes position only while the radar screen is alive
|
||||
// Tick loop — position, timer, and radio updates every second
|
||||
while (isActive) {
|
||||
val timeNow = System.currentTimeMillis()
|
||||
val pos = satelliteRepo.getPosition(satPass.orbitalObject, stationPos, timeNow)
|
||||
when {
|
||||
satPass.isDeepSpace -> {
|
||||
val time = 0L.toTimerString()
|
||||
_uiState.update { it.copy(currentTime = time, isCurrentTimeAos = false, orbitalPos = pos) }
|
||||
}
|
||||
satPass.aosTime > timeNow -> {
|
||||
val time = satPass.aosTime.minus(timeNow).toTimerString()
|
||||
_uiState.update { it.copy(currentTime = time, isCurrentTimeAos = true, orbitalPos = pos) }
|
||||
}
|
||||
else -> {
|
||||
val time = satPass.losTime.minus(timeNow).toTimerString()
|
||||
_uiState.update { it.copy(currentTime = time, isCurrentTimeAos = false, orbitalPos = pos) }
|
||||
}
|
||||
}
|
||||
val (time, isAos) = computeTimer(satPass.isDeepSpace, satPass.aosTime, satPass.losTime, timeNow)
|
||||
_uiState.update { it.copy(currentTime = time, isCurrentTimeAos = isAos, orbitalPos = pos) }
|
||||
processRadios(transmitters, satPass.orbitalObject, timeNow)
|
||||
sendPassData(pos)
|
||||
delay(1000)
|
||||
@@ -140,10 +119,18 @@ class RadarViewModel(
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
private fun handleAction(action: RadarAction) {
|
||||
fun onAction(action: RadarAction) {
|
||||
when (action) {
|
||||
is RadarAction.AddToCalendar -> addToCalendar(action.name, action.aosTime, action.losTime)
|
||||
is RadarAction.SelectTransmitter -> { _uiState.update { it.copy(selectedTransmitterUuid = action.uuid) } }
|
||||
is RadarAction.SelectTransmitter -> _uiState.update { it.copy(selectedTransmitterUuid = action.uuid) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeTimer(isDeepSpace: Boolean, aosTime: Long, losTime: Long, timeNow: Long): Pair<String, Boolean> {
|
||||
return when {
|
||||
isDeepSpace -> 0L.toTimerString() to false
|
||||
aosTime > timeNow -> (aosTime - timeNow).toTimerString() to true
|
||||
else -> (losTime - timeNow).toTimerString() to false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,8 +170,10 @@ class RadarViewModel(
|
||||
|
||||
private suspend fun processRadios(radios: List<SatRadio>, orbitalObject: OrbitalObject, time: Long) {
|
||||
val transmitters = satelliteRepo.getRadios(orbitalObject, stationPos, radios, time)
|
||||
val isFreqEnabled =
|
||||
settingsRepo.rcSettings.value.frequencyState || settingsRepo.rcSettings.value.bluetoothFrequencyState
|
||||
_uiState.update { state ->
|
||||
if (!settingsRepo.rcSettings.value.frequencyState && !settingsRepo.rcSettings.value.bluetoothFrequencyState) {
|
||||
if (!isFreqEnabled) {
|
||||
return@update state.copy(
|
||||
transmitters = transmitters,
|
||||
selectedTransmitterUuid = null,
|
||||
@@ -197,18 +186,12 @@ class RadarViewModel(
|
||||
val low = radio.downlinkLow
|
||||
val high = radio.downlinkHigh
|
||||
when {
|
||||
low != null && high != null ->
|
||||
(low + high) / 2
|
||||
low != null ->
|
||||
low
|
||||
low != null && high != null -> (low + high) / 2
|
||||
low != null -> low
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
state.copy(
|
||||
transmitters = transmitters,
|
||||
selectedTransmitterUuid = selectedUuid,
|
||||
selectedFrequency = freq
|
||||
)
|
||||
state.copy(transmitters = transmitters, selectedTransmitterUuid = selectedUuid, selectedFrequency = freq)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user