mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Add automatic recording functionality on boot
This commit is contained in:
parent
2e9f1c7ade
commit
a0bf2d03eb
@ -47,6 +47,7 @@
|
||||
</receiver>
|
||||
<service
|
||||
android:name=".services.AudioRecorderService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="microphone" />
|
||||
|
||||
<!-- Change locale for Android <= 12 -->
|
||||
|
@ -19,7 +19,7 @@ data class AppSettings(
|
||||
val showAdvancedSettings: Boolean = false,
|
||||
val theme: Theme = Theme.SYSTEM,
|
||||
val lastRecording: RecordingInformation? = null,
|
||||
val bootBehavior: BootBehavior? = BootBehavior.SHOW_NOTIFICATION,
|
||||
val bootBehavior: BootBehavior? = BootBehavior.START_RECORDING,
|
||||
) {
|
||||
fun setShowAdvancedSettings(showAdvancedSettings: Boolean): AppSettings {
|
||||
return copy(showAdvancedSettings = showAdvancedSettings)
|
||||
|
@ -45,8 +45,15 @@ class BootReceiver : BroadcastReceiver() {
|
||||
}
|
||||
}
|
||||
|
||||
println("BootReceiver.startRecording()")
|
||||
val intent = Intent(context, AudioRecorderService::class.java).apply {
|
||||
action = "init"
|
||||
|
||||
putExtra(
|
||||
"startImmediately",
|
||||
true,
|
||||
)
|
||||
|
||||
if (settings.notificationSettings != null) {
|
||||
putExtra(
|
||||
"notificationDetails",
|
||||
@ -61,7 +68,6 @@ class BootReceiver : BroadcastReceiver() {
|
||||
}
|
||||
}
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
context.bindService(intent, connection, 0)
|
||||
}
|
||||
|
||||
private fun showNotification(context: Context) {
|
||||
@ -98,8 +104,11 @@ class BootReceiver : BroadcastReceiver() {
|
||||
return
|
||||
}
|
||||
|
||||
println("BootReceiver.onReceive()")
|
||||
|
||||
scope.launch {
|
||||
context.dataStore.data.collectLatest { settings ->
|
||||
println("BootBehavior: ${settings.bootBehavior}")
|
||||
when (settings.bootBehavior) {
|
||||
AppSettings.BootBehavior.CONTINUE_RECORDING -> {
|
||||
if (AudioRecorderExporter.hasRecordingsAvailable(context)) {
|
||||
|
@ -58,10 +58,21 @@ abstract class IntervalRecorderService : ExtraRecorderInformationService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchCounterValue() {
|
||||
val files = outputFolder.listFiles()?.filter {
|
||||
val name = it.nameWithoutExtension
|
||||
|
||||
name.toIntOrNull() != null
|
||||
}?.toList() ?: emptyList()
|
||||
|
||||
counter = files.size
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
super.start()
|
||||
|
||||
outputFolder.mkdirs()
|
||||
fetchCounterValue()
|
||||
|
||||
scope.launch {
|
||||
dataStore.data.collectLatest { preferenceSettings ->
|
||||
|
@ -55,10 +55,10 @@ abstract class RecorderService : Service() {
|
||||
it
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
"initStart" -> {
|
||||
startRecording()
|
||||
if (intent.getBooleanExtra("startImmediately", false)) {
|
||||
startRecording()
|
||||
}
|
||||
}
|
||||
|
||||
"changeState" -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user