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()
|
||||
} else if (isValidValue(train)) {
|
||||
train.trim()
|
||||
} else ""
|
||||
} else null
|
||||
|
||||
val map = mutableMapOf<String, String>()
|
||||
|
||||
@@ -158,7 +158,8 @@ class TrainRecord(jsonData: JSONObject? = null) {
|
||||
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 (isValidValue(speed)) map["speed"] = "速度: ${speed.trim()} km/h"
|
||||
if (isValidValue(position)) map["position"] = "位置: ${position.trim()} km"
|
||||
|
||||
@@ -162,18 +162,20 @@ fun TrainRecordItem(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val trainDisplay = recordMap["train"]?.toString() ?: "未知列车"
|
||||
val trainDisplay = recordMap["train"]?.toString() ?: ""
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
Text(
|
||||
text = trainDisplay,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 20.sp,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
if (trainDisplay.isNotEmpty()) {
|
||||
Text(
|
||||
text = trainDisplay,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 20.sp,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
|
||||
val directionText = when (record.direction) {
|
||||
1 -> "下"
|
||||
@@ -206,13 +208,13 @@ fun TrainRecordItem(
|
||||
|
||||
val formattedInfo = when {
|
||||
record.locoType.isNotEmpty() && record.loco.isNotEmpty() -> {
|
||||
val shortLoco = if (record.loco.length > 5) {
|
||||
record.loco.takeLast(5)
|
||||
} else {
|
||||
record.loco
|
||||
}
|
||||
"${record.locoType}-${shortLoco}"
|
||||
val shortLoco = if (record.loco.length > 5) {
|
||||
record.loco.takeLast(5)
|
||||
} else {
|
||||
record.loco
|
||||
}
|
||||
"${record.locoType}-${shortLoco}"
|
||||
}
|
||||
record.locoType.isNotEmpty() -> record.locoType
|
||||
record.loco.isNotEmpty() -> record.loco
|
||||
else -> ""
|
||||
@@ -528,18 +530,20 @@ fun MergedTrainRecordItem(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val trainDisplay = recordMap["train"]?.toString() ?: "未知列车"
|
||||
val trainDisplay = recordMap["train"]?.toString() ?: ""
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
Text(
|
||||
text = trainDisplay,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 20.sp,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
if (trainDisplay.isNotEmpty()) {
|
||||
Text(
|
||||
text = trainDisplay,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 20.sp,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
|
||||
val directionText = when (latestRecord.direction) {
|
||||
1 -> "下"
|
||||
@@ -572,13 +576,13 @@ fun MergedTrainRecordItem(
|
||||
|
||||
val formattedInfo = when {
|
||||
latestRecord.locoType.isNotEmpty() && latestRecord.loco.isNotEmpty() -> {
|
||||
val shortLoco = if (latestRecord.loco.length > 5) {
|
||||
latestRecord.loco.takeLast(5)
|
||||
} else {
|
||||
latestRecord.loco
|
||||
}
|
||||
"${latestRecord.locoType}-${shortLoco}"
|
||||
val shortLoco = if (latestRecord.loco.length > 5) {
|
||||
latestRecord.loco.takeLast(5)
|
||||
} else {
|
||||
latestRecord.loco
|
||||
}
|
||||
"${latestRecord.locoType}-${shortLoco}"
|
||||
}
|
||||
latestRecord.locoType.isNotEmpty() -> latestRecord.locoType
|
||||
latestRecord.loco.isNotEmpty() -> latestRecord.loco
|
||||
else -> ""
|
||||
|
||||
Reference in New Issue
Block a user