|
|
@ -96,7 +96,7 @@ class QrReaderActivity : AppCompatActivity() { |
|
|
|
builder.setPositiveButton(getString(R.string.ok)) { dialog, which -> |
|
|
|
run { |
|
|
|
val txt = input.text.toString() |
|
|
|
processText(txt) |
|
|
|
processQrCodeText(txt) |
|
|
|
} |
|
|
|
} |
|
|
|
builder.setNegativeButton(getString(R.string.cancel)) { dialog, which -> dialog.cancel() } |
|
|
@ -123,13 +123,13 @@ class QrReaderActivity : AppCompatActivity() { |
|
|
|
captureManager.onDestroy() |
|
|
|
} |
|
|
|
|
|
|
|
private fun processText(barcodeInfo: String) { |
|
|
|
private fun processQrCodeText(qrcodeInfo: String) { |
|
|
|
val code = intent.getIntExtra("REQUEST_CODE", 0) |
|
|
|
|
|
|
|
// See if this the data is of the right format |
|
|
|
if (code == REQUEST_CONNDATA && !barcodeInfo.startsWith("ws")) { |
|
|
|
// Check if data is websocket connection |
|
|
|
if (code == REQUEST_CONNDATA && !qrcodeInfo.startsWith("ws")) { |
|
|
|
Log.i(TAG, "Not a connection") |
|
|
|
var err = barcodeInfo |
|
|
|
var err = qrcodeInfo |
|
|
|
if (err.length > 48) { |
|
|
|
err = err.substring(0, 22) + "...." + err.substring(err.length - 22, err.length) |
|
|
|
} |
|
|
@ -137,11 +137,12 @@ class QrReaderActivity : AppCompatActivity() { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// Check if data is valid hush z-address |
|
|
|
if (code == REQUEST_ADDRESS && |
|
|
|
!DataModel.isValidAddress(StringBuilder(barcodeInfo).toString()) && |
|
|
|
!barcodeInfo.startsWith("hush:")) { |
|
|
|
!DataModel.isValidAddress(StringBuilder(qrcodeInfo).toString()) && |
|
|
|
!qrcodeInfo.startsWith("hush:")) { |
|
|
|
Log.i(TAG, "Not an address") |
|
|
|
var err = barcodeInfo |
|
|
|
var err = qrcodeInfo |
|
|
|
if (err.length > 48) { |
|
|
|
err = err.substring(0, 22) + "...." + err.substring(err.length - 22, err.length) |
|
|
|
} |
|
|
@ -149,37 +150,20 @@ class QrReaderActivity : AppCompatActivity() { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// The data seems valid, so return it. |
|
|
|
// The data seems valid, so return it |
|
|
|
val data = Intent() |
|
|
|
|
|
|
|
// Payment URIs are often formatted as "hush:<addr>", but this causes parsing problems. |
|
|
|
// So change it to hush://<addr>, so that it parses properly |
|
|
|
if (barcodeInfo.startsWith("hush:") && !barcodeInfo.startsWith("hush://")) { |
|
|
|
data.data = Uri.parse(barcodeInfo.replaceFirst("hush:", "hush://")) |
|
|
|
if (qrcodeInfo.startsWith("hush:") && !qrcodeInfo.startsWith("hush://")) { |
|
|
|
data.data = Uri.parse(qrcodeInfo.replaceFirst("hush:", "hush://")) |
|
|
|
} else { |
|
|
|
data.data = Uri.parse(barcodeInfo) |
|
|
|
data.data = Uri.parse(qrcodeInfo) |
|
|
|
} |
|
|
|
|
|
|
|
setResult(Activity.RESULT_OK, data) |
|
|
|
finish() |
|
|
|
} |
|
|
|
|
|
|
|
private fun processQrCodeText(qrcodeInfo: String) { |
|
|
|
if (qrcodeInfo.startsWith("ws")) { |
|
|
|
Log.i(TAG, "It's a ws connection") |
|
|
|
//Toast.makeText(this, "YEAH: " + qrcodeInfo, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
|
|
val data = Intent() // The data seems valid, so return it |
|
|
|
data.data = Uri.parse(qrcodeInfo) |
|
|
|
setResult(Activity.RESULT_OK, data) |
|
|
|
finish() |
|
|
|
} else { |
|
|
|
Log.i(TAG, "Not a ws connection") |
|
|
|
//Toast.makeText(this, "Not a ws connection", Toast.LENGTH_SHORT).show(); |
|
|
|
setResult(Activity.RESULT_CANCELED) |
|
|
|
finish() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private val TAG = "QrReader" |
|
|
|
} |
|
|
|