mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +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
|
recorder = newRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun pause() {
|
||||||
|
super.pause()
|
||||||
|
|
||||||
|
resetRecorder()
|
||||||
|
}
|
||||||
|
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
super.stop()
|
super.stop()
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ abstract class IntervalRecorderService: ExtraRecorderInformationService() {
|
|||||||
|
|
||||||
// Make overrideable
|
// Make overrideable
|
||||||
open fun startNewCycle() {
|
open fun startNewCycle() {
|
||||||
|
counter += 1
|
||||||
deleteOldRecordings()
|
deleteOldRecordings()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +90,11 @@ abstract class IntervalRecorderService: ExtraRecorderInformationService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun resume() {
|
override fun resume() {
|
||||||
super.resume()
|
|
||||||
createTimer()
|
createTimer()
|
||||||
|
|
||||||
|
// We first want to start our timers, so the `ExtraRecorderInformationService` can fetch
|
||||||
|
// amplitudes
|
||||||
|
super.resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
|
@ -21,10 +21,14 @@ import androidx.compose.foundation.layout.width
|
|||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Delete
|
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.material.icons.filled.Save
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.FloatingActionButton
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.LargeFloatingActionButton
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@ -99,8 +103,6 @@ fun RecordingStatus(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
) {
|
) {
|
||||||
val distance = Duration.between(audioRecorder.recorderService!!.recordingStart, now).toMillis()
|
|
||||||
|
|
||||||
Pulsating {
|
Pulsating {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -111,7 +113,7 @@ fun RecordingStatus(
|
|||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
Text(
|
Text(
|
||||||
text = formatDuration(distance),
|
text = formatDuration(audioRecorder.recordingTime!!),
|
||||||
style = MaterialTheme.typography.headlineLarge,
|
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 alpha by animateFloatAsState(if (progressVisible) 1f else 0f, tween(1000))
|
||||||
val label = stringResource(R.string.ui_audioRecorder_action_save_label)
|
val label = stringResource(R.string.ui_audioRecorder_action_save_label)
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ class AudioRecorderModel: ViewModel() {
|
|||||||
val isInRecording: Boolean
|
val isInRecording: Boolean
|
||||||
get() = recorderState !== RecorderState.IDLE && recordingTime != null
|
get() = recorderState !== RecorderState.IDLE && recordingTime != null
|
||||||
|
|
||||||
|
val isPaused: Boolean
|
||||||
|
get() = recorderState === RecorderState.PAUSED
|
||||||
|
|
||||||
val progress: Float
|
val progress: Float
|
||||||
get() = (recordingTime!! / recorderService!!.settings!!.maxDuration).toFloat()
|
get() = (recordingTime!! / recorderService!!.settings!!.maxDuration).toFloat()
|
||||||
|
|
||||||
@ -96,6 +99,14 @@ class AudioRecorderModel: ViewModel() {
|
|||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun pauseRecording() {
|
||||||
|
recorderService!!.changeState(RecorderState.PAUSED)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resumeRecording() {
|
||||||
|
recorderService!!.changeState(RecorderState.RECORDING)
|
||||||
|
}
|
||||||
|
|
||||||
fun setMaxAmplitudesAmount(amount: Int) {
|
fun setMaxAmplitudesAmount(amount: Int) {
|
||||||
recorderService?.amplitudesAmount = amount
|
recorderService?.amplitudesAmount = amount
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
<string name="ui_audioRecorder_action_delete_label">Delete</string>
|
<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_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_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_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_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>
|
<string name="ui_audioRecorder_action_save_processing_dialog_title">Processing</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user