fix: ProgressStyle Point位置計算を修正

- Point(0) は @IntRange(from=1) 違反 → coerceIn(1, max) で修正
- Segment length を均等固定値(100)にして丸め誤差を排除
- progressMax = numSegments * 100 で座標系を統一
- Point position = stationIndex * 100 で全駅等分に忠実に配置
- デバッグログにpointPositionsを追加(Metroコンソールで確認可能)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
harukin-expo-dev-env
2026-03-23 06:21:26 +00:00
parent 9a567d2486
commit f19600a3af
2 changed files with 24 additions and 14 deletions

View File

@@ -7,7 +7,6 @@ import android.graphics.Color
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import kotlin.math.roundToInt
object TrainFollowNotificationBuilder {
fun build(
@@ -102,10 +101,12 @@ object TrainFollowNotificationBuilder {
val numSegments = total - 1
val curIdx = currentIndex.coerceIn(0, total - 1)
// 各駅の位置を010000の範囲で計算全駅等分
val positions = (0 until total).map { i ->
if (numSegments == 0) 0
else (i * 10000.0 / numSegments).roundToInt().coerceIn(0, 10000)
if (numSegments == 0) {
return NotificationCompat.ProgressStyle()
.setProgressSegments(listOf(
NotificationCompat.ProgressStyle.Segment(1).setColor(trainColor)
))
.setProgress(1)
}
val dimColor = Color.argb(
@@ -115,31 +116,35 @@ object TrainFollowNotificationBuilder {
Color.blue(trainColor)
)
// 各セグメントの長さを均等に(合計 = numSegments * 100
val segmentLength = 100
val progressMax = numSegments * segmentLength
// セグメント: 通過済み=trainColor, 未通過=dimColor
val segments = (0 until numSegments).map { i ->
val length = positions[i + 1] - positions[i]
val segColor = if (i < curIdx) trainColor else dimColor
NotificationCompat.ProgressStyle.Segment(length).setColor(segColor)
NotificationCompat.ProgressStyle.Segment(segmentLength).setColor(segColor)
}
// ポイント: 停車駅のみ表示(通過駅はポイントなし)
// ポイント位置: 駅 i → i * segmentLength (ただし最小値 1)
val stopPoints = mutableListOf<NotificationCompat.ProgressStyle.Point>()
stations.forEachIndexed { i, station ->
if (station.isStop) {
val pos = (i * segmentLength).coerceIn(1, progressMax)
val ptColor = if (i <= curIdx) trainColor else dimColor
stopPoints.add(
NotificationCompat.ProgressStyle.Point(positions[i]).setColor(ptColor)
NotificationCompat.ProgressStyle.Point(pos).setColor(ptColor)
)
}
}
// 現在地 = 駅位置に対応する進捗値
val progressValue = positions[curIdx]
// 現在地進捗値
val progressValue = (curIdx * segmentLength).coerceIn(0, progressMax)
android.util.Log.d("ProgressStyle",
"total=$total stops=${stopPoints.size} curIdx=$curIdx progressValue=$progressValue " +
"stopPositions=${stopPoints.map { "?" }} " +
"stationNames=${stations.filter { it.isStop }.map { it.name }}"
"total=$total stops=${stopPoints.size} curIdx=$curIdx " +
"progressMax=$progressMax progressValue=$progressValue " +
"pointPositions=${stopPoints.joinToString(",") { "${it.position}" }}"
)
return NotificationCompat.ProgressStyle()

View File

@@ -284,6 +284,11 @@ export async function updateTrainFollowActivity(
const totalStations = state.allStations?.length ?? state.stationStops?.length ?? 0;
const stopsJson = JSON.stringify(state.stationStops ?? []);
const allStationsJson = JSON.stringify(state.allStations ?? []);
const stopCount = state.allStations?.filter(s => s.isStop).length ?? 0;
console.log(`[LiveActivity] update: currentIdx=${currentIdx} total=${totalStations} stops=${stopCount} allStations=${state.allStations?.length ?? 0} currentStation=${state.currentStation} nextStation=${state.nextStation}`);
if (state.allStations && state.allStations.length > 0) {
console.log(`[LiveActivity] first5=${JSON.stringify(state.allStations.slice(0, 5))} around_cur=${JSON.stringify(state.allStations.slice(Math.max(0, currentIdx - 1), currentIdx + 3))}`);
}
await ExpoLiveActivityModule.updateTrainFollowNotification({
title, body, color,
progressCurrent: currentIdx,