@@ -9,6 +9,7 @@ import android.widget.Toast
99import androidx.activity.ComponentActivity
1010import androidx.activity.compose.rememberLauncherForActivityResult
1111import androidx.activity.compose.setContent
12+ import androidx.activity.enableEdgeToEdge
1213import androidx.activity.result.contract.ActivityResultContracts
1314import androidx.camera.core.CameraControl
1415import androidx.camera.core.CameraInfo
@@ -49,6 +50,7 @@ import androidx.compose.runtime.LaunchedEffect
4950import androidx.compose.runtime.getValue
5051import androidx.compose.runtime.mutableStateOf
5152import androidx.compose.runtime.remember
53+ import androidx.compose.runtime.rememberCoroutineScope
5254import androidx.compose.runtime.setValue
5355import androidx.compose.ui.Alignment
5456import androidx.compose.ui.Modifier
@@ -77,6 +79,9 @@ import com.masterdns.vpn.ui.theme.MdvSpace
7779import com.masterdns.vpn.util.QrCodeUtil
7880import java.util.concurrent.Executors
7981import java.util.concurrent.atomic.AtomicBoolean
82+ import kotlinx.coroutines.Dispatchers
83+ import kotlinx.coroutines.launch
84+ import kotlinx.coroutines.withContext
8085
8186class ScannerActivity : ComponentActivity () {
8287
@@ -86,6 +91,7 @@ class ScannerActivity : ComponentActivity() {
8691
8792 override fun onCreate (savedInstanceState : Bundle ? ) {
8893 super .onCreate(savedInstanceState)
94+ enableEdgeToEdge()
8995 setContent {
9096 MasterDnsVPNTheme {
9197 ScannerScreen (
@@ -128,17 +134,22 @@ private fun ScannerScreen(
128134 var cameraControl by remember { mutableStateOf<CameraControl ?>(null ) }
129135 var hasTorch by remember { mutableStateOf(false ) }
130136 var torchEnabled by remember { mutableStateOf(false ) }
137+ val scope = rememberCoroutineScope()
131138
132139 val galleryLauncher = rememberLauncherForActivityResult(
133140 contract = ActivityResultContracts .GetContent ()
134141 ) { uri ->
135142 if (uri != null ) {
136- val decoded = QrCodeUtil .decodeFromUri(context, uri)
137- if (! decoded.isNullOrBlank()) {
138- onScanResult(decoded)
139- return @rememberLauncherForActivityResult
143+ scope.launch(Dispatchers .IO ) {
144+ val decoded = QrCodeUtil .decodeFromUri(context, uri)
145+ withContext(Dispatchers .Main ) {
146+ if (! decoded.isNullOrBlank()) {
147+ onScanResult(decoded)
148+ } else {
149+ Toast .makeText(context, context.getString(R .string.scanner_decoding_failed), Toast .LENGTH_SHORT ).show()
150+ }
151+ }
140152 }
141- Toast .makeText(context, context.getString(R .string.scanner_decoding_failed), Toast .LENGTH_SHORT ).show()
142153 }
143154 }
144155
@@ -168,10 +179,10 @@ private fun ScannerScreen(
168179 }
169180 },
170181 colors = TopAppBarDefaults .topAppBarColors(
171- containerColor = Color . Black .copy(alpha = 0.7f ) ,
172- titleContentColor = Color . White ,
173- navigationIconContentColor = Color . White ,
174- actionIconContentColor = Color . White
182+ containerColor = MdvColor . OverlayScrim ,
183+ titleContentColor = MdvColor . OnCameraBackdrop ,
184+ navigationIconContentColor = MdvColor . OnCameraBackdrop ,
185+ actionIconContentColor = MdvColor . OnCameraBackdrop
175186 )
176187 )
177188 }
@@ -180,7 +191,7 @@ private fun ScannerScreen(
180191 modifier = Modifier
181192 .fillMaxSize()
182193 .padding(innerPadding)
183- .background(Color . Black )
194+ .background(MdvColor . CameraBackdrop )
184195 ) {
185196 if (hasCameraPermission) {
186197 CameraPreviewView (
@@ -201,7 +212,7 @@ private fun ScannerScreen(
201212 ) {
202213 Text (
203214 text = stringResource(R .string.scanner_camera_permission_required),
204- color = Color . White ,
215+ color = MdvColor . OnCameraBackdrop ,
205216 style = MaterialTheme .typography.bodyLarge
206217 )
207218 Spacer (modifier = Modifier .height(MdvSpace .S3 ))
@@ -218,7 +229,7 @@ private fun ScannerScreen(
218229private fun ScannerOverlay () {
219230 val scanBoxSize = 260 .dp
220231 val cornerLength = 28 .dp
221- val cornerWidth = 4 .dp
232+ val cornerWidth = MdvSpace . S1
222233 val cornerColor = MdvColor .PrimaryContainer
223234
224235 Box (modifier = Modifier .fillMaxSize()) {
@@ -233,7 +244,7 @@ private fun ScannerOverlay() {
233244 val left = (canvasWidth - boxSizePx) / 2f
234245 val top = (canvasHeight - boxSizePx) / 2f
235246
236- drawRect(color = Color ( 0x99000000 ) )
247+ drawRect(color = MdvColor . OverlayScrim )
237248 drawRect(
238249 color = Color .Transparent ,
239250 topLeft = Offset (left, top),
@@ -272,7 +283,7 @@ private fun ScannerOverlay() {
272283
273284 Text (
274285 text = stringResource(R .string.scanner_hint),
275- color = Color . White ,
286+ color = MdvColor . OnCameraBackdrop ,
276287 style = MaterialTheme .typography.bodyMedium,
277288 modifier = Modifier
278289 .align(Alignment .Center )
0 commit comments