Skip to content

Commit

Permalink
Merge pull request #54 from lakscastro/master
Browse files Browse the repository at this point in the history
`v0.3.1` to fix critical exception on `listFiles` API
  • Loading branch information
alexrintt authored May 31, 2022
2 parents 90b7331 + 82cf746 commit bc1133c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 14 deletions.
11 changes: 10 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": [
"README.md",
"docs/Getting Started.md"
"docs/index.md"
],
"imageSize": 100,
"contributorsPerLine": 7,
Expand Down Expand Up @@ -58,6 +58,15 @@
"bug",
"ideas"
]
},
{
"login": "EternityForest",
"name": "Daniel Dunn",
"avatar_url": "https://avatars.githubusercontent.com/u/758047?v=4",
"profile": "https://eternityforest.com",
"contributions": [
"bug"
]
}
],
"projectName": "shared-storage",
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: lakscastro
assignees: ''

---

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.3.1

Minor improvements and bug fixes:

- Crash when ommiting `DocumentFileColumn.id` column on `listFiles` API. Thanks to @EternityForest.
- Updated docs to info that now `DocumentFileColumn.id` column is optional when calling `listFiles`.

## 0.3.0

Major release focused on support for `Storage Access Framework`.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ These are the brilliant minds behind the development of this plugin!
<td align="center"><a href="https://www.bibliotecaortodoxa.ro"><img src="https://avatars.githubusercontent.com/u/1148228?v=4?s=100" width="100px;" alt=""/><br /><sub><b>www.bibliotecaortodoxa.ro</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/commits?author=aplicatii-romanesti" title="Code">💻</a> <a href="https://github.com/lakscastro/shared-storage/issues?q=author%3Aaplicatii-romanesti" title="Bug reports">🐛</a> <a href="#ideas-aplicatii-romanesti" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/dangilbert"><img src="https://avatars.githubusercontent.com/u/6799566?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dangilbert</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/commits?author=dangilbert" title="Code">💻</a> <a href="https://github.com/lakscastro/shared-storage/issues?q=author%3Adangilbert" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/dhaval-k-simformsolutions"><img src="https://avatars.githubusercontent.com/u/90894202?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dhaval-k-simformsolutions</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/issues?q=author%3Adhaval-k-simformsolutions" title="Bug reports">🐛</a> <a href="#ideas-dhaval-k-simformsolutions" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://eternityforest.com"><img src="https://avatars.githubusercontent.com/u/758047?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Daniel Dunn</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/issues?q=author%3AEternityForest" title="Bug reports">🐛</a></td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import android.os.Build
import android.provider.DocumentsContract
import android.util.Base64
import androidx.annotation.RequiresApi
import androidx.annotation.RestrictTo
import androidx.documentfile.provider.DocumentFile
import io.lakscastro.sharedstorage.plugin.API_19
import io.lakscastro.sharedstorage.plugin.API_21
import io.lakscastro.sharedstorage.plugin.API_24
import java.io.ByteArrayOutputStream
import java.io.Closeable
import java.io.File

/**
* Helper class to make more easy to handle callbacks using Kotlin syntax
Expand Down Expand Up @@ -174,12 +172,17 @@ fun traverseDirectoryEntries(
while (dirNodes.isNotEmpty()) {
val (parent, children) = dirNodes.removeAt(0)

val requiredColumns = if (rootOnly) emptyArray() else arrayOf(
DocumentsContract.Document.COLUMN_MIME_TYPE,
DocumentsContract.Document.COLUMN_DOCUMENT_ID
)
val requiredColumns =
if (rootOnly) emptyArray() else arrayOf(DocumentsContract.Document.COLUMN_MIME_TYPE)

val intrinsicColumns =
arrayOf(DocumentsContract.Document.COLUMN_DOCUMENT_ID)

val projection = arrayOf(*columns, *requiredColumns).toSet().toTypedArray()
val projection = arrayOf(
*columns,
*requiredColumns,
*intrinsicColumns
).toSet().toTypedArray()

val cursor = contentResolver.query(
children,
Expand All @@ -198,7 +201,7 @@ fun traverseDirectoryEntries(
while (cursor.moveToNext()) {
val data = mutableMapOf<String, Any>()

for (column in columns) {
for (column in projection) {
data[column] = cursorHandlerOf(typeOfColumn(column)!!)(
cursor,
cursor.getColumnIndexOrThrow(column)
Expand All @@ -220,7 +223,7 @@ fun traverseDirectoryEntries(
)
)

if (isDirectory != null && isDirectory && !rootOnly) {
if (isDirectory == true && !rootOnly) {
val nextChildren =
DocumentsContract.buildChildDocumentsUriUsingTree(rootUri, id)

Expand Down
4 changes: 3 additions & 1 deletion docs/Usage/Storage Access Framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ if (grantedUri != null) {

This method list files lazily **over a granted uri:**

> **Note** `DocumentFileColumn.id` is optional. It is required to fetch the file list from native API. So it is enabled regardless if you include this column or not. And this applies only to this API (`listFiles`).
```dart
/// *Must* be a granted uri from `openDocumentTree`
final Uri myGrantedUri = ...
Expand All @@ -83,7 +85,7 @@ const List<DocumentFileColumn> columns = <DocumentFileColumn>[
DocumentFileColumn.displayName,
DocumentFileColumn.size,
DocumentFileColumn.lastModified,
DocumentFileColumn.id,
DocumentFileColumn.id, // Optional column, will be available/queried regardless if is or not included here
DocumentFileColumn.mimeType,
];
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Most Flutter plugins use Android API's under the hood. So this plugin does the s
These are the brilliant minds behind the development of this plugin!

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->

<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
Expand All @@ -80,6 +79,7 @@ These are the brilliant minds behind the development of this plugin!
<td align="center"><a href="https://www.bibliotecaortodoxa.ro"><img src="https://avatars.githubusercontent.com/u/1148228?v=4?s=100" width="100px;" alt=""/><br /><sub><b>www.bibliotecaortodoxa.ro</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/commits?author=aplicatii-romanesti" title="Code">💻</a> <a href="https://github.com/lakscastro/shared-storage/issues?q=author%3Aaplicatii-romanesti" title="Bug reports">🐛</a> <a href="#ideas-aplicatii-romanesti" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/dangilbert"><img src="https://avatars.githubusercontent.com/u/6799566?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dangilbert</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/commits?author=dangilbert" title="Code">💻</a> <a href="https://github.com/lakscastro/shared-storage/issues?q=author%3Adangilbert" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/dhaval-k-simformsolutions"><img src="https://avatars.githubusercontent.com/u/90894202?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dhaval-k-simformsolutions</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/issues?q=author%3Adhaval-k-simformsolutions" title="Bug reports">🐛</a> <a href="#ideas-dhaval-k-simformsolutions" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://eternityforest.com"><img src="https://avatars.githubusercontent.com/u/758047?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Daniel Dunn</b></sub></a><br /><a href="https://github.com/lakscastro/shared-storage/issues?q=author%3AEternityForest" title="Bug reports">🐛</a></td>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions example/lib/screens/folder_files/folder_file_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class _FolderFileListState extends State<FolderFileList> {
DocumentFileColumn.displayName,
DocumentFileColumn.size,
DocumentFileColumn.lastModified,
// Optional column (this can't be removed because it's required to list files)
DocumentFileColumn.id,
DocumentFileColumn.mimeType,
];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: shared_storage
description: "Flutter plugin to get Android shared folders like DCIM, Downloads, Video, Audio. Works with Android 4.1 (API Level 16+)"
version: 0.3.0
version: 0.3.1
homepage: https://github.com/lakscastro/shared-storage
repository: https://github.com/lakscastro/shared-storage
issue_tracker: https://github.com/lakscastro/shared-storage/issues
Expand Down

0 comments on commit bc1133c

Please sign in to comment.