Skip to content

Commit ab5898a

Browse files
committed
review: import before finishing on live scan; torch a11y default in layout
- Live scan now awaits importText() and then finish()es on the main thread, so importedN is populated before onDestroy() reads it (previously finished first, making the toast report '0 profile(s)'). - Layout torch FAB default contentDescription is now scan_torch_turn_on (matches the stateful runtime updates).
1 parent 1802556 commit ab5898a

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

app/src/main/java/io/nekohasekai/sagernet/ui/ScannerActivity.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ class ScannerActivity : ThemedActivity() {
152152
.addOnSuccessListener { barcodes ->
153153
val text = barcodes.firstOrNull { !it.rawValue.isNullOrBlank() }?.rawValue
154154
if (text != null && !finished.getAndSet(true)) {
155-
// First successful scan wins: finish the activity and import in the
156-
// background (the activity-scoped toast in onDestroy reports the count).
157-
finish()
158-
runOnDefaultDispatcher { importText(text) }
155+
// First successful scan wins. Import first, then finish on the main
156+
// thread, so importedN is populated before onDestroy() reads it for
157+
// the "N profile(s)" toast (finishing first raced the background import).
158+
runOnDefaultDispatcher {
159+
importText(text)
160+
onMainDispatcher { finish() }
161+
}
159162
}
160163
}
161164
.addOnFailureListener { Logs.w(it) }

app/src/main/res/layout/layout_scanner.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
android:layout_height="wrap_content"
4141
android:layout_gravity="center_horizontal|bottom"
4242
android:layout_marginBottom="48dp"
43-
android:contentDescription="@string/scan_toggle_torch"
43+
android:contentDescription="@string/scan_torch_turn_on"
4444
android:src="@drawable/ic_baseline_flash_off_24"
4545
app:fabSize="normal" />
4646

0 commit comments

Comments
 (0)