mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Add pause / resume functionality
This commit is contained in:
parent
d125ed79d5
commit
0e6eff9f85
@ -49,6 +49,12 @@ class AudioRecorderService: IntervalRecorderService() {
|
||||
recorder = newRecorder
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
super.pause()
|
||||
|
||||
resetRecorder()
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
super.stop()
|
||||
|
||||
|
@ -43,6 +43,7 @@ abstract class IntervalRecorderService: ExtraRecorderInformationService() {
|
||||
|
||||
// Make overrideable
|
||||
open fun startNewCycle() {
|
||||
counter += 1
|
||||
deleteOldRecordings()
|
||||
}
|
||||
|
||||
@ -89,8 +90,11 @@ abstract class IntervalRecorderService: ExtraRecorderInformationService() {
|
||||
}
|
||||
|
||||
override fun resume() {
|
||||
super.resume()
|
||||
createTimer()
|
||||
|
||||
// We first want to start our timers, so the `ExtraRecorderInformationService` can fetch
|
||||
// amplitudes
|
||||
super.resume()
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
|
@ -21,10 +21,14 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Pause
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Save
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@ -99,8 +103,6 @@ fun RecordingStatus(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
) {
|
||||
val distance = Duration.between(audioRecorder.recorderService!!.recordingStart, now).toMillis()
|
||||
|
||||
Pulsating {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
@ -111,7 +113,7 @@ fun RecordingStatus(
|
||||
}
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Text(
|
||||
text = formatDuration(distance),
|
||||
text = formatDuration(audioRecorder.recordingTime!!),
|
||||
style = MaterialTheme.typography.headlineLarge,
|
||||
)
|
||||
}
|
||||
@ -164,6 +166,27 @@ fun RecordingStatus(
|
||||
}
|
||||
}
|
||||
|
||||
val pauseLabel = stringResource(R.string.ui_audioRecorder_action_pause_label)
|
||||
val resumeLabel = stringResource(R.string.ui_audioRecorder_action_resume_label)
|
||||
LargeFloatingActionButton(
|
||||
modifier = Modifier
|
||||
.semantics {
|
||||
contentDescription = if (audioRecorder.isPaused) resumeLabel else pauseLabel
|
||||
},
|
||||
onClick = {
|
||||
if (audioRecorder.isPaused) {
|
||||
audioRecorder.resumeRecording()
|
||||
} else {
|
||||
audioRecorder.pauseRecording()
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
if (audioRecorder.isPaused) Icons.Default.PlayArrow else Icons.Default.Pause,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
|
||||
val alpha by animateFloatAsState(if (progressVisible) 1f else 0f, tween(1000))
|
||||
val label = stringResource(R.string.ui_audioRecorder_action_save_label)
|
||||
|
||||
|
@ -30,6 +30,9 @@ class AudioRecorderModel: ViewModel() {
|
||||
val isInRecording: Boolean
|
||||
get() = recorderState !== RecorderState.IDLE && recordingTime != null
|
||||
|
||||
val isPaused: Boolean
|
||||
get() = recorderState === RecorderState.PAUSED
|
||||
|
||||
val progress: Float
|
||||
get() = (recordingTime!! / recorderService!!.settings!!.maxDuration).toFloat()
|
||||
|
||||
@ -96,6 +99,14 @@ class AudioRecorderModel: ViewModel() {
|
||||
reset()
|
||||
}
|
||||
|
||||
fun pauseRecording() {
|
||||
recorderService!!.changeState(RecorderState.PAUSED)
|
||||
}
|
||||
|
||||
fun resumeRecording() {
|
||||
recorderService!!.changeState(RecorderState.RECORDING)
|
||||
}
|
||||
|
||||
fun setMaxAmplitudesAmount(amount: Int) {
|
||||
recorderService?.amplitudesAmount = amount
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
<string name="ui_audioRecorder_action_delete_label">Delete</string>
|
||||
<string name="ui_audioRecorder_action_delete_confirm_title">Delete Recording?</string>
|
||||
<string name="ui_audioRecorder_action_delete_confirm_message">Are you sure you want to delete this recording?</string>
|
||||
<string name="ui_audioRecorder_action_pause_label">Pause Recording</string>
|
||||
<string name="ui_audioRecorder_action_resume_label">Resume Recording</string>
|
||||
<string name="ui_audioRecorder_action_save_label">Save Recording</string>
|
||||
<string name="ui_audioRecorder_action_start_description">Alibi will continue recording in the background and store the last <xliff:g name="durationInMinutes">%s</xliff:g> minutes at your request</string>
|
||||
<string name="ui_audioRecorder_action_save_processing_dialog_title">Processing</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user