fix: correct the default value handling issue when the train display is empty
This commit is contained in:
@@ -149,7 +149,7 @@ class TrainRecord(jsonData: JSONObject? = null) {
|
|||||||
lbjClass.trim()
|
lbjClass.trim()
|
||||||
} else if (isValidValue(train)) {
|
} else if (isValidValue(train)) {
|
||||||
train.trim()
|
train.trim()
|
||||||
} else ""
|
} else null
|
||||||
|
|
||||||
val map = mutableMapOf<String, String>()
|
val map = mutableMapOf<String, String>()
|
||||||
|
|
||||||
@@ -158,7 +158,8 @@ class TrainRecord(jsonData: JSONObject? = null) {
|
|||||||
map["receivedTimestamp"] = dateFormat.format(receivedTimestamp)
|
map["receivedTimestamp"] = dateFormat.format(receivedTimestamp)
|
||||||
|
|
||||||
|
|
||||||
if (trainDisplay.isNotEmpty()) map["train"] = trainDisplay
|
trainDisplay?.takeIf { it.isNotEmpty() }?.let { map["train"] = it }
|
||||||
|
|
||||||
if (directionText != "未知") map["direction"] = directionText
|
if (directionText != "未知") map["direction"] = directionText
|
||||||
if (isValidValue(speed)) map["speed"] = "速度: ${speed.trim()} km/h"
|
if (isValidValue(speed)) map["speed"] = "速度: ${speed.trim()} km/h"
|
||||||
if (isValidValue(position)) map["position"] = "位置: ${position.trim()} km"
|
if (isValidValue(position)) map["position"] = "位置: ${position.trim()} km"
|
||||||
|
|||||||
@@ -162,18 +162,20 @@ fun TrainRecordItem(
|
|||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
val trainDisplay = recordMap["train"]?.toString() ?: "未知列车"
|
val trainDisplay = recordMap["train"]?.toString() ?: ""
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||||
) {
|
) {
|
||||||
|
if (trainDisplay.isNotEmpty()) {
|
||||||
Text(
|
Text(
|
||||||
text = trainDisplay,
|
text = trainDisplay,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val directionText = when (record.direction) {
|
val directionText = when (record.direction) {
|
||||||
1 -> "下"
|
1 -> "下"
|
||||||
@@ -528,18 +530,20 @@ fun MergedTrainRecordItem(
|
|||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
val trainDisplay = recordMap["train"]?.toString() ?: "未知列车"
|
val trainDisplay = recordMap["train"]?.toString() ?: ""
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||||
) {
|
) {
|
||||||
|
if (trainDisplay.isNotEmpty()) {
|
||||||
Text(
|
Text(
|
||||||
text = trainDisplay,
|
text = trainDisplay,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val directionText = when (latestRecord.direction) {
|
val directionText = when (latestRecord.direction) {
|
||||||
1 -> "下"
|
1 -> "下"
|
||||||
|
|||||||
Reference in New Issue
Block a user