add qr scanner for creator app and android app

This commit is contained in:
kulikov0 committed 2026-07-26 22:33:34 +02:00
1 parent 2bad03c542
commit be69b94560
18 files changed
+397 -15

No files matched your search

@@ -33,6 +33,12 @@ class AddDestinationSheet : BottomSheetDialogFragment() {
val buttonCancel = view.findViewById<Button>(R.id.buttonCancel)
val buttonSave = view.findViewById<Button>(R.id.buttonSave)
val prefillLink = arguments?.getString(ARG_PREFILL_LINK).orEmpty()
if (prefillLink.isNotEmpty()) {
inputLink.setText(prefillLink)
inputName.setText(CallConfig.suggestNameFor(prefillLink))
}
pasteChip.setOnClickListener {
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = clipboard.primaryClip
@@ -80,8 +86,14 @@ class AddDestinationSheet : BottomSheetDialogFragment() {
companion object {
const val TAG = "AddDestinationSheet"
fun show(manager: FragmentManager) {
AddDestinationSheet().show(manager, TAG)
private const val ARG_PREFILL_LINK = "prefill_link"
fun show(manager: FragmentManager, prefillLink: String = "") {
val sheet = AddDestinationSheet()
if (prefillLink.isNotEmpty()) {
sheet.arguments = Bundle().apply { putString(ARG_PREFILL_LINK, prefillLink) }
}
sheet.show(manager, TAG)
}
}
}
@@ -11,9 +11,18 @@ import bypass.whitelist.tunnel.CallPlatform
import bypass.whitelist.tunnel.TunnelMode
import bypass.whitelist.tunnel.VpnStatus
import bypass.whitelist.util.Prefs
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
class MainFragment : Fragment(R.layout.fragment_main_screen) {
private val scanQrLauncher = registerForActivityResult(ScanContract()) { result ->
val scanned = result.contents?.trim().orEmpty()
if (scanned.isNotEmpty()) {
AddDestinationSheet.show(parentFragmentManager, scanned)
}
}
private var content: MainFragmentView? = null
private var pendingStatus: VpnStatus? = null
private var connectedSinceMs: Long = 0L
@@ -44,6 +53,16 @@ class MainFragment : Fragment(R.layout.fragment_main_screen) {
container.onAddCallClicked = {
AddDestinationSheet.show(parentFragmentManager)
}
container.onScanQrClicked = {
scanQrLauncher.launch(
ScanOptions()
.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
.setPrompt(getString(R.string.scan_qr_prompt))
.setBeepEnabled(false)
.setOrientationLocked(false)
.setCaptureActivity(QrCaptureActivity::class.java)
)
}
container.onHeroPressed = {
if (isHostConnected() || isHostConnecting()) {
host()?.onDisconnectPressed()
@@ -21,6 +21,7 @@ class MainFragmentView(private val root: View) {
private val headerSub: TextView = root.findViewById(R.id.headerSub)
private val addButton: View = root.findViewById(R.id.headerAddButton)
private val scanButton: View = root.findViewById(R.id.headerScanButton)
private val hero: View = root.findViewById(R.id.heroButton)
private val heroLabel: TextView = root.findViewById(R.id.heroLabel)
private val heroPowerIcon: ImageView = root.findViewById(R.id.heroPowerIcon)
@@ -43,6 +44,7 @@ class MainFragmentView(private val root: View) {
private val statMode: TextView = root.findViewById(R.id.statMode)
var onAddCallClicked: Callback? = null
var onScanQrClicked: Callback? = null
var onHeroPressed: Callback? = null
var onPingPressed: Callback? = null
var onCallSelected: ParamCallback<CallConfig>? = null
@@ -58,6 +60,7 @@ class MainFragmentView(private val root: View) {
emptyCta.clipToOutline = true
pingButton.clipToOutline = true
addButton.setOnClickListener { onAddCallClicked?.invoke() }
scanButton.setOnClickListener { onScanQrClicked?.invoke() }
emptyCta.setOnClickListener { onAddCallClicked?.invoke() }
hero.setOnTouchListener { v, event ->
when (event.action) {
@@ -0,0 +1,5 @@
package bypass.whitelist.ui
import com.journeyapps.barcodescanner.CaptureActivity
class QrCaptureActivity : CaptureActivity()