simplifying the stroboscope handling

This commit is contained in:
tibbi 2019-08-23 22:43:47 +02:00
parent 353fb14af3
commit c3d00cd536
1 changed files with 6 additions and 13 deletions

View File

@ -33,8 +33,6 @@ class MyCameraImpl(val context: Context) {
@Volatile @Volatile
private var isStroboscopeRunning = false private var isStroboscopeRunning = false
@Volatile @Volatile
private var shouldSOSStop = false
@Volatile
private var isSOSRunning = false private var isSOSRunning = false
fun newInstance(context: Context) = MyCameraImpl(context) fun newInstance(context: Context) = MyCameraImpl(context)
@ -95,17 +93,17 @@ class MyCameraImpl(val context: Context) {
disableFlashlight() disableFlashlight()
} }
if (isSOSRunning) { return if (isSOSRunning) {
stopSOS() stopSOS()
false
} else { } else {
isSOSRunning = true
Thread(stroboscope).start() Thread(stroboscope).start()
true
} }
return isSOSRunning
} }
fun stopSOS() { fun stopSOS() {
shouldSOSStop = true shouldStroboscopeStop = true
bus!!.post(Events.StopSOS()) bus!!.post(Events.StopSOS())
} }
@ -172,7 +170,6 @@ class MyCameraImpl(val context: Context) {
fun enableFlashlight() { fun enableFlashlight() {
shouldStroboscopeStop = true shouldStroboscopeStop = true
shouldSOSStop = true
if (isStroboscopeRunning || isSOSRunning) { if (isStroboscopeRunning || isSOSRunning) {
shouldEnableFlashlight = true shouldEnableFlashlight = true
return return
@ -234,7 +231,6 @@ class MyCameraImpl(val context: Context) {
bus?.unregister(this) bus?.unregister(this)
isFlashlightOn = false isFlashlightOn = false
shouldStroboscopeStop = true shouldStroboscopeStop = true
shouldSOSStop = true
} }
private val stroboscope = Runnable { private val stroboscope = Runnable {
@ -242,11 +238,10 @@ class MyCameraImpl(val context: Context) {
return@Runnable return@Runnable
} }
shouldStroboscopeStop = false
if (isStroboSOS) { if (isStroboSOS) {
shouldSOSStop = false
isSOSRunning = true isSOSRunning = true
} else { } else {
shouldStroboscopeStop = false
isStroboscopeRunning = true isStroboscopeRunning = true
} }
@ -259,7 +254,6 @@ class MyCameraImpl(val context: Context) {
Thread.sleep(stroboFrequency) Thread.sleep(stroboFrequency)
} catch (e: Exception) { } catch (e: Exception) {
shouldStroboscopeStop = true shouldStroboscopeStop = true
shouldSOSStop = true
} }
} }
} else { } else {
@ -302,11 +296,10 @@ class MyCameraImpl(val context: Context) {
} }
} }
shouldStroboscopeStop = false
if (isStroboSOS) { if (isStroboSOS) {
shouldSOSStop = false
isSOSRunning = false isSOSRunning = false
} else { } else {
shouldStroboscopeStop = false
isStroboscopeRunning = false isStroboscopeRunning = false
} }