diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt | 12 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt | 14 |
2 files changed, 21 insertions, 5 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt b/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt index 3ebd501..4705c0b 100644 --- a/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt +++ b/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt | |||
@@ -28,10 +28,14 @@ import org.pacien.tincapp.BuildConfig | |||
28 | object BrowseFilesIntents { | 28 | object BrowseFilesIntents { |
29 | private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files" | 29 | private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files" |
30 | 30 | ||
31 | fun openDocumentTree(context: Context, documentId: String) { | 31 | fun documentUri(documentId: String) = |
32 | val contentUri = DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId) | 32 | DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId) |
33 | openDocumentTree(context, contentUri) | 33 | |
34 | } | 34 | fun childDocumentsUri(parentDocumentId: String) = |
35 | DocumentsContract.buildChildDocumentsUri(URI_AUTHORITY, parentDocumentId) | ||
36 | |||
37 | fun openDocumentTree(context: Context, documentId: String) = | ||
38 | openDocumentTree(context, documentUri(documentId)) | ||
35 | 39 | ||
36 | fun openDocumentTree(context: Context, contentUri: Uri) { | 40 | fun openDocumentTree(context: Context, contentUri: Uri) { |
37 | val intent = Intent(Intent.ACTION_VIEW).apply { | 41 | val intent = Intent(Intent.ACTION_VIEW).apply { |
diff --git a/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt b/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt index 8b8e2a7..688ae27 100644 --- a/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt +++ b/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt | |||
@@ -22,6 +22,7 @@ import android.os.CancellationSignal | |||
22 | import android.os.ParcelFileDescriptor | 22 | import android.os.ParcelFileDescriptor |
23 | import android.database.Cursor | 23 | import android.database.Cursor |
24 | import android.database.MatrixCursor | 24 | import android.database.MatrixCursor |
25 | import android.net.Uri | ||
25 | import android.os.Build | 26 | import android.os.Build |
26 | import android.provider.DocumentsContract | 27 | import android.provider.DocumentsContract |
27 | import android.provider.DocumentsContract.Document | 28 | import android.provider.DocumentsContract.Document |
@@ -92,13 +93,14 @@ class FilesDocumentsProvider : DocumentsProvider() { | |||
92 | sortOrder: String? | 93 | sortOrder: String? |
93 | ): Cursor = | 94 | ): Cursor = |
94 | MatrixCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION).apply { | 95 | MatrixCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION).apply { |
96 | setNotificationUrl(BrowseFilesIntents.childDocumentsUri(parentDocumentId!!)) | ||
95 | when (parentDocumentId) { | 97 | when (parentDocumentId) { |
96 | ROOT_DOCUMENT_ID -> { | 98 | ROOT_DOCUMENT_ID -> { |
97 | addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE) | 99 | addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE) |
98 | addVirtualDirRow(VIRTUAL_ROOT_LOG, Document.FLAG_DIR_SUPPORTS_CREATE) | 100 | addVirtualDirRow(VIRTUAL_ROOT_LOG, Document.FLAG_DIR_SUPPORTS_CREATE) |
99 | } | 101 | } |
100 | 102 | ||
101 | else -> fileForDocumentId(parentDocumentId!!).listFiles()?.forEach { | 103 | else -> fileForDocumentId(parentDocumentId).listFiles()?.forEach { |
102 | addFileRow(documentIdForFile(it), it) | 104 | addFileRow(documentIdForFile(it), it) |
103 | } | 105 | } |
104 | } | 106 | } |
@@ -126,6 +128,7 @@ class FilesDocumentsProvider : DocumentsProvider() { | |||
126 | override fun deleteDocument(documentId: String?) { | 128 | override fun deleteDocument(documentId: String?) { |
127 | fileForDocumentId(documentId!!).apply { | 129 | fileForDocumentId(documentId!!).apply { |
128 | if (!deleteRecursively()) throw FileSystemException(this) | 130 | if (!deleteRecursively()) throw FileSystemException(this) |
131 | notifyChange(BrowseFilesIntents.childDocumentsUri(documentIdForFile(parentFile))) | ||
129 | } | 132 | } |
130 | } | 133 | } |
131 | 134 | ||
@@ -150,6 +153,7 @@ class FilesDocumentsProvider : DocumentsProvider() { | |||
150 | else -> createNewFile() | 153 | else -> createNewFile() |
151 | } | 154 | } |
152 | if (!success) throw FileSystemException(this) | 155 | if (!success) throw FileSystemException(this) |
156 | notifyChange(BrowseFilesIntents.childDocumentsUri(parentDocumentId)) | ||
153 | }.let { | 157 | }.let { |
154 | documentIdForFile(it) | 158 | documentIdForFile(it) |
155 | } | 159 | } |
@@ -223,4 +227,12 @@ class FilesDocumentsProvider : DocumentsProvider() { | |||
223 | val row = newRow() | 227 | val row = newRow() |
224 | pairs.forEach { row.add(it.first, it.second) } | 228 | pairs.forEach { row.add(it.first, it.second) } |
225 | } | 229 | } |
230 | |||
231 | private fun MatrixCursor.setNotificationUrl(uri: Uri) { | ||
232 | setNotificationUri(context!!.contentResolver, uri) | ||
233 | } | ||
234 | |||
235 | private fun notifyChange(uri: Uri) { | ||
236 | context!!.contentResolver.notifyChange(uri, null) | ||
237 | } | ||
226 | } \ No newline at end of file | 238 | } \ No newline at end of file |