diff --git a/app/src/main/java/org/noxylva/lbjconsole/model/TrainRecord.kt b/app/src/main/java/org/noxylva/lbjconsole/model/TrainRecord.kt index 3a38845..a6c52a9 100644 --- a/app/src/main/java/org/noxylva/lbjconsole/model/TrainRecord.kt +++ b/app/src/main/java/org/noxylva/lbjconsole/model/TrainRecord.kt @@ -149,7 +149,7 @@ class TrainRecord(jsonData: JSONObject? = null) { lbjClass.trim() } else if (isValidValue(train)) { train.trim() - } else "" + } else null val map = mutableMapOf() @@ -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" diff --git a/app/src/main/java/org/noxylva/lbjconsole/ui/screens/HistoryScreen.kt b/app/src/main/java/org/noxylva/lbjconsole/ui/screens/HistoryScreen.kt index 925f7ab..2d5cb2d 100644 --- a/app/src/main/java/org/noxylva/lbjconsole/ui/screens/HistoryScreen.kt +++ b/app/src/main/java/org/noxylva/lbjconsole/ui/screens/HistoryScreen.kt @@ -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 -> "下" @@ -203,16 +205,16 @@ 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 -> ""