mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
fix: Set state after action to avoid coroutine going out of scope
This commit is contained in:
parent
d79aabab50
commit
df78952cfb
@ -32,6 +32,9 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
var state = RecorderState.IDLE
|
var state = RecorderState.IDLE
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
protected var _newState = RecorderState.IDLE
|
||||||
|
private set
|
||||||
|
|
||||||
var onStateChange: ((RecorderState) -> Unit)? = null
|
var onStateChange: ((RecorderState) -> Unit)? = null
|
||||||
var onError: () -> Unit = {}
|
var onError: () -> Unit = {}
|
||||||
|
|
||||||
@ -168,8 +171,9 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun stopRecording() {
|
suspend fun stopRecording() {
|
||||||
changeState(RecorderState.IDLE)
|
_newState = RecorderState.IDLE
|
||||||
stop()
|
stop()
|
||||||
|
changeState(RecorderState.IDLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -105,11 +105,11 @@ class VideoRecorderService :
|
|||||||
super.startNewCycle()
|
super.startNewCycle()
|
||||||
|
|
||||||
fun action() {
|
fun action() {
|
||||||
activeRecording?.stop()
|
stopActiveRecording()
|
||||||
val newRecording = prepareVideoRecording()
|
val newRecording = prepareVideoRecording()
|
||||||
|
|
||||||
activeRecording = newRecording.start(ContextCompat.getMainExecutor(this)) { event ->
|
activeRecording = newRecording.start(ContextCompat.getMainExecutor(this)) { event ->
|
||||||
if (event is VideoRecordEvent.Finalize && this@VideoRecorderService.state == RecorderState.IDLE) {
|
if (event is VideoRecordEvent.Finalize && this@VideoRecorderService._newState == RecorderState.IDLE) {
|
||||||
_videoFinalizerListener.complete(Unit)
|
_videoFinalizerListener.complete(Unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,8 +197,10 @@ class VideoRecorderService :
|
|||||||
// `resume` override not needed as `startNewCycle` is called by `IntervalRecorderService`
|
// `resume` override not needed as `startNewCycle` is called by `IntervalRecorderService`
|
||||||
|
|
||||||
private fun stopActiveRecording() {
|
private fun stopActiveRecording() {
|
||||||
|
runCatching {
|
||||||
activeRecording?.stop()
|
activeRecording?.stop()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun prepareVideoRecording() =
|
private fun prepareVideoRecording() =
|
||||||
|
@ -136,7 +136,7 @@ abstract class BaseRecorderModel<S : IntervalRecorderService.Settings, I, T : In
|
|||||||
|
|
||||||
val intent = Intent(context, intentClass)
|
val intent = Intent(context, intentClass)
|
||||||
|
|
||||||
context.unbindService(connection)
|
unbindFromService(context)
|
||||||
context.stopService(intent)
|
context.stopService(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user