Skip to content

Commit cd8f64f

Browse files
committed
Cleaning up the QrEncoder interface
1 parent 1bfd5ab commit cd8f64f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

composeqrcode/src/main/java/com/lightspark/composeqr/QrCodeView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fun QrCodeView(
3636
modifier: Modifier = Modifier,
3737
colors: QrCodeColors = QrCodeColors.default(),
3838
dotShape: DotShape = DotShape.Square,
39-
encoder: QrEncoder = QrEncoder(),
39+
encoder: QrEncoder = ZxingQrEncoder(),
4040
overlayContent: (@Composable () -> Unit)? = null,
4141
) {
4242
Box(modifier = modifier, contentAlignment = Alignment.Center) {
@@ -70,9 +70,9 @@ fun QrCodeView(
7070
modifier: Modifier = Modifier,
7171
colors: QrCodeColors = QrCodeColors.default(),
7272
dotShape: DotShape = DotShape.Square,
73-
encoder: QrEncoder = QrEncoder()
73+
encoder: QrEncoder = ZxingQrEncoder()
7474
) {
75-
val encodedData = remember(data, encoder) { encoder(data) }
75+
val encodedData = remember(data, encoder) { encoder.encode(data) }
7676

7777
Canvas(modifier = modifier.background(colors.background)) {
7878
encodedData?.let { matrix ->

composeqrcode/src/main/java/com/lightspark/composeqr/QrEncoder.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ import com.google.zxing.qrcode.encoder.ByteMatrix
66
import com.google.zxing.qrcode.encoder.Encoder
77

88
/**
9-
* Encodes a string into a QR code ByteMatrix. This is just a small wrapper around the ZXing library with sane defaults.
9+
* Encodes a string into a QR code ByteMatrix. The default implementation, `ZxingQrEncoder` just
10+
* wraps the ZXing library with sane defaults.
1011
*/
11-
class QrEncoder {
12-
operator fun invoke(qrData: String): ByteMatrix? {
12+
interface QrEncoder {
13+
fun encode(qrData: String): ByteMatrix?
14+
}
15+
16+
/**
17+
* This is just a small wrapper around the ZXing library with sane defaults.
18+
*/
19+
class ZxingQrEncoder : QrEncoder {
20+
override fun encode(qrData: String): ByteMatrix? {
1321
return Encoder.encode(
1422
qrData,
1523
ErrorCorrectionLevel.H,

0 commit comments

Comments
 (0)