mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
refactor: Small improvements for changeState in RecorderService
This commit is contained in:
parent
c38be920ec
commit
79b33ced2e
@ -91,6 +91,14 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun _changeStateValue(newState: RecorderState) {
|
||||||
|
state = newState
|
||||||
|
|
||||||
|
onStateChange?.invoke(newState)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used to change the state of the service
|
||||||
|
// will internally call start() / pause() / resume() / stop()
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun changeState(newState: RecorderState) {
|
fun changeState(newState: RecorderState) {
|
||||||
if (state == newState) {
|
if (state == newState) {
|
||||||
@ -106,27 +114,23 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
} else {
|
} else {
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createRecordingTimeTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
RecorderState.PAUSED -> {
|
RecorderState.PAUSED -> {
|
||||||
pause()
|
pause()
|
||||||
isPaused = true
|
isPaused = true
|
||||||
|
|
||||||
|
recordingTimeTimer.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
RecorderState.IDLE -> {
|
||||||
}
|
|
||||||
|
|
||||||
when (newState) {
|
|
||||||
RecorderState.RECORDING -> {
|
|
||||||
createRecordingTimeTimer()
|
|
||||||
}
|
|
||||||
|
|
||||||
RecorderState.PAUSED, RecorderState.IDLE -> {
|
|
||||||
recordingTimeTimer.shutdown()
|
recordingTimeTimer.shutdown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update notification
|
||||||
if (
|
if (
|
||||||
arrayOf(
|
arrayOf(
|
||||||
RecorderState.RECORDING,
|
RecorderState.RECORDING,
|
||||||
@ -140,7 +144,8 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
notification
|
notification
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onStateChange?.invoke(newState)
|
|
||||||
|
_changeStateValue(newState)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be immediately called after creating the service!
|
// Must be immediately called after creating the service!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user