diff --git a/app/src/main/java/dgca/verifier/app/android/MainActivity.kt b/app/src/main/java/dgca/verifier/app/android/MainActivity.kt index 72c79fb7..65238bf0 100644 --- a/app/src/main/java/dgca/verifier/app/android/MainActivity.kt +++ b/app/src/main/java/dgca/verifier/app/android/MainActivity.kt @@ -113,25 +113,24 @@ class MainActivity : AppCompatActivity() { return } - val builder = StringBuilder() - val records = NdefParser.parse(messages[0]) - val size = records.size - - for (i in 0 until size) { - val record = records[i] - val str = record.str() - builder.append(str) - } - - val qrCodeText = builder.toString() - if (qrCodeText.isNotEmpty()) { - navHostFragment.childFragmentManager.primaryNavigationFragment?.let { fragment -> - if (fragment is CodeReaderFragment && fragment.isVisible) { - fragment.onNdefMessageReceived(qrCodeText) + val itr = messages.listIterator() + + while (itr.hasNext()) { + val records = NdefParser.parse(itr.next()) + + for (i in 0 until records.size) { + if (records[i] != null) { + val record = records[i].str() + + if (record.length >= 5 && record.substring(0, 4) == "HC1:") { + navHostFragment.childFragmentManager.primaryNavigationFragment?.let { fragment -> + if (fragment is CodeReaderFragment && fragment.isVisible) { + fragment.onNdefMessageReceived(record) + } + } + } } } - } else { - Timber.d("Received empty NDEFMessage") } } } \ No newline at end of file diff --git a/app/src/main/java/dgca/verifier/app/android/nfc/NdefParser.kt b/app/src/main/java/dgca/verifier/app/android/nfc/NdefParser.kt index 3b2296ca..308dbf5b 100644 --- a/app/src/main/java/dgca/verifier/app/android/nfc/NdefParser.kt +++ b/app/src/main/java/dgca/verifier/app/android/nfc/NdefParser.kt @@ -65,7 +65,9 @@ fun NdefRecord.parse(): ParsedNdefRecord? { Charsets.UTF_16 } - val text = String(recordPayload, textEncoding) + val langCodeLen = (recordPayload[0] and 63.toByte()).toInt() + val text = String(recordPayload, textEncoding).substring(1 + langCodeLen) + return TextRecord(text) } catch (e: UnsupportedEncodingException) { Timber.w("We got a malformed tag.") diff --git a/app/src/main/java/dgca/verifier/app/android/reader/CodeReaderFragment.kt b/app/src/main/java/dgca/verifier/app/android/reader/CodeReaderFragment.kt index 03b3e45e..a9074023 100644 --- a/app/src/main/java/dgca/verifier/app/android/reader/CodeReaderFragment.kt +++ b/app/src/main/java/dgca/verifier/app/android/reader/CodeReaderFragment.kt @@ -267,21 +267,15 @@ class CodeReaderFragment : BindingFragment(), NavCont } fun onNdefMessageReceived(qrCodeText: String) { - val position = binding.countrySelector.selectedItemPosition - if (position == -1 || refinedCountries.isEmpty()) { - return - } - try { - val countryCode = refinedCountries[position].toLowerCase(Locale.ROOT) val action = CodeReaderFragmentDirections.actionCodeReaderFragmentToVerificationDialogFragment( - qrCodeText, - countryCode + qrCodeText, + binding.countrySelector.selectedItem?.toString() ?: "" ) findNavController().navigate(action) } catch (ex: Exception) { - Timber.d("Cannot get iso country code for position.") + Timber.d("action_codeReaderFragment_to_verificationDialogFragment cannot be found from the current destination Destination.") } } -} \ No newline at end of file +}