Skip to content

Commit 3cfbbde

Browse files
committed
fix: Use one source of truth for the filename (instead of recalculating it, this doesn't work, as the date _time_ will differ)
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
1 parent a88507a commit 3cfbbde

File tree

4 files changed

+32
-43
lines changed

4 files changed

+32
-43
lines changed

app/src/main/java/app/myzel394/alibi/helpers/AudioBatchesFolder.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,25 @@ class AudioBatchesFolder(
4040
override fun getOutputFileForFFmpeg(
4141
date: LocalDateTime,
4242
extension: String,
43+
fileName: String,
4344
): String {
4445
return when (type) {
45-
BatchType.INTERNAL -> asInternalGetOutputFile(date, extension).absolutePath
46+
BatchType.INTERNAL -> asInternalGetOutputFile(fileName).absolutePath
4647

4748
BatchType.CUSTOM -> {
48-
val name = getName(date, extension)
49-
5049
FFmpegKitConfig.getSafParameterForWrite(
5150
context,
52-
(customFolder!!.findFile(name) ?: customFolder.createFile(
51+
(customFolder!!.findFile(fileName) ?: customFolder.createFile(
5352
"audio/${extension}",
54-
getName(date, extension),
53+
fileName,
5554
)!!).uri
5655
)!!
5756
}
5857

5958
BatchType.MEDIA -> {
6059
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
6160
val mediaUri = getOrCreateMediaFile(
62-
name = getName(date, extension),
61+
name = fileName,
6362
mimeType = "audio/$extension",
6463
relativePath = BASE_SCOPED_STORAGE_RELATIVE_PATH + "/" + MEDIA_SUBFOLDER_NAME,
6564
)
@@ -72,7 +71,7 @@ class AudioBatchesFolder(
7271
val path = arrayOf(
7372
Environment.getExternalStoragePublicDirectory(BASE_LEGACY_STORAGE_FOLDER),
7473
MEDIA_SUBFOLDER_NAME,
75-
getName(date, extension)
74+
fileName,
7675
).joinToString("/")
7776
return File(path)
7877
.apply {

app/src/main/java/app/myzel394/alibi/helpers/BatchesFolder.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ abstract class BatchesFolder(
191191
return "$name.$extension"
192192
}
193193

194-
fun asInternalGetOutputFile(date: LocalDateTime, extension: String): File {
195-
return File(getInternalFolder(), getName(date, extension))
194+
fun asInternalGetOutputFile(fileName: String): File {
195+
return File(getInternalFolder(), fileName)
196196
}
197197

198198
fun asMediaGetLegacyFile(name: String): File = File(
@@ -203,16 +203,8 @@ abstract class BatchesFolder(
203203
}
204204

205205
fun checkIfOutputAlreadyExists(
206-
date: LocalDateTime,
207-
extension: String
206+
fileName: String,
208207
): Boolean {
209-
val stem = date
210-
.format(DateTimeFormatter.ISO_DATE_TIME)
211-
.toString()
212-
.replace(":", "-")
213-
.replace(".", "_")
214-
val fileName = "$stem.$extension"
215-
216208
return when (type) {
217209
BatchType.INTERNAL -> File(getInternalFolder(), fileName).exists()
218210

@@ -245,6 +237,7 @@ abstract class BatchesFolder(
245237
abstract fun getOutputFileForFFmpeg(
246238
date: LocalDateTime,
247239
extension: String,
240+
fileName: String,
248241
): String
249242

250243
abstract fun cleanup()
@@ -255,18 +248,17 @@ abstract class BatchesFolder(
255248
disableCache: Boolean? = null,
256249
onNextParameterTry: (String) -> Unit = {},
257250
onProgress: (Float?) -> Unit = {},
251+
fileName: String,
258252
): String {
259253
val disableCache = disableCache ?: (type != BatchType.INTERNAL)
260254
val date = recording.getStartDateForFilename(filenameFormat)
261255

262-
if (!disableCache && checkIfOutputAlreadyExists(
263-
recording.recordingStart,
264-
recording.fileExtension
265-
)
256+
if (!disableCache && checkIfOutputAlreadyExists(fileName)
266257
) {
267258
return getOutputFileForFFmpeg(
268259
date = recording.recordingStart,
269260
extension = recording.fileExtension,
261+
fileName = fileName,
270262
)
271263
}
272264

@@ -282,6 +274,7 @@ abstract class BatchesFolder(
282274
val outputFile = getOutputFileForFFmpeg(
283275
date = date,
284276
extension = recording.fileExtension,
277+
fileName = fileName,
285278
)
286279

287280
concatenationFunction(

app/src/main/java/app/myzel394/alibi/helpers/VideoBatchesFolder.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,28 @@ class VideoBatchesFolder(
3939

4040
private var customParcelFileDescriptor: ParcelFileDescriptor? = null
4141

42-
override fun getOutputFileForFFmpeg(date: LocalDateTime, extension: String): String {
42+
override fun getOutputFileForFFmpeg(
43+
date: LocalDateTime,
44+
extension: String,
45+
fileName: String,
46+
): String {
4347
return when (type) {
44-
BatchType.INTERNAL -> asInternalGetOutputFile(date, extension).absolutePath
48+
BatchType.INTERNAL -> asInternalGetOutputFile(fileName).absolutePath
4549

4650
BatchType.CUSTOM -> {
47-
val name = getName(date, extension)
48-
4951
FFmpegKitConfig.getSafParameterForWrite(
5052
context,
51-
(customFolder!!.findFile(name) ?: customFolder.createFile(
53+
(customFolder!!.findFile(fileName) ?: customFolder.createFile(
5254
"video/${extension}",
53-
getName(date, extension),
55+
fileName,
5456
)!!).uri
5557
)!!
5658
}
5759

5860
BatchType.MEDIA -> {
5961
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
6062
val mediaUri = getOrCreateMediaFile(
61-
name = getName(date, extension),
63+
name = fileName,
6264
mimeType = "video/$extension",
6365
relativePath = BASE_SCOPED_STORAGE_RELATIVE_PATH + "/" + MEDIA_SUBFOLDER_NAME,
6466
)
@@ -71,7 +73,7 @@ class VideoBatchesFolder(
7173
val path = arrayOf(
7274
Environment.getExternalStoragePublicDirectory(BASE_LEGACY_STORAGE_FOLDER),
7375
MEDIA_SUBFOLDER_NAME,
74-
getName(date, extension)
76+
fileName,
7577
).joinToString("/")
7678
return File(path)
7779
.apply {

app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/RecorderEventsHandler.kt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,38 +177,33 @@ fun RecorderEventsHandler(
177177
else -> throw Exception("Unknown recorder type")
178178
}
179179

180+
val fileName = batchesFolder.getName(
181+
recording.recordingStart,
182+
recording.fileExtension,
183+
)
184+
180185
batchesFolder.concatenate(
181186
recording,
182187
filenameFormat = settings.filenameFormat,
188+
fileName = fileName,
183189
onProgress = { percentage ->
184190
processingProgress = percentage
185191
}
186192
)
187193

188194
// Save file
189-
val name = batchesFolder.getName(
190-
recording.recordingStart,
191-
recording.fileExtension,
192-
)
193-
194195
when (batchesFolder.type) {
195196
BatchesFolder.BatchType.INTERNAL -> {
196197
when (batchesFolder) {
197198
is AudioBatchesFolder -> {
198199
saveAudioFile(
199-
batchesFolder.asInternalGetOutputFile(
200-
recording.recordingStart,
201-
recording.fileExtension,
202-
), name
200+
batchesFolder.asInternalGetOutputFile(fileName), fileName
203201
)
204202
}
205203

206204
is VideoBatchesFolder -> {
207205
saveVideoFile(
208-
batchesFolder.asInternalGetOutputFile(
209-
recording.recordingStart,
210-
recording.fileExtension,
211-
), name
206+
batchesFolder.asInternalGetOutputFile(fileName), fileName
212207
)
213208
}
214209
}

0 commit comments

Comments
 (0)