Update FeliCa transaction parsing on Android
This commit is contained in:
@ -820,17 +820,8 @@ private object KmtReader {
|
||||
private fun parseHistoryBlock(data: ByteArray, strings: AndroidStrings): TransactionItem? {
|
||||
if (data.size < 16) return null
|
||||
val stationId = data.copyOfRange(8, 10).bigEndianLong().toInt()
|
||||
val type = data[10].toInt() and 0xFF
|
||||
val isParking = stationId == 0
|
||||
var isCredit = type == 0x00
|
||||
val title = when (type) {
|
||||
0x00, 0x03 -> strings.get(R.string.topup)
|
||||
0x01 -> strings.get(R.string.payment)
|
||||
else -> strings.get(R.string.payment)
|
||||
}
|
||||
if (type == 0x03){
|
||||
isCredit = true
|
||||
}
|
||||
val transactionKind = felicaTransactionKind(data)
|
||||
val amount = if (isParking) {
|
||||
data.copyOfRange(8, 12).bigEndianLong()
|
||||
} else {
|
||||
@ -844,14 +835,54 @@ private object KmtReader {
|
||||
val location = stationMap[stationId]?.uppercase(Locale.getDefault()).orEmpty()
|
||||
|
||||
return TransactionItem(
|
||||
title = title,
|
||||
title = strings.get(transactionKind.titleRes),
|
||||
date = date,
|
||||
amount = amount,
|
||||
isCredit = isCredit,
|
||||
isCredit = transactionKind.isCredit,
|
||||
locationName = location
|
||||
)
|
||||
}
|
||||
|
||||
private fun felicaTransactionKind(data: ByteArray): FelicaTransactionKind {
|
||||
val signature = listOf(
|
||||
data[10].toInt() and 0xFF,
|
||||
data[11].toInt() and 0xFF,
|
||||
data[12].toInt() and 0xFF
|
||||
)
|
||||
|
||||
return when (signature) {
|
||||
listOf(0x00, 0x02, 0x00),
|
||||
listOf(0x03, 0x01, 0x00) -> FelicaTransactionKind(
|
||||
titleRes = R.string.topup,
|
||||
isCredit = true
|
||||
)
|
||||
|
||||
listOf(0x01, 0x01, 0x01),
|
||||
listOf(0x01, 0x58, 0x01),
|
||||
listOf(0x03, 0x61, 0x01) -> FelicaTransactionKind(
|
||||
titleRes = R.string.payment,
|
||||
isCredit = false
|
||||
)
|
||||
|
||||
else -> when (data[10].toInt() and 0xFF) {
|
||||
0x00 -> FelicaTransactionKind(
|
||||
titleRes = R.string.topup,
|
||||
isCredit = true
|
||||
)
|
||||
|
||||
0x01, 0x03 -> FelicaTransactionKind(
|
||||
titleRes = R.string.payment,
|
||||
isCredit = false
|
||||
)
|
||||
|
||||
else -> FelicaTransactionKind(
|
||||
titleRes = R.string.payment,
|
||||
isCredit = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseReskaDate(data: ByteArray): Date {
|
||||
val first16 = data.toHex().take(16)
|
||||
return runCatching {
|
||||
@ -859,3 +890,8 @@ private object KmtReader {
|
||||
}.getOrNull() ?: Date()
|
||||
}
|
||||
}
|
||||
|
||||
private data class FelicaTransactionKind(
|
||||
val titleRes: Int,
|
||||
val isCredit: Boolean
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user