Skip to content

Commit

Permalink
Merge pull request #54 from ImaginativeShohag/barcode-scanner
Browse files Browse the repository at this point in the history
refactor(barcodescanner): rename `BarcodeAnalyser` to `BarcodeAnalyzer`, improve ui
  • Loading branch information
ImaginativeShohag authored Dec 27, 2024
2 parents 4ed2765 + 2edd4b3 commit 4c687aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.google.mlkit.vision.barcode.common.Barcode
import com.google.mlkit.vision.common.InputImage
import timber.log.Timber

class BarcodeAnalyser(
class BarcodeAnalyzer(
private val controller: LifecycleCameraController,
private val onBarcodeDetect: (barcodes: List<Barcode>) -> Unit
) : ImageAnalysis.Analyzer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fun CameraPreviewView(

cameraProvider = cameraProviderFuture.get()

val barcodeAnalyser = BarcodeAnalyser(
val barcodeAnalyzer = BarcodeAnalyzer(
controller = cameraController,
onBarcodeDetect = { barcodes ->
stopCamera()
Expand All @@ -97,7 +97,7 @@ fun CameraPreviewView(
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build()
.also {
it.setAnalyzer(cameraExecutor, barcodeAnalyser)
it.setAnalyzer(cameraExecutor, barcodeAnalyzer)
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import org.imaginativeworld.whynotcompose.common.compose.compositions.AppComponent
Expand Down Expand Up @@ -99,6 +100,16 @@ private fun BarcodeScannerScreenSkeletonPreview() {
}
}

@PreviewLightDark
@Composable
private fun BarcodeScannerScreenSkeletonWithCodePreview() {
AppTheme {
BarcodeScannerScreenSkeleton(
scannedCode = "Lorem Ipsum Dolor"
)
}
}

@Suppress("ktlint:compose:modifier-missing-check")
@Composable
fun BarcodeScannerScreenSkeleton(
Expand Down Expand Up @@ -133,12 +144,18 @@ fun BarcodeScannerScreenSkeleton(
style = MaterialTheme.typography.titleMedium
)

if (scannedCode.isNullOrBlank()) {
Text("No Data")
val finalScannedCode = if (scannedCode.isNullOrBlank()) {
"No Data"
} else {
Text(scannedCode)
scannedCode
}

Text(
finalScannedCode,
fontFamily = FontFamily.Monospace,
style = MaterialTheme.typography.bodyLarge
)

Spacer(Modifier.height(32.dp))

Button(
Expand Down

0 comments on commit 4c687aa

Please sign in to comment.