mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Improve check for existing file query
This commit is contained in:
parent
c6dca0fc77
commit
329b41b4c8
@ -3,6 +3,7 @@ package app.myzel394.alibi.helpers
|
|||||||
import android.content.ContentUris
|
import android.content.ContentUris
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
@ -52,40 +53,29 @@ class VideoBatchesFolder(
|
|||||||
var uri: Uri? = null
|
var uri: Uri? = null
|
||||||
context.contentResolver.query(
|
context.contentResolver.query(
|
||||||
mediaContentUri,
|
mediaContentUri,
|
||||||
null,
|
arrayOf(MediaStore.MediaColumns._ID, MediaStore.MediaColumns.DISPLAY_NAME),
|
||||||
// TODO: Improve
|
// TODO: Improve
|
||||||
null,
|
"${MediaStore.MediaColumns.DISPLAY_NAME} = '$name'",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
)!!.use { cursor ->
|
)!!.use { cursor ->
|
||||||
while (cursor.moveToNext()) {
|
if (cursor.moveToFirst()) {
|
||||||
|
// No need to check for the name since the query already did that
|
||||||
val id = cursor.getColumnIndex(MediaStore.MediaColumns._ID)
|
val id = cursor.getColumnIndex(MediaStore.MediaColumns._ID)
|
||||||
|
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
continue
|
return@use
|
||||||
}
|
|
||||||
|
|
||||||
val nameID = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
|
|
||||||
|
|
||||||
if (nameID == -1) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
val cursorName = cursor.getString(nameID)
|
|
||||||
|
|
||||||
if (cursorName != name) {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uri = ContentUris.withAppendedId(
|
uri = ContentUris.withAppendedId(
|
||||||
mediaContentUri,
|
mediaContentUri,
|
||||||
cursor.getLong(id)
|
cursor.getLong(id)
|
||||||
)
|
)
|
||||||
return@use
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
|
// Create empty output file to be able to write to it
|
||||||
uri = context.contentResolver.insert(
|
uri = context.contentResolver.insert(
|
||||||
mediaContentUri,
|
mediaContentUri,
|
||||||
android.content.ContentValues().apply {
|
android.content.ContentValues().apply {
|
||||||
@ -97,10 +87,13 @@ class VideoBatchesFolder(
|
|||||||
MediaStore.MediaColumns.MIME_TYPE,
|
MediaStore.MediaColumns.MIME_TYPE,
|
||||||
"video/$extension"
|
"video/$extension"
|
||||||
)
|
)
|
||||||
put(
|
|
||||||
MediaStore.Video.Media.RELATIVE_PATH,
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
Environment.DIRECTORY_DCIM + "/alibi/video_recordings"
|
put(
|
||||||
)
|
MediaStore.Video.Media.RELATIVE_PATH,
|
||||||
|
MEDIA_RELATIVE_PATH,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)!!
|
)!!
|
||||||
}
|
}
|
||||||
@ -158,6 +151,8 @@ class VideoBatchesFolder(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val MEDIA_RELATIVE_PATH = Environment.DIRECTORY_DCIM + "/alibi/video_recordings"
|
||||||
|
|
||||||
// Parameters to be passed in descending order
|
// Parameters to be passed in descending order
|
||||||
// Those parameters first try to concatenate without re-encoding
|
// Those parameters first try to concatenate without re-encoding
|
||||||
// if that fails, it'll try several fallback methods
|
// if that fails, it'll try several fallback methods
|
||||||
|
Loading…
x
Reference in New Issue
Block a user