pull/43/head^2
kunfei 5 years ago
parent e116f4f1ef
commit 4e0ffc8056
  1. 26
      app/src/main/java/io/legado/app/utils/FileUtils.kt

@ -116,13 +116,12 @@ object FileUtils {
} else if (isMediaDocument(uri)) { } else if (isMediaDocument(uri)) {
val docId = DocumentsContract.getDocumentId(uri) val docId = DocumentsContract.getDocumentId(uri)
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val type = split[0]
var contentUri: Uri? = null val contentUri: Uri = when (split[0]) {
when (type) { "image" -> MediaStore.Images.Media.EXTERNAL_CONTENT_URI
"image" -> contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI "video" -> MediaStore.Video.Media.EXTERNAL_CONTENT_URI
"video" -> contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI "audio" -> MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
"audio" -> contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI else -> uri
} }
val selection = "_id=?" val selection = "_id=?"
@ -137,7 +136,6 @@ object FileUtils {
uri.lastPathSegment uri.lastPathSegment
else else
getDataColumn(context, uri, null, null) getDataColumn(context, uri, null, null)
} else if ("file".equals(uri.scheme, ignoreCase = true)) { } else if ("file".equals(uri.scheme, ignoreCase = true)) {
return uri.path return uri.path
}// File }// File
@ -145,8 +143,8 @@ object FileUtils {
return null return null
} }
fun getDataColumn( private fun getDataColumn(
context: Context, uri: Uri?, selection: String?, context: Context, uri: Uri, selection: String?,
selectionArgs: kotlin.Array<String>? selectionArgs: kotlin.Array<String>?
): String? { ): String? {
@ -155,7 +153,7 @@ object FileUtils {
try { try {
context.contentResolver.query( context.contentResolver.query(
uri!!, uri,
projection, projection,
selection, selection,
selectionArgs, selectionArgs,
@ -177,7 +175,7 @@ object FileUtils {
* @param uri The Uri to check. * @param uri The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider. * @return Whether the Uri authority is ExternalStorageProvider.
*/ */
fun isExternalStorageDocument(uri: Uri): Boolean { private fun isExternalStorageDocument(uri: Uri): Boolean {
return "com.android.externalstorage.documents" == uri.authority return "com.android.externalstorage.documents" == uri.authority
} }
@ -185,7 +183,7 @@ object FileUtils {
* @param uri The Uri to check. * @param uri The Uri to check.
* @return Whether the Uri authority is DownloadsProvider. * @return Whether the Uri authority is DownloadsProvider.
*/ */
fun isDownloadsDocument(uri: Uri): Boolean { private fun isDownloadsDocument(uri: Uri): Boolean {
return "com.android.providers.downloads.documents" == uri.authority return "com.android.providers.downloads.documents" == uri.authority
} }
@ -193,7 +191,7 @@ object FileUtils {
* @param uri The Uri to check. * @param uri The Uri to check.
* @return Whether the Uri authority is MediaProvider. * @return Whether the Uri authority is MediaProvider.
*/ */
fun isMediaDocument(uri: Uri): Boolean { private fun isMediaDocument(uri: Uri): Boolean {
return "com.android.providers.media.documents" == uri.authority return "com.android.providers.media.documents" == uri.authority
} }
@ -201,7 +199,7 @@ object FileUtils {
* @param uri The Uri to check. * @param uri The Uri to check.
* @return Whether the Uri authority is Google Photos. * @return Whether the Uri authority is Google Photos.
*/ */
fun isGooglePhotosUri(uri: Uri): Boolean { private fun isGooglePhotosUri(uri: Uri): Boolean {
return "com.google.android.apps.photos.content" == uri.authority return "com.google.android.apps.photos.content" == uri.authority
} }

Loading…
Cancel
Save