mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
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:
parent
2bef2ee5bd
commit
fb04805255
2 changed files with 20 additions and 2 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue