Skip to content

Commit b01f3c0

Browse files
authored
Merge pull request #14357 from woocommerce/issue/woomob-908-woo-posbarcodes-scanners-might-have-troubles-scanning
[WOOMOB-908] Improve scanning performance in dark mode for Scanner setup flow
2 parents dde5ad8 + 433dfc8 commit b01f3c0

File tree

3 files changed

+111
-11
lines changed

3 files changed

+111
-11
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/compose/component/BarcodeComponent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ fun BarcodeEAN13Code(
8080
content: String,
8181
widthDp: Dp,
8282
heightDp: Dp,
83-
codeColor: Color,
84-
backgroundColor: Color,
83+
codeColor: Color = colorResource(id = R.color.woo_black_90),
84+
backgroundColor: Color = colorResource(id = R.color.woo_white),
8585
@DrawableRes overlayId: Int? = null,
8686
) {
8787
Image(
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.woocommerce.android.ui.woopos.common.composeui.component
2+
3+
import android.app.Activity
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.runtime.DisposableEffect
6+
import androidx.compose.runtime.LaunchedEffect
7+
import androidx.compose.runtime.getValue
8+
import androidx.compose.runtime.mutableStateOf
9+
import androidx.compose.runtime.remember
10+
import androidx.compose.runtime.setValue
11+
import androidx.compose.ui.platform.LocalContext
12+
13+
@Composable
14+
fun WooPosBrightnessControl(temporarilyIncreaseToMax: Boolean = true) {
15+
val context = LocalContext.current
16+
var originalBrightness by remember { mutableStateOf<Float?>(null) }
17+
18+
LaunchedEffect(temporarilyIncreaseToMax) {
19+
val activity = context as? Activity ?: return@LaunchedEffect
20+
val window = activity.window
21+
22+
if (temporarilyIncreaseToMax) {
23+
if (originalBrightness == null) {
24+
originalBrightness = window.attributes.screenBrightness
25+
}
26+
window.attributes = window.attributes.apply {
27+
screenBrightness = 1.0f
28+
}
29+
} else {
30+
originalBrightness?.let {
31+
window.attributes = window.attributes.apply {
32+
screenBrightness = it
33+
}
34+
originalBrightness = null
35+
}
36+
}
37+
}
38+
39+
DisposableEffect(Unit) {
40+
onDispose {
41+
if (temporarilyIncreaseToMax && originalBrightness != null) {
42+
val activity = context as? Activity ?: return@onDispose
43+
activity.window.attributes = activity.window.attributes.apply {
44+
screenBrightness = originalBrightness ?: -1.0f
45+
}
46+
}
47+
}
48+
}
49+
}

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/scanningsetup/WooPosScanningSetupDialog.kt

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import com.woocommerce.android.ui.compose.component.BarcodeEAN13Code
6666
import com.woocommerce.android.ui.compose.component.getText
6767
import com.woocommerce.android.ui.compose.preview.FontScalePreviews
6868
import com.woocommerce.android.ui.woopos.common.composeui.WooPosPreview
69+
import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosBrightnessControl
6970
import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosButton
7071
import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosButtonState
7172
import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosDialogWrapper
@@ -141,6 +142,8 @@ fun WooPosScanningSetupDialog(
141142
id = R.string.woopos_scanning_setup_dialog_content_description
142143
)
143144
) {
145+
WooPosBrightnessControl(temporarilyIncreaseToMax = true)
146+
144147
val state by viewModel.state.collectAsState()
145148
Column(
146149
modifier = Modifier
@@ -308,10 +311,10 @@ private fun ScannerModeSetupContent(
308311

309312
Box(
310313
modifier = Modifier
311-
.size(172.dp)
314+
.size(184.dp)
312315
.clip(RoundedCornerShape(WooPosCornerRadius.Medium.value))
313316
.background(Color.White)
314-
.padding(WooPosSpacing.Small.value.toAdaptivePadding()),
317+
.padding(WooPosSpacing.Medium.value.toAdaptivePadding()),
315318
contentAlignment = Alignment.Center
316319
) {
317320
Image(
@@ -366,13 +369,20 @@ private fun TestScannerContent(
366369
modifier = Modifier.padding(bottom = WooPosSpacing.Large.value.toAdaptivePadding())
367370
)
368371

369-
BarcodeEAN13Code(
370-
barcodeValue,
371-
300.dp,
372-
150.dp,
373-
codeColor = MaterialTheme.colorScheme.onSurface,
374-
backgroundColor = MaterialTheme.colorScheme.surfaceBright
375-
)
372+
Box(
373+
modifier = Modifier
374+
.size(300.dp, 150.dp)
375+
.clip(RoundedCornerShape(WooPosCornerRadius.Medium.value))
376+
.background(Color.White)
377+
.padding(WooPosSpacing.Medium.value.toAdaptivePadding()),
378+
contentAlignment = Alignment.Center
379+
) {
380+
BarcodeEAN13Code(
381+
barcodeValue,
382+
300.dp,
383+
150.dp
384+
)
385+
}
376386

377387
Spacer(modifier = Modifier.height(WooPosSpacing.XLarge.value.toAdaptivePadding()))
378388

@@ -862,3 +872,44 @@ fun WooPosScanningSetupTestScannerFailedStep() {
862872
}
863873
}
864874
}
875+
876+
@WooPosPreview
877+
@Composable
878+
fun WooPosScanningSetupTestQRContent() {
879+
WooPosTheme {
880+
Box(
881+
modifier = Modifier.fillMaxSize(),
882+
contentAlignment = Alignment.Center
883+
) {
884+
ScannerModeSetupContent(
885+
onPrimaryClick = {},
886+
onSecondaryClick = {},
887+
primaryButtonText = "Next",
888+
secondaryButtonText = "Back",
889+
title = "Scanner Mode Setup",
890+
message = "Follow the instructions to set up your scanner in HID mode.",
891+
qrCodeImageRes = R.drawable.ic_woopos_reader_setup_code_star_bsh_20
892+
)
893+
}
894+
}
895+
}
896+
897+
@WooPosPreview
898+
@Composable
899+
fun WooPosScanningSetupTestBarcodeContent() {
900+
WooPosTheme {
901+
Box(
902+
modifier = Modifier.fillMaxSize(),
903+
contentAlignment = Alignment.Center
904+
) {
905+
TestScannerContent(
906+
onSecondaryClick = {},
907+
secondaryButtonText = "Back",
908+
title = "Scanner Mode Setup",
909+
message = "Follow the instructions to set up your scanner in HID mode.",
910+
barcodeValue = "123456789012",
911+
onBarcodeScanned = {},
912+
)
913+
}
914+
}
915+
}

0 commit comments

Comments
 (0)