From d59db59dd49b27a6d92a5fdf180d2f7daa13e6e2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 22 Aug 2019 16:33:57 +0200 Subject: [PATCH] add a camera initialization to SOS too --- .../flashlight/helpers/MyCameraImpl.kt | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt index 1df88bb..b62a251 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt @@ -59,15 +59,8 @@ class MyCameraImpl(val context: Context) { disableFlashlight() } - if (!isNougatPlus()) { - if (camera == null) { - initCamera() - } - - if (camera == null) { - context.toast(R.string.camera_error) - return false - } + if (!tryInitCamera()) { + return false } if (isStroboscopeRunning) { @@ -88,6 +81,10 @@ class MyCameraImpl(val context: Context) { stopStroboscope() } + if (!tryInitCamera()) { + return false + } + if (isFlashlightOn) { disableFlashlight() } @@ -101,6 +98,20 @@ class MyCameraImpl(val context: Context) { 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() { if (isMarshmallow) { setupMarshmallowCamera()