Skip to content

Commit

Permalink
Address some detekt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Scholz committed Oct 10, 2023
1 parent 490d461 commit 74ea0b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions kotlin-sample/src/main/kotlin/io/github/simonscholz/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.simonscholz

import io.github.simonscholz.qrcode.DEFAULT_IMG_SIZE
import io.github.simonscholz.qrcode.QrCodeApi
import io.github.simonscholz.qrcode.QrCodeColorConfig
import io.github.simonscholz.qrcode.QrCodeConfig
Expand All @@ -19,7 +20,6 @@ fun BufferedImage.toFile(file: File) {
ImageIO.write(this, "png", file)
}

private const val IMG_SIZE = 300
private const val RELATIVE_SQUARE_BORDER_ROUND = .5
private val VIOLETT = Color(0x0063, 0x000B, 0x00A5)

Expand Down Expand Up @@ -49,15 +49,15 @@ fun main() {
}

private fun createDefaultQrCode(qrCodeApi: QrCodeApi, qrCodeDir: String) {
qrCodeApi.createQrImage(QrCodeConfig("https://simonscholz.github.io/", IMG_SIZE))
qrCodeApi.createQrImage(QrCodeConfig("https://simonscholz.github.io/", DEFAULT_IMG_SIZE))
.toFile(File(qrCodeDir, "/qr-with-defaults-kotlin.png"))
}

private fun createDefaultQrCodeWithLogo(resource: URL, qrCodeApi: QrCodeApi, qrCodeDir: String) {
val logo = ImageIO.read(resource)
val qrCodeConfig = QrCodeConfig(
"https://simonscholz.github.io/",
IMG_SIZE,
DEFAULT_IMG_SIZE,
QrLogoConfig(logo),
)
qrCodeApi.createQrImage(qrCodeConfig).toFile(File(qrCodeDir, "/qr-with-logo-kotlin.png"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package io.github.simonscholz.qrcode
import java.awt.Color
import java.awt.image.BufferedImage

const val DEFAULT_IMG_SIZE = 300

/**
* Object to be passed to QrCodeApi.
*
Expand All @@ -15,7 +17,7 @@ import java.awt.image.BufferedImage
*/
data class QrCodeConfig @JvmOverloads constructor(
val qrCodeText: String,
val qrCodeSize: Int = 300,
val qrCodeSize: Int = DEFAULT_IMG_SIZE,
val qrLogoConfig: QrLogoConfig? = null,
val qrCodeColorConfig: QrCodeColorConfig = QrCodeColorConfig(),
val qrPositionalSquaresConfig: QrPositionalSquaresConfig = QrPositionalSquaresConfig(),
Expand All @@ -27,7 +29,7 @@ data class QrCodeConfig @JvmOverloads constructor(
}

class Builder(private val qrCodeText: String) {
private var qrCodeSize: Int = 300
private var qrCodeSize: Int = DEFAULT_IMG_SIZE
private var qrLogoConfig: QrLogoConfig? = null
private var qrCodeColorConfig: QrCodeColorConfig = QrCodeColorConfig()
private var qrPositionalSquaresConfig: QrPositionalSquaresConfig = QrPositionalSquaresConfig()
Expand All @@ -36,7 +38,9 @@ data class QrCodeConfig @JvmOverloads constructor(
fun qrCodeSize(qrCodeSize: Int) = apply { this.qrCodeSize = qrCodeSize }

@JvmOverloads fun qrLogoConfig(logo: BufferedImage, relativeSize: Double = .2, bgColor: Color? = null) = apply { this.qrLogoConfig = QrLogoConfig(logo, relativeSize, bgColor) }
fun qrCodeColorConfig(bgColor: Color = Color.WHITE, fillColor: Color = Color.BLACK) = apply { this.qrCodeColorConfig = QrCodeColorConfig(bgColor, fillColor) }

@JvmOverloads fun qrCodeColorConfig(bgColor: Color = Color.WHITE, fillColor: Color = Color.BLACK) = apply { this.qrCodeColorConfig = QrCodeColorConfig(bgColor, fillColor) }

fun qrPositionalSquaresConfig(qrPositionalSquaresConfig: QrPositionalSquaresConfig) = apply { this.qrPositionalSquaresConfig = qrPositionalSquaresConfig }

@JvmOverloads fun qrBorderConfig(color: Color = Color.BLACK, relativeSize: Double = .05, relativeBorderRound: Double = 0.2) = apply { this.qrBorderConfig = QrBorderConfig(color, relativeSize, relativeBorderRound) }
Expand All @@ -59,7 +63,11 @@ data class QrCodeConfig @JvmOverloads constructor(
* @param relativeSize - relative size of the logo, defaults to 0.2
* @param bgColor - specify the background color of the logo, defaults to null
*/
data class QrLogoConfig @JvmOverloads constructor(val logo: BufferedImage, val relativeSize: Double = .2, val bgColor: Color? = null) {
data class QrLogoConfig @JvmOverloads constructor(
val logo: BufferedImage,
val relativeSize: Double = .2,
val bgColor: Color? = null,
) {
init {
require(relativeSize in .1..1.0) { "relativeSize must be in between 0.1 and 1." }
}
Expand All @@ -73,7 +81,10 @@ data class QrLogoConfig @JvmOverloads constructor(val logo: BufferedImage, val r
* @param bgColor - specify the background color of the qr code - may also be transparent, defaults to Color.WHITE
* @param fillColor - specify the fill or foreground color of the qr code - should not be transparent, defaults to Color.BLACK
*/
data class QrCodeColorConfig @JvmOverloads constructor(val bgColor: Color = Color.WHITE, val fillColor: Color = Color.BLACK)
data class QrCodeColorConfig @JvmOverloads constructor(
val bgColor: Color = Color.WHITE,
val fillColor: Color = Color.BLACK,
)

/**
* Specify the colors and shapes of the positional squares of the qr code.
Expand All @@ -97,7 +108,7 @@ data class QrPositionalSquaresConfig @JvmOverloads constructor(
require(relativeSquareBorderRound in 0.0..1.0) { "relativeSquareBorderRound must be in between 0 and 1." }
}

class Builder() {
class Builder {
private var isCircleShaped: Boolean = false
private var relativeSquareBorderRound: Double = .0
private var centerColor: Color = Color.BLACK
Expand Down Expand Up @@ -130,7 +141,11 @@ data class QrPositionalSquaresConfig @JvmOverloads constructor(
* @param relativeSize - relative size of the border, defaults to 0.05
* @param relativeBorderRound - relative border round, defaults to 0.2
*/
data class QrBorderConfig @JvmOverloads constructor(val color: Color = Color.BLACK, val relativeSize: Double = .05, val relativeBorderRound: Double = 0.2) {
data class QrBorderConfig @JvmOverloads constructor(
val color: Color = Color.BLACK,
val relativeSize: Double = .05,
val relativeBorderRound: Double = 0.2,
) {
init {
require(relativeSize in 0.01..1.0) { "relativeSize must be in between 0.01 and 1." }
require(relativeBorderRound in 0.01..1.0) { "relativeSize must be in between 0.01 and 1." }
Expand Down

0 comments on commit 74ea0b3

Please sign in to comment.