Skip to content

Commit 98f9931

Browse files
committed
make strobo and SOS toggling more reliable
1 parent 704fa52 commit 98f9931

File tree

1 file changed

+17
-5
lines changed
  • app/src/main/kotlin/com/simplemobiletools/flashlight/helpers

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class MyCameraImpl(val context: Context) {
2525
private var params: Camera.Parameters? = null
2626
private var isMarshmallow = false
2727
private var shouldEnableFlashlight = false
28+
private var shouldEnableStroboscope = false
29+
private var shouldEnableSOS = false
2830
private var isStroboSOS = false // are we sending SOS, or casual stroboscope?
2931

3032
private var marshmallowCamera: MarshmallowCamera? = null
@@ -55,7 +57,7 @@ class MyCameraImpl(val context: Context) {
5557
fun toggleStroboscope(): Boolean {
5658
if (isSOSRunning) {
5759
stopSOS()
58-
toggleStroboscope()
60+
shouldEnableStroboscope = true
5961
return true
6062
}
6163

@@ -85,7 +87,7 @@ class MyCameraImpl(val context: Context) {
8587
fun toggleSOS(): Boolean {
8688
if (isStroboscopeRunning) {
8789
stopStroboscope()
88-
toggleSOS()
90+
shouldEnableSOS = true
8991
return true
9092
}
9193

@@ -324,9 +326,19 @@ class MyCameraImpl(val context: Context) {
324326
isStroboscopeRunning = false
325327
}
326328

327-
if (shouldEnableFlashlight) {
328-
enableFlashlight()
329-
shouldEnableFlashlight = false
329+
when {
330+
shouldEnableFlashlight -> {
331+
enableFlashlight()
332+
shouldEnableFlashlight = false
333+
}
334+
shouldEnableSOS -> {
335+
toggleSOS()
336+
shouldEnableSOS = false
337+
}
338+
shouldEnableStroboscope -> {
339+
toggleStroboscope()
340+
shouldEnableStroboscope = false
341+
}
330342
}
331343
}
332344
}

0 commit comments

Comments
 (0)