Skip to content

Commit b00757d

Browse files
author
LaksCastro
committed
(#7) Add missing docs to the new SAF APIs
1 parent c34c15d commit b00757d

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

lib/src/storage_access_framework/storage_access_framework.dart

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ import 'package:shared_storage/shared_storage.dart';
22
import 'package:shared_storage/src/method_channel.dart';
33
import 'package:shared_storage/src/storage_access_framework/uri_permission.dart';
44

5-
/// TODO: Add [initialDir] param as mentioned here:
6-
/// TODO: Add documentation
5+
/// Start Activity Action: Allow the user to pick a directory subtree.
6+
/// When invoked, the system will display the various `DocumentsProvider`
7+
/// instances installed on the device, letting the user navigate through them.
8+
/// Apps can fully manage documents within the returned directory.
9+
///
10+
/// [Refer to details](https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE)
11+
///
12+
/// TODO: Implement [initialDir] param to
13+
/// support the initial directory of the directory picker
714
Future<Uri?> openDocumentTree() async {
815
const kOpenDocumentTree = 'openDocumentTree';
916

@@ -15,7 +22,18 @@ Future<Uri?> openDocumentTree() async {
1522
return Uri.parse(selectedDirectoryUri);
1623
}
1724

18-
/// TODO: Add documentation
25+
/// Starts Activity Action: Allow the user to create a new document.
26+
/// When invoked, the system will display the various `DocumentsProvider`
27+
/// instances installed on the device, letting the user navigate through them.
28+
/// The returned document may be a newly created document with no content,
29+
/// or it may be an existing document with the requested MIME type.
30+
///
31+
/// - [mimeType] is the kind of file that you want to create
32+
/// - [content] the file content, will be converted to bytes `List<Int>`
33+
/// - [displayName] the name of the file without any extension
34+
/// - [directory] Needs to be the [URI] directory returned by `openDocumentTree`
35+
///
36+
/// [Refer to details](https://developer.android.com/reference/android/content/Intent#ACTION_CREATE_DOCUMENT)
1937
Future<Uri?> createDocumentFile({
2038
required String mimeType,
2139
required String content,
@@ -46,6 +64,10 @@ Future<Uri?> createDocumentFile({
4664
return Uri.parse(createdFileUri);
4765
}
4866

67+
/// Returns an `List<URI>` with all persisted [URI]
68+
///
69+
/// To persist an [URI] call `openDocumentTree`
70+
/// and to remove an persisted [URI] call `releasePersistableUriPermission`
4971
Future<List<UriPermission>?> persistedUriPermissions() async {
5072
const kPersistedUriPermissions = 'persistedUriPermissions';
5173

@@ -60,6 +82,12 @@ Future<List<UriPermission>?> persistedUriPermissions() async {
6082
.toList();
6183
}
6284

85+
/// Will revoke an persistable URI
86+
///
87+
/// Call this when your App no longer wants the permission of an [URI] returned
88+
/// by `openDocumentTree` method
89+
///
90+
/// To get the current persisted [URI]s call `persistedUriPermissions`
6391
Future<void> releasePersistableUriPermission(Uri directory) async {
6492
const kReleasePersistableUriPermission = 'releasePersistableUriPermission';
6593

@@ -73,7 +101,8 @@ Future<void> releasePersistableUriPermission(Uri directory) async {
73101
/// Convenient method to verify if a given [uri]
74102
/// is allowed to be write or read from SAF API's
75103
///
76-
/// TODO: Improve documentation
104+
/// This uses the `releasePersistableUriPermission` method to get the List
105+
/// of allowed [URI]s then will verify if the [uri] is included in
77106
Future<bool> isPersistedUri(Uri uri) async {
78107
final persistedUris = await persistedUriPermissions();
79108

lib/src/storage_access_framework/uri_permission.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
///
55
/// [Refer to details](https://developer.android.com/reference/android/content/UriPermission)
66
class UriPermission {
7+
/// Whether an [UriPermission] is created with [`FLAG_GRANT_READ_URI_PERMISSION`](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION)
78
final bool isReadPermission;
9+
10+
/// Whether an [UriPermission] is created with [`FLAG_GRANT_WRITE_URI_PERMISSION`](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_WRITE_URI_PERMISSION)
811
final bool isWritePermission;
12+
13+
/// Return the time when this permission was first persisted, in milliseconds
14+
/// since January 1, 1970 00:00:00.0 UTC. Returns `INVALID_TIME` if
15+
/// not persisted.
16+
///
17+
/// [Refer to details](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/UriPermission.java#77)
918
final int persistedTime;
19+
20+
/// Return the Uri this permission pertains to.
21+
///
22+
/// [Refer to details](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/UriPermission.java#56)
1023
final Uri uri;
1124

25+
/// Even we allow create instances of this class avoid it and use
26+
/// `persistedUriPermissions` API instead
1227
const UriPermission(
1328
{required this.isReadPermission,
1429
required this.isWritePermission,

0 commit comments

Comments
 (0)