diff --git a/calf-file-picker/src/androidMain/kotlin/com/mohamedrejeb/calf/picker/UriHelper.kt b/calf-file-picker/src/androidMain/kotlin/com/mohamedrejeb/calf/picker/UriHelper.kt deleted file mode 100644 index 3c28bc6..0000000 --- a/calf-file-picker/src/androidMain/kotlin/com/mohamedrejeb/calf/picker/UriHelper.kt +++ /dev/null @@ -1,112 +0,0 @@ -package com.mohamedrejeb.calf.picker - -import android.content.ContentUris -import android.content.Context -import android.database.Cursor -import android.net.Uri -import android.os.Environment -import android.provider.DocumentsContract -import android.provider.MediaStore - -internal object URIPathHelper { - fun getPath( - context: Context, - uri: Uri?, - ): String? { - if (uri == null) return null - - // DocumentProvider - if (DocumentsContract.isDocumentUri(context, uri)) { - // ExternalStorageProvider - if (isExternalStorageDocument(uri)) { - val docId = DocumentsContract.getDocumentId(uri) - val split = docId.split(":".toRegex()).toTypedArray() - val type = split[0] - if ("primary".equals(type, ignoreCase = true)) { - return Environment.getExternalStorageDirectory().toString() + "/" + split[1] - } - } else if (isDownloadsDocument(uri)) { - val id = DocumentsContract.getDocumentId(uri) - val contentUri = - ContentUris.withAppendedId( - Uri.parse("content://downloads/public_downloads"), - java.lang.Long.valueOf(id), - ) - return getDataColumn(context, contentUri, null, null) - } else if (isMediaDocument(uri)) { - val docId = DocumentsContract.getDocumentId(uri) - val split = docId.split(":".toRegex()).toTypedArray() - val type = split[0] - var contentUri: Uri? = null - println("docId: $docId") - println("type: $type") - - when (type) { - "image" -> { - contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI - } - "video" -> { - contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI - } - "audio" -> { - contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI - } - } - val selection = "_id=?" - val selectionArgs = arrayOf(split[1]) - println("contentUri: $contentUri") - println("selectionArgs: $selectionArgs") - return getDataColumn(context, contentUri, selection, selectionArgs) - ?: getDataColumn(context, uri, null, null) - } - } else if (isExternalStorageDocument(uri)) { - if (uri.pathSegments.size > 1) { - val docId = uri.pathSegments[1] - val split = docId.split(":".toRegex()).toTypedArray() - val type = split[0] - if ("primary".equals(type, ignoreCase = true) && split.size > 1) { - return Environment.getExternalStorageDirectory().toString() + "/" + split[1] - } - } - } else if ("content".equals(uri.scheme, ignoreCase = true)) { - println("content") - return getDataColumn(context, uri, null, null) - } else if ("file".equals(uri.scheme, ignoreCase = true)) { - return uri.path - } - return null - } - - private fun getDataColumn( - context: Context, - uri: Uri?, - selection: String?, - selectionArgs: Array?, - ): String? { - var cursor: Cursor? = null - val column = "_data" - val projection = arrayOf(column) - try { - cursor = context.contentResolver.query(uri!!, projection, selection, selectionArgs, null) - if (cursor != null && cursor.moveToFirst()) { - val columnIndex: Int = cursor.getColumnIndexOrThrow(column) - return cursor.getString(columnIndex) - } - } finally { - cursor?.close() - } - return null - } - - private fun isExternalStorageDocument(uri: Uri): Boolean { - return "com.android.externalstorage.documents" == uri.authority - } - - private fun isDownloadsDocument(uri: Uri): Boolean { - return "com.android.providers.downloads.documents" == uri.authority - } - - private fun isMediaDocument(uri: Uri): Boolean { - return "com.android.providers.media.documents" == uri.authority - } -} diff --git a/calf-file-picker/src/desktopMain/kotlin/com/mohamedrejeb/calf/picker/FilePickerLauncher.desktop.kt b/calf-file-picker/src/desktopMain/kotlin/com/mohamedrejeb/calf/picker/FilePickerLauncher.desktop.kt index 909f16b..0469b42 100644 --- a/calf-file-picker/src/desktopMain/kotlin/com/mohamedrejeb/calf/picker/FilePickerLauncher.desktop.kt +++ b/calf-file-picker/src/desktopMain/kotlin/com/mohamedrejeb/calf/picker/FilePickerLauncher.desktop.kt @@ -66,9 +66,3 @@ actual class FilePickerLauncher actual constructor( val File.extension: String get() = name.substringAfterLast(".") - -fun main() { - MimeTypes.findExtensionsByMimeTypes("video/*", true).also { - println(it) - } -} \ No newline at end of file