Fix: Show 'unknown' for position logs older than 6 months (#1416)

* Fix: Show 'unknown' for position logs older than 6 months

Display 'unknown' instead of the timestamp for position logs older than 6 months. This addresses an issue where unknown timestamps were incorrectly shown as 1970 (unix epoch).

* Fix: make detekt happy

* Replace "Unknown" with "Unknown Age" in position logs

The text displayed for positions older than six months in position logs has been changed from "Unknown" to "Unknown Age". This update adds clarity and context to the age of positions in the log.
This commit is contained in:
James Rich 2024-11-19 07:29:44 -06:00 committed by GitHub
parent 2bef2ee5bd
commit fb04805255
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -17,8 +17,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.ContentAlpha
import androidx.compose.material.Icon
@ -55,6 +55,7 @@ import com.geeksville.mesh.ui.theme.AppTheme
import com.geeksville.mesh.util.metersIn
import com.geeksville.mesh.util.toString
import java.text.DateFormat
import kotlin.time.Duration.Companion.days
@Composable
private fun RowScope.PositionText(text: String, weight: Float) {
@ -117,10 +118,26 @@ private fun PositionItem(
PositionText("${position.groundSpeed} Km/h", Weight15)
PositionText("%.0f°".format(position.groundTrack * HeadingDeg), Weight15)
}
PositionText(dateFormat.format(position.time * SecondsToMillis), Weight40)
PositionText(formatPositionTime(position, dateFormat), Weight40)
}
}
@Composable
private fun formatPositionTime(
position: MeshProtos.Position,
dateFormat: DateFormat
): String {
val currentTime = System.currentTimeMillis()
val sixMonthsAgo = currentTime - 180.days.inWholeMilliseconds
val isOlderThanSixMonths = position.time * SecondsToMillis > sixMonthsAgo
val timeText = if (isOlderThanSixMonths) {
stringResource(id = R.string.unknown_age)
} else {
dateFormat.format(position.time * SecondsToMillis)
}
return timeText
}
@OptIn(ExperimentalLayoutApi::class)
@Composable
private fun ActionButtons(

View file

@ -312,4 +312,5 @@
<string name="max">Max</string>
<string name="selected">Selected</string>
<string name="not_selected">Not Selected</string>
<string name="unknown_age">Unknown Age</string>
</resources>