fix: Sort batches

This commit is contained in:
Myzel394 2023-12-31 23:37:32 +01:00
parent da34df6b87
commit 3a542f3a4d
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B

View File

@ -18,7 +18,7 @@ import java.time.format.DateTimeFormatter
import com.arthenica.ffmpegkit.FFmpegKitConfig import com.arthenica.ffmpegkit.FFmpegKitConfig
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.net.toFile import androidx.core.net.toUri
import app.myzel394.alibi.ui.RECORDER_INTERNAL_SELECTED_VALUE import app.myzel394.alibi.ui.RECORDER_INTERNAL_SELECTED_VALUE
import app.myzel394.alibi.ui.RECORDER_MEDIA_SELECTED_VALUE import app.myzel394.alibi.ui.RECORDER_MEDIA_SELECTED_VALUE
import app.myzel394.alibi.ui.SUPPORTS_SCOPED_STORAGE import app.myzel394.alibi.ui.SUPPORTS_SCOPED_STORAGE
@ -112,15 +112,19 @@ abstract class BatchesFolder(
} }
fun getBatchesForFFmpeg(): List<String> { fun getBatchesForFFmpeg(): List<String> {
// TODO: There is probably a better way to do this iteratively, look at it if you have time
return when (type) { return when (type) {
BatchType.INTERNAL -> BatchType.INTERNAL ->
(getInternalFolder() ((getInternalFolder()
.listFiles() .listFiles()
?.filter { ?.filter {
it.nameWithoutExtension.toIntOrNull() != null it.nameWithoutExtension.toIntOrNull() != null
} }
?.toList() ?.toList()
?: emptyList()) ?: emptyList()) as List<File>)
.sortedBy {
it.nameWithoutExtension.toInt()
}
.map { it.absolutePath } .map { it.absolutePath }
BatchType.CUSTOM -> getCustomDefinedFolder() BatchType.CUSTOM -> getCustomDefinedFolder()
@ -128,6 +132,9 @@ abstract class BatchesFolder(
.filter { .filter {
it.name?.substringBeforeLast(".")?.toIntOrNull() != null it.name?.substringBeforeLast(".")?.toIntOrNull() != null
} }
.sortedBy {
it.name!!.substringBeforeLast(".").toInt()
}
.map { .map {
FFmpegKitConfig.getSafParameterForRead( FFmpegKitConfig.getSafParameterForRead(
context, context,
@ -136,24 +143,32 @@ abstract class BatchesFolder(
} }
BatchType.MEDIA -> { BatchType.MEDIA -> {
val filePaths = mutableListOf<String>() val fileUris = mutableListOf<Uri>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
queryMediaContent { _, _, uri, _ -> queryMediaContent { _, _, uri, _ ->
filePaths.add( fileUris.add(uri)
}
} else {
legacyMediaFolder.listFiles()?.forEach {
fileUris.add(it.toUri())
}
}
fileUris
.sortedBy {
return@sortedBy it
.lastPathSegment!!
.substring(mediaPrefix.length)
.substringBeforeLast(".")
.toInt()
}
.map { uri ->
FFmpegKitConfig.getSafParameterForRead( FFmpegKitConfig.getSafParameterForRead(
context, context,
uri, uri,
)!! )!!
)
} }
} else {
legacyMediaFolder.listFiles()?.forEach {
filePaths.add(it.absolutePath)
}
}
filePaths
} }
} }
} }
@ -367,6 +382,7 @@ abstract class BatchesFolder(
null, null,
) )
} else { } else {
// TODO: Fix "would you like to try saving" -> Save button
legacyMediaFolder.listFiles()?.forEach { legacyMediaFolder.listFiles()?.forEach {
val fileCounter = val fileCounter =
it.nameWithoutExtension.substring(mediaPrefix.length).toIntOrNull() it.nameWithoutExtension.substring(mediaPrefix.length).toIntOrNull()