package com.bitcointxoko.gudariwallet.util import android.content.Context import android.content.Intent import android.net.Uri object IntentUtils { private val PAYMENT_SCHEMES = setOf( "lightning", "bitcoin", "lnurlp", "lnurlw", "lnurlc", "lnurl" ) fun shareText(context: Context, text: String, chooserTitle: String) { val intent = Intent(Intent.ACTION_SEND).apply { type = "text/plain" putExtra(Intent.EXTRA_TEXT, text) } context.startActivity(Intent.createChooser(intent, chooserTitle)) } /** * Returns a raw payment URI string if the intent carries one, else null. * * Handles: * - ACTION_VIEW with a recognised scheme (BTCPay "Pay in wallet", browser links) * - ACTION_SEND with text/plain (share sheet from another app) */ fun extractPaymentUri(intent: Intent?): String? { if (intent == null) return null // Case 1: direct URI intent (most common — BTCPay, wallet links) if (intent.action == Intent.ACTION_VIEW) { val uri: Uri? = intent.data if (uri != null && uri.scheme?.lowercase() in PAYMENT_SCHEMES) { return uri.toString() } } // Case 2: share-sheet text (e.g. another app shares a BOLT-11 string) if (intent.action == Intent.ACTION_SEND && intent.type == "text/plain") { val text = intent.getStringExtra(Intent.EXTRA_TEXT)?.trim() if (!text.isNullOrBlank()) return text } return null } }