Make sure to handle a null ResultPoint correctly

Never trust ZXing to deliver a non-null object.
Also make sure to not use an empty array of ResultPoint's.
This commit is contained in:
Markus Fisch
2020-04-03 18:11:45 +02:00
parent aca97afc78
commit 3bba6cf10d
@@ -36,8 +36,12 @@ import kotlinx.coroutines.launch
@FlowPreview
class CameraActivity : AppCompatActivity() {
private val zxing = Zxing(ResultPointCallback { point ->
detectorView.post {
mapping?.map(point)?.let { detectorView.mark(listOf(it)) }
point?.let {
mapping?.map(it)?.let {
detectorView.post {
detectorView.mark(listOf(it))
}
}
}
})
@@ -289,7 +293,9 @@ class CameraActivity : AppCompatActivity() {
cameraView.post {
val rp = result.resultPoints
val m = mapping
if (m != null && rp != null) {
if (m != null && rp != null &&
rp.isNotEmpty()
) {
detectorView.mark(m.map(rp))
}
vibrator.vibrate()