Skip to content

Commit

Permalink
Improve Permission Handling and QR Code Import Logic in ScScannerActi…
Browse files Browse the repository at this point in the history
…vity (#3777)

Refactored permission request handling in ScScannerActivity to improve readability and simplify the flow. Improved QR code import logic to ensure better handling of the scanned result and enhance user feedback.
  • Loading branch information
CodeWithTamim authored Oct 25, 2024
1 parent c6758b1 commit ba54005
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScScannerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@ class ScScannerActivity : BaseActivity() {
fun importQRcode(): Boolean {
RxPermissions(this)
.request(Manifest.permission.CAMERA)
.subscribe {
if (it)
.subscribe { granted ->
if (granted) {
scanQRCode.launch(Intent(this, ScannerActivity::class.java))
else
} else {
toast(R.string.toast_permission_denied)
}
}

return true
}


private val scanQRCode = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == RESULT_OK) {
val (count, countSub) = AngConfigManager.importBatchConfig(it.data?.getStringExtra("SCAN_RESULT"), "", false)
val scanResult = it.data?.getStringExtra("SCAN_RESULT").orEmpty()
val (count, countSub) = AngConfigManager.importBatchConfig(scanResult, "", false)

if (count + countSub > 0) {
toast(R.string.toast_success)
} else {
toast(R.string.toast_failure)
}

startActivity(Intent(this, MainActivity::class.java))
}
finish()
}

}

0 comments on commit ba54005

Please sign in to comment.