fix: Properly assign batchesFolder

This commit is contained in:
Myzel394 2023-11-28 17:43:31 +01:00
parent 448108a974
commit 89baa35ed7
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
7 changed files with 23 additions and 34 deletions

View File

@ -6,21 +6,21 @@ import android.media.AudioDeviceInfo
import android.media.AudioManager
import android.media.MediaRecorder
import android.media.MediaRecorder.OnErrorListener
import android.net.Uri
import android.os.Build
import android.os.Handler
import android.os.Looper
import androidx.compose.material3.SnackbarDuration
import androidx.documentfile.provider.DocumentFile
import app.myzel394.alibi.db.AudioRecorderSettings
import app.myzel394.alibi.db.RecordingInformation
import app.myzel394.alibi.enums.RecorderState
import app.myzel394.alibi.helpers.AudioBatchesFolder
import app.myzel394.alibi.helpers.BatchesFolder
import app.myzel394.alibi.ui.utils.MicrophoneInfo
import java.lang.IllegalStateException
class AudioRecorderService :
IntervalRecorderService<AudioRecorderService.Settings, RecordingInformation>() {
override var batchesFolder: BatchesFolder = AudioBatchesFolder.viaInternalFolder(this)
var amplitudesAmount = 1000
var selectedMicrophone: MicrophoneInfo? = null

View File

@ -1,20 +1,6 @@
package app.myzel394.alibi.services
import android.media.MediaRecorder
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import app.myzel394.alibi.dataStore
import app.myzel394.alibi.db.AudioRecorderSettings
import app.myzel394.alibi.db.RecordingInformation
import app.myzel394.alibi.helpers.AudioRecorderExporter
import app.myzel394.alibi.helpers.BatchesFolder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.w3c.dom.DocumentFragment
import java.io.File
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
@ -28,7 +14,7 @@ abstract class IntervalRecorderService<S : IntervalRecorderService.Settings, I>
private lateinit var cycleTimer: ScheduledExecutorService
var batchesFolder: BatchesFolder = BatchesFolder.viaInternalFolder(this)
abstract var batchesFolder: BatchesFolder
var onCustomOutputFolderNotAccessible: () -> Unit = {}
@ -54,10 +40,8 @@ abstract class IntervalRecorderService<S : IntervalRecorderService.Settings, I>
override fun start() {
batchesFolder.initFolders()
if (!batchesFolder.checkIfFolderIsAccessible()) {
batchesFolder =
BatchesFolder.viaInternalFolder(this@IntervalRecorderService)
batchesFolder.initFolders()
onCustomOutputFolderNotAccessible()
return
}
createTimer()

View File

@ -13,6 +13,8 @@ import androidx.camera.video.VideoCapture
import androidx.core.content.ContextCompat
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.db.RecordingInformation
import app.myzel394.alibi.helpers.BatchesFolder
import app.myzel394.alibi.helpers.VideoBatchesFolder
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -23,6 +25,8 @@ import kotlinx.coroutines.withContext
class VideoRecorderService :
IntervalRecorderService<VideoRecorderService.Settings, RecordingInformation>() {
override var batchesFolder: BatchesFolder = VideoBatchesFolder.viaInternalFolder(this)
private val job = SupervisorJob()
private val scope = CoroutineScope(Dispatchers.IO + job)

View File

@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModel
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.db.RecordingInformation
import app.myzel394.alibi.enums.RecorderState
import app.myzel394.alibi.helpers.AudioBatchesFolder
import app.myzel394.alibi.helpers.AudioRecorderExporter
import app.myzel394.alibi.helpers.BatchesFolder
import app.myzel394.alibi.services.AudioRecorderService
@ -67,9 +68,9 @@ class AudioRecorderModel :
override fun startRecording(context: Context, settings: AppSettings) {
batchesFolder = if (settings.audioRecorderSettings.saveFolder == null)
BatchesFolder.viaInternalFolder(context)
AudioBatchesFolder.viaInternalFolder(context)
else
BatchesFolder.viaCustomFolder(
AudioBatchesFolder.viaCustomFolder(
context,
DocumentFile.fromTreeUri(
context,
@ -95,6 +96,8 @@ class AudioRecorderModel :
recorderService!!.changeMicrophone(microphone)
if (microphone == null) {
// Microphone was reset to default,
// default is always assumed to be connected
microphoneStatus = MicrophoneConnectivityStatus.CONNECTED
}
}

View File

@ -66,7 +66,10 @@ abstract class BaseRecorderModel<S : IntervalRecorderService.Settings, I, T : In
recorder.onError = {
onError()
}
recorder.batchesFolder = batchesFolder ?: recorder.batchesFolder
if (batchesFolder != null) {
recorder.batchesFolder = batchesFolder!!
}
// Rest should be initialized from the child class
onServiceConnected(recorder)

View File

@ -8,7 +8,7 @@ class VideoRecorderModel :
override val intentClass = VideoRecorderService::class.java
override fun onServiceConnected(service: VideoRecorderService) {
service.settings = VideoRecorderService.Settings.from()
service.settings = VideoRecorderService.Settings.from(settings)
service.clearAllRecordings()
service.startRecording()

View File

@ -1,9 +1,6 @@
package app.myzel394.alibi.ui.screens
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.IBinder
import android.annotation.SuppressLint
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
@ -12,19 +9,15 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.services.AudioRecorderService
import app.myzel394.alibi.services.RecorderService
import app.myzel394.alibi.services.VideoService
import app.myzel394.alibi.ui.models.VideoRecorderModel
@SuppressLint("NewApi")
@Composable
fun POCVideo(
videoRecorder: VideoRecorderModel,
@ -46,6 +39,8 @@ fun POCVideo(
videoRecorder.startRecording(context, settings)
} else {
videoRecorder.stopRecording(context)
val folder = "content://media/external/video/media/DCIM/Recordings"
}
started = !started