Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-5808] GS1 QR code is show as QR Code if value does not have GS1 prefix value. #3709

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ class QRImageControllerImpl(
) : QRImageController {

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun getWriterFromRendering(value: String, renderingType: UiRenderType) = when {
value.startsWith(GS1Elements.GS1_d2_IDENTIFIER.element) -> Pair(
DataMatrixWriter(),
BarcodeFormat.DATA_MATRIX,
)
renderingType == UiRenderType.QR_CODE -> Pair(QRCodeWriter(), BarcodeFormat.QR_CODE)
renderingType == UiRenderType.BAR_CODE -> Pair(Code128Writer(), BarcodeFormat.CODE_128)
else -> throw IllegalArgumentException()
}
fun getWriterFromRendering(value: String, renderingType: UiRenderType) =
when (renderingType) {
UiRenderType.GS1_DATAMATRIX ->
if (value.startsWith(GS1Elements.GS1_d2_IDENTIFIER.element)) {
Pair(DataMatrixWriter(), BarcodeFormat.DATA_MATRIX)
} else {
Pair(QRCodeWriter(), BarcodeFormat.QR_CODE)
}
UiRenderType.QR_CODE -> Pair(QRCodeWriter(), BarcodeFormat.QR_CODE)
UiRenderType.BAR_CODE -> Pair(Code128Writer(), BarcodeFormat.CODE_128)
else -> throw IllegalArgumentException()
}

private fun formattedContent(value: String) =
value.removePrefix(GS1Elements.GS1_d2_IDENTIFIER.element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ class QRImageControllerTest {
@Test
fun shouldReturnDataMatrixWriter() {
val testValue = "]d2\u001D01084700069915412110081996195256\u001D10DXB2005\u001D17220228"
controller.getWriterFromRendering(testValue, UiRenderType.QR_CODE).let { (writer, format) ->
controller.getWriterFromRendering(testValue, UiRenderType.GS1_DATAMATRIX).let { (writer, format) ->
assertTrue(writer is DataMatrixWriter)
assertTrue(format == BarcodeFormat.DATA_MATRIX)
}
}

@Test
fun shouldReturnQRWriterWhenValueDoesNotHaveGS1Prefix() {
val testValue = "01084700069915412110081996195256\u001D10DXB2005\u001D17220228"
controller.getWriterFromRendering(testValue, UiRenderType.GS1_DATAMATRIX).let { (writer, format) ->
assertTrue(writer is QRCodeWriter)
assertTrue(format == BarcodeFormat.QR_CODE)
}
}

@Test
fun shouldReturnQRWriter() {
val testValue = "qrValue"
Expand Down