diff options
author | Allan Wang <me@allanwang.ca> | 2017-10-10 16:44:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-10 16:44:54 -0400 |
commit | ff597a7ef456fcb37160fa7a46b45296098ca413 (patch) | |
tree | 4e209a27ad52a5fa466726ef7beb74601377e5fa /mediapicker/src | |
parent | 5343e63855d70bd5c801e7d8baf774a3386b5f34 (diff) | |
download | kau-ff597a7ef456fcb37160fa7a46b45296098ca413.tar.gz kau-ff597a7ef456fcb37160fa7a46b45296098ca413.tar.bz2 kau-ff597a7ef456fcb37160fa7a46b45296098ca413.zip |
fix/validate-document-uri (#80)
* Check if id is document before retrieving
* Add logging
* Add null check for getString index 1
Diffstat (limited to 'mediapicker/src')
-rw-r--r-- | mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt | 2 | ||||
-rw-r--r-- | mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt index ae85558..26736d4 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt @@ -21,7 +21,7 @@ data class MediaModel( @Throws(SQLException::class) constructor(@NonNull cursor: Cursor) : this( cursor.getString(0), - cursor.getString(1), + cursor.getString(1) ?: "", cursor.getLong(2), cursor.getLong(3), cursor.getString(4) diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt index d518b78..ec5d2f0 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -153,8 +153,7 @@ abstract class MediaPickerCore<T : IItem<*, *>>( * The adapter will be cleared on each successful call */ open fun loadItems() { - kauRequestPermissions(Manifest.permission.READ_EXTERNAL_STORAGE) { - granted, _ -> + kauRequestPermissions(Manifest.permission.READ_EXTERNAL_STORAGE) { granted, _ -> if (granted) { supportLoaderManager.initLoader(LOADER_ID, null, this) onStatusChange(true) @@ -191,7 +190,7 @@ abstract class MediaPickerCore<T : IItem<*, *>>( } catch (ignored: InterruptedException) { } catch (ignored: ExecutionException) { } finally { - glide.clear(target) + glide.clear(target) } } } @@ -238,9 +237,13 @@ abstract class MediaPickerCore<T : IItem<*, *>>( * See <a href="http://hmkcode.com/android-display-selected-image-and-its-real-path/"></a> */ private fun <R> ContentResolver.query(baseUri: Uri, uris: List<Uri>, block: (cursor: Cursor) -> R) { - val ids = uris.map { + val ids = uris.filter { + val valid = DocumentsContract.isDocumentUri(this@MediaPickerCore, it) + if (!valid) KL.d("Non document uri: ${it.encodedPath}") + valid + }.mapNotNull { DocumentsContract.getDocumentId(it).split(":").getOrNull(1) - }.filterNotNull().joinToString(prefix = "(", separator = ",", postfix = ")") + }.joinToString(prefix = "(", separator = ",", postfix = ")") //? query replacements are done for one arg at a time //since we potentially have a list of ids, we'll just format the WHERE clause ourself query(baseUri, MediaModel.projection, "${BaseColumns._ID} IN $ids", null, sortQuery)?.use(block) |