mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 19:00:26 +01:00
Add force legacy QR scanning switch.
This commit is contained in:
@@ -8,6 +8,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.subjects.PublishSubject
|
||||
import org.signal.core.util.logging.Log
|
||||
|
||||
/**
|
||||
* View for starting up a camera and scanning a QR-Code. Safe to use on an API version and
|
||||
@@ -19,15 +20,15 @@ class QrScannerView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : FrameLayout(context, attrs, defStyleAttr), ScannerView {
|
||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private val scannerView: ScannerView
|
||||
private var scannerView: ScannerView? = null
|
||||
private val qrDataPublish: PublishSubject<String> = PublishSubject.create()
|
||||
|
||||
val qrData: Observable<String> = qrDataPublish
|
||||
|
||||
init {
|
||||
val scannerView: FrameLayout = if (Build.VERSION.SDK_INT >= 21) {
|
||||
private fun initScannerView(forceLegacy: Boolean) {
|
||||
val scannerView: FrameLayout = if (Build.VERSION.SDK_INT >= 21 && !forceLegacy) {
|
||||
ScannerView21(context) { qrDataPublish.onNext(it) }
|
||||
} else {
|
||||
ScannerView19(context) { qrDataPublish.onNext(it) }
|
||||
@@ -39,12 +40,23 @@ class QrScannerView @JvmOverloads constructor(
|
||||
this.scannerView = (scannerView as ScannerView)
|
||||
}
|
||||
|
||||
override fun start(lifecycleOwner: LifecycleOwner) {
|
||||
scannerView.start(lifecycleOwner)
|
||||
fun start(lifecycleOwner: LifecycleOwner, forceLegacy: Boolean = false) {
|
||||
if (scannerView != null) {
|
||||
Log.w(TAG, "Attempt to start scanning that has already started")
|
||||
return
|
||||
}
|
||||
|
||||
initScannerView(forceLegacy)
|
||||
|
||||
scannerView?.start(lifecycleOwner)
|
||||
lifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
qrDataPublish.onComplete()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(QrScannerView::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user