Skip to content

Commit d59db59

Browse files
committed
add a camera initialization to SOS too
1 parent 1f1f55e commit d59db59

File tree

1 file changed

+20
-9
lines changed
  • app/src/main/kotlin/com/simplemobiletools/flashlight/helpers

1 file changed

+20
-9
lines changed

app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,8 @@ class MyCameraImpl(val context: Context) {
5959
disableFlashlight()
6060
}
6161

62-
if (!isNougatPlus()) {
63-
if (camera == null) {
64-
initCamera()
65-
}
66-
67-
if (camera == null) {
68-
context.toast(R.string.camera_error)
69-
return false
70-
}
62+
if (!tryInitCamera()) {
63+
return false
7164
}
7265

7366
if (isStroboscopeRunning) {
@@ -88,6 +81,10 @@ class MyCameraImpl(val context: Context) {
8881
stopStroboscope()
8982
}
9083

84+
if (!tryInitCamera()) {
85+
return false
86+
}
87+
9188
if (isFlashlightOn) {
9289
disableFlashlight()
9390
}
@@ -101,6 +98,20 @@ class MyCameraImpl(val context: Context) {
10198
bus!!.post(Events.StopSOS())
10299
}
103100

101+
private fun tryInitCamera(): Boolean {
102+
if (!isNougatPlus()) {
103+
if (camera == null) {
104+
initCamera()
105+
}
106+
107+
if (camera == null) {
108+
context.toast(R.string.camera_error)
109+
return false
110+
}
111+
}
112+
return true
113+
}
114+
104115
fun handleCameraSetup() {
105116
if (isMarshmallow) {
106117
setupMarshmallowCamera()

0 commit comments

Comments
 (0)