Skip to content

Commit bd1c986

Browse files
committed
fix(scanner): offload gallery decode to io dispatcher, add edgetoedge, and polish dialog tokens
1 parent a9c3fc9 commit bd1c986

4 files changed

Lines changed: 41 additions & 26 deletions

File tree

‎android/app/src/main/java/com/masterdns/vpn/ui/profiles/ProfilesScreen.kt‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,17 +1510,17 @@ private fun SubscriptionQrDialog(
15101510
}
15111511
},
15121512
confirmButton = {
1513-
Row(horizontalArrangement = Arrangement.spacedBy(MdvSpace.S2)) {
1514-
TextButton(onClick = {
1515-
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
1516-
clipboard.setPrimaryClip(ClipData.newPlainText(subscription.name, subscription.url))
1517-
Toast.makeText(context, context.getString(R.string.profiles_share_copied), Toast.LENGTH_SHORT).show()
1518-
}) {
1519-
Text(stringResource(R.string.btn_copy))
1520-
}
1521-
TextButton(onClick = onDismiss) {
1522-
Text(stringResource(R.string.action_close))
1523-
}
1513+
TextButton(onClick = {
1514+
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
1515+
clipboard.setPrimaryClip(ClipData.newPlainText(subscription.name, subscription.url))
1516+
Toast.makeText(context, context.getString(R.string.profiles_share_copied), Toast.LENGTH_SHORT).show()
1517+
}) {
1518+
Text(stringResource(R.string.btn_copy))
1519+
}
1520+
},
1521+
dismissButton = {
1522+
TextButton(onClick = onDismiss) {
1523+
Text(stringResource(R.string.action_close))
15241524
}
15251525
}
15261526
)

‎android/app/src/main/java/com/masterdns/vpn/ui/scanner/ScannerActivity.kt‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.widget.Toast
99
import androidx.activity.ComponentActivity
1010
import androidx.activity.compose.rememberLauncherForActivityResult
1111
import androidx.activity.compose.setContent
12+
import androidx.activity.enableEdgeToEdge
1213
import androidx.activity.result.contract.ActivityResultContracts
1314
import androidx.camera.core.CameraControl
1415
import androidx.camera.core.CameraInfo
@@ -49,6 +50,7 @@ import androidx.compose.runtime.LaunchedEffect
4950
import androidx.compose.runtime.getValue
5051
import androidx.compose.runtime.mutableStateOf
5152
import androidx.compose.runtime.remember
53+
import androidx.compose.runtime.rememberCoroutineScope
5254
import androidx.compose.runtime.setValue
5355
import androidx.compose.ui.Alignment
5456
import androidx.compose.ui.Modifier
@@ -77,6 +79,9 @@ import com.masterdns.vpn.ui.theme.MdvSpace
7779
import com.masterdns.vpn.util.QrCodeUtil
7880
import java.util.concurrent.Executors
7981
import java.util.concurrent.atomic.AtomicBoolean
82+
import kotlinx.coroutines.Dispatchers
83+
import kotlinx.coroutines.launch
84+
import kotlinx.coroutines.withContext
8085

8186
class 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(
218229
private 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)

‎android/app/src/main/java/com/masterdns/vpn/ui/theme/MdvTokens.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ object MdvColor {
3131
val OnError = Color(0xFF690005)
3232

3333
val QrBackground = Color(0xFFFFFFFF)
34+
val OverlayScrim = Color(0x99000000)
35+
val CameraBackdrop = Color(0xFF000000)
36+
val OnCameraBackdrop = Color(0xFFFFFFFF)
3437
}
3538

3639
object MdvSpace {

‎android/app/src/main/java/com/masterdns/vpn/util/QrCodeUtil.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ object QrCodeUtil {
9393
context.contentResolver.openInputStream(uri)?.use { stream ->
9494
BitmapFactory.decodeStream(stream, null, options)
9595
}
96-
val sampleSize = maxOf(1, options.outHeight / 600)
96+
val maxDimension = maxOf(options.outWidth, options.outHeight)
97+
val sampleSize = maxOf(1, maxDimension / 600)
9798
val decodeOptions = BitmapFactory.Options().apply { inSampleSize = sampleSize }
9899
val bitmap = context.contentResolver.openInputStream(uri)?.use { stream ->
99100
BitmapFactory.decodeStream(stream, null, decodeOptions)

0 commit comments

Comments
 (0)