diff --git a/detekt.yml b/detekt.yml index 66f48b5a..bf1ac4a6 100644 --- a/detekt.yml +++ b/detekt.yml @@ -1,5 +1,5 @@ complexity: - ComplexMethod: + CyclomaticComplexMethod: ignoreSingleWhenExpression: true LongParameterList: ignoreAnnotated: ['Parcelize'] @@ -15,8 +15,6 @@ formatting: active: false FinalNewline: insertFinalNewLine: false - ParameterListWrapping: - indentSize: 2 performance: SpreadOperator: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ea514289..65e6b423 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,25 +1,25 @@ [versions] -quickie = "1.5.2" +quickie = "1.6.0" androidconfig-minSdk = "21" -androidconfig-compileSdk = "32" -androidconfig-targetSdk = "32" -androidconfig-buildTools = "32.0.0" +androidconfig-compileSdk = "33" +androidconfig-targetSdk = "33" +androidconfig-buildTools = "33.0.1" androidGradle = "7.3.1" -kotlin = "1.7.20" +kotlin = "1.7.21" appcompat = "1.5.1" -cameraX = "1.1.0" +cameraX = "1.2.0" -barcodeScanning = "17.0.2" +barcodeScanning = "17.0.3" barcodeScanningGms = "18.1.0" materialDesign = "1.7.0" -detekt = "1.21.0" -gradleVersions = "0.43.0" +detekt = "1.22.0" +gradleVersions = "0.44.0" dokka = "1.7.20" junit = "5.9.1" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e5832..943f0cbf 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661e..f398c33c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb6..65dcd68d 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,10 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -143,12 +143,16 @@ fi if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac diff --git a/gradlew.bat b/gradlew.bat index 53a6b238..6689b85b 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QROverlayView.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QROverlayView.kt index c4df41b1..ce2446cb 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QROverlayView.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QROverlayView.kt @@ -119,6 +119,12 @@ internal class QROverlayView @JvmOverloads constructor( } } + fun setCloseVisibilityAndOnClick(visible: Boolean, action: () -> Unit = {}) { + binding.closeImageView.visibility = if (visible) View.VISIBLE else View.GONE + binding.closeImageView.setOnClickListener { action() } + if (visible) binding.closeImageView.setTintAndStateAwareBackground() + } + fun setTorchVisibilityAndOnClick(visible: Boolean, action: (Boolean) -> Unit = {}) { binding.torchImageView.visibility = if (visible) View.VISIBLE else View.GONE binding.torchImageView.setOnClickListener { action(!it.isSelected) } diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt index 03a3c3b2..98ed1811 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt @@ -37,6 +37,7 @@ internal class QRScannerActivity : AppCompatActivity() { private var barcodeFormats = intArrayOf(Barcode.FORMAT_QR_CODE) private var hapticFeedback = true private var showTorchToggle = false + private var showCloseButton = false private var useFrontCamera = false internal var errorDialog: Dialog? = null set(value) { @@ -82,10 +83,20 @@ internal class QRScannerActivity : AppCompatActivity() { } private fun startCamera() { - val cameraProviderFuture = ProcessCameraProvider.getInstance(this) + val cameraProviderFuture = try { + ProcessCameraProvider.getInstance(this) + } catch (e: Exception) { + onFailure(e) + return + } cameraProviderFuture.addListener({ - val cameraProvider = cameraProviderFuture.get() + val cameraProvider = try { + cameraProviderFuture.get() + } catch (e: Exception) { + onFailure(e) + return@addListener + } val preview = Preview.Builder().build().also { it.setSurfaceProvider(binding.previewView.surfaceProvider) } val imageAnalysis = ImageAnalysis.Builder() @@ -107,14 +118,14 @@ internal class QRScannerActivity : AppCompatActivity() { } cameraProvider.unbindAll() + + val cameraSelector = + if (useFrontCamera) CameraSelector.DEFAULT_FRONT_CAMERA else CameraSelector.DEFAULT_BACK_CAMERA + try { - val cameraSelector = if (useFrontCamera) { - CameraSelector.DEFAULT_FRONT_CAMERA - } else { - CameraSelector.DEFAULT_BACK_CAMERA - } val camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageAnalysis) binding.overlayView.visibility = View.VISIBLE + binding.overlayView.setCloseVisibilityAndOnClick(showCloseButton) { finish() } if (showTorchToggle && camera.cameraInfo.hasFlashUnit()) { binding.overlayView.setTorchVisibilityAndOnClick(true) { camera.cameraControl.enableTorch(it) } camera.cameraInfo.torchState.observe(this) { binding.overlayView.setTorchState(it == TorchState.ON) } @@ -131,6 +142,7 @@ internal class QRScannerActivity : AppCompatActivity() { private fun onSuccess(result: Barcode) { binding.overlayView.isHighlighted = true if (hapticFeedback) { + @Suppress("DEPRECATION") binding.overlayView.performHapticFeedback( HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING or HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING @@ -165,6 +177,7 @@ internal class QRScannerActivity : AppCompatActivity() { } private fun applyScannerConfig() { + @Suppress("DEPRECATION") intent?.getParcelableExtra(EXTRA_CONFIG)?.let { barcodeFormats = it.formats binding.overlayView.setCustomText(it.stringRes) @@ -173,6 +186,7 @@ internal class QRScannerActivity : AppCompatActivity() { hapticFeedback = it.hapticFeedback showTorchToggle = it.showTorchToggle useFrontCamera = it.useFrontCamera + showCloseButton = it.showCloseButton } } diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt index 2b3433d6..78e1e427 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt @@ -12,4 +12,5 @@ internal class ParcelableScannerConfig( val showTorchToggle: Boolean, val horizontalFrameRatio: Float, val useFrontCamera: Boolean, + val showCloseButton: Boolean, ) : Parcelable \ No newline at end of file diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt index a9c2d8cc..03e6bbb5 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt @@ -6,6 +6,7 @@ import androidx.annotation.StringRes /** * Builder for ScannerConfig used in ScanBarcode ActivityResultContract. */ +@Suppress("LongParameterList") public class ScannerConfig internal constructor( internal val formats: IntArray, internal val stringRes: Int, @@ -14,6 +15,7 @@ public class ScannerConfig internal constructor( internal val showTorchToggle: Boolean, internal val horizontalFrameRatio: Float, internal val useFrontCamera: Boolean, + internal val showCloseButton: Boolean, ) { public class Builder { @@ -24,6 +26,7 @@ public class ScannerConfig internal constructor( private var showTorchToggle: Boolean = false private var horizontalFrameRatio: Float = 1f private var useFrontCamera: Boolean = false + private var showCloseButton: Boolean = false /** * Set a list of interested barcode formats. List must not be empty. @@ -63,6 +66,11 @@ public class ScannerConfig internal constructor( */ public fun setUseFrontCamera(enable: Boolean): Builder = apply { useFrontCamera = enable } + /** + * Show or hide (default) close button. + */ + public fun setShowCloseButton(enable: Boolean): Builder = apply { showCloseButton = enable } + /** * Build the BarcodeConfig required by the ScanBarcode ActivityResultContract. */ @@ -75,6 +83,7 @@ public class ScannerConfig internal constructor( showTorchToggle, horizontalFrameRatio, useFrontCamera, + showCloseButton, ) } diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/IntentExtensions.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/IntentExtensions.kt index ac7852a4..2f2f9edd 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/IntentExtensions.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/IntentExtensions.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package io.github.g00fy2.quickie.extensions import android.content.Intent diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt index 09912755..7d24d8d3 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt @@ -12,4 +12,5 @@ internal fun ScannerConfig.toParcelableConfig() = showTorchToggle = showTorchToggle, horizontalFrameRatio = horizontalFrameRatio, useFrontCamera = useFrontCamera, + showCloseButton = showCloseButton, ) \ No newline at end of file diff --git a/quickie/src/main/res/drawable/quickie_bg_torch.xml b/quickie/src/main/res/drawable/quickie_bg_round.xml similarity index 100% rename from quickie/src/main/res/drawable/quickie_bg_torch.xml rename to quickie/src/main/res/drawable/quickie_bg_round.xml diff --git a/quickie/src/main/res/drawable/quickie_ic_close.xml b/quickie/src/main/res/drawable/quickie_ic_close.xml new file mode 100644 index 00000000..8deb808e --- /dev/null +++ b/quickie/src/main/res/drawable/quickie_ic_close.xml @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/quickie/src/main/res/layout/quickie_overlay_view.xml b/quickie/src/main/res/layout/quickie_overlay_view.xml index 5896816d..5324b000 100644 --- a/quickie/src/main/res/layout/quickie_overlay_view.xml +++ b/quickie/src/main/res/layout/quickie_overlay_view.xml @@ -26,13 +26,26 @@ app:drawableTopCompat="@drawable/quickie_ic_qrcode" /> + +