Support pkpass files without any extra data

Previously, the code assumed one of "boardingPass", "coupon", "eventTicket", "generic" existed and refused to pass a pkpass file without any of them
This commit is contained in:
Sylvia van Os
2025-03-17 18:37:28 +01:00
parent 99eaaebf1c
commit 2c77dcadb5
4 changed files with 68 additions and 13 deletions

View File

@@ -296,30 +296,22 @@ class PkpassParser(context: Context, uri: Uri?) {
}
// Append type-specific info to the pass
noteText.append("\n\n")
// Find the relevant pass type and parse it
var hasPassData = false
for (passType in listOf("boardingPass", "coupon", "eventTicket", "generic")) {
try {
noteText.append(
parsePassJSONPassFields(
jsonObject.getJSONObject(passType),
locale
)
var extraText = parsePassJSONPassFields(
jsonObject.getJSONObject(passType),
locale
)
hasPassData = true
noteText.append("\n\n")
noteText.append(extraText)
break
} catch (ignored: JSONException) {}
}
// Failed to parse anything, error out
if (!hasPassData) {
throw FormatException(mContext.getString(R.string.errorReadingFile))
}
note = noteText.toString()
}