add a camera initialization to SOS too

This commit is contained in:
tibbi 2019-08-22 16:33:57 +02:00
parent 1f1f55e8e7
commit d59db59dd4
1 changed files with 20 additions and 9 deletions

View File

@ -59,15 +59,8 @@ class MyCameraImpl(val context: Context) {
disableFlashlight() disableFlashlight()
} }
if (!isNougatPlus()) { if (!tryInitCamera()) {
if (camera == null) { return false
initCamera()
}
if (camera == null) {
context.toast(R.string.camera_error)
return false
}
} }
if (isStroboscopeRunning) { if (isStroboscopeRunning) {
@ -88,6 +81,10 @@ class MyCameraImpl(val context: Context) {
stopStroboscope() stopStroboscope()
} }
if (!tryInitCamera()) {
return false
}
if (isFlashlightOn) { if (isFlashlightOn) {
disableFlashlight() disableFlashlight()
} }
@ -101,6 +98,20 @@ class MyCameraImpl(val context: Context) {
bus!!.post(Events.StopSOS()) bus!!.post(Events.StopSOS())
} }
private fun tryInitCamera(): Boolean {
if (!isNougatPlus()) {
if (camera == null) {
initCamera()
}
if (camera == null) {
context.toast(R.string.camera_error)
return false
}
}
return true
}
fun handleCameraSetup() { fun handleCameraSetup() {
if (isMarshmallow) { if (isMarshmallow) {
setupMarshmallowCamera() setupMarshmallowCamera()