aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt14
-rw-r--r--app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt18
2 files changed, 15 insertions, 17 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 4705c0b..a4cc5c5 100644
--- a/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt
+++ b/app/src/main/java/org/pacien/tincapp/storageprovider/BrowseFilesIntents.kt
@@ -21,23 +21,13 @@ package org.pacien.tincapp.storageprovider
21import android.content.Context 21import android.content.Context
22import android.content.Intent 22import android.content.Intent
23import android.net.Uri 23import android.net.Uri
24import android.provider.DocumentsContract
25import android.provider.DocumentsContract.Document 24import android.provider.DocumentsContract.Document
26import org.pacien.tincapp.BuildConfig
27 25
28object BrowseFilesIntents { 26object BrowseFilesIntents {
29 private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files"
30
31 fun documentUri(documentId: String) =
32 DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId)
33
34 fun childDocumentsUri(parentDocumentId: String) =
35 DocumentsContract.buildChildDocumentsUri(URI_AUTHORITY, parentDocumentId)
36
37 fun openDocumentTree(context: Context, documentId: String) = 27 fun openDocumentTree(context: Context, documentId: String) =
38 openDocumentTree(context, documentUri(documentId)) 28 openDocumentTree(context, FilesDocumentsProvider.documentUri(documentId))
39 29
40 fun openDocumentTree(context: Context, contentUri: Uri) { 30 private fun openDocumentTree(context: Context, contentUri: Uri) {
41 val intent = Intent(Intent.ACTION_VIEW).apply { 31 val intent = Intent(Intent.ACTION_VIEW).apply {
42 setDataAndType(contentUri, Document.MIME_TYPE_DIR) 32 setDataAndType(contentUri, Document.MIME_TYPE_DIR)
43 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) 33 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
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 48d0319..80b7331 100644
--- a/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt
+++ b/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt
@@ -29,6 +29,7 @@ import android.provider.DocumentsContract.Document
29import android.provider.DocumentsContract.Root 29import android.provider.DocumentsContract.Root
30import android.provider.DocumentsProvider 30import android.provider.DocumentsProvider
31import androidx.annotation.RequiresApi 31import androidx.annotation.RequiresApi
32import org.pacien.tincapp.BuildConfig
32import org.pacien.tincapp.R 33import org.pacien.tincapp.R
33import org.pacien.tincapp.context.AppPaths 34import org.pacien.tincapp.context.AppPaths
34import org.pacien.tincapp.utils.isParentOf 35import org.pacien.tincapp.utils.isParentOf
@@ -41,8 +42,9 @@ import kotlin.io.path.relativeTo
41 42
42class FilesDocumentsProvider : DocumentsProvider() { 43class FilesDocumentsProvider : DocumentsProvider() {
43 companion object { 44 companion object {
44 const val ROOT_ID = "" 45 private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files"
45 const val ROOT_DOCUMENT_ID = "/" 46 private const val ROOT_ID = ""
47 private const val ROOT_DOCUMENT_ID = "/"
46 const val VIRTUAL_ROOT_NETWORKS = "networks" 48 const val VIRTUAL_ROOT_NETWORKS = "networks"
47 const val VIRTUAL_ROOT_LOG = "log" 49 const val VIRTUAL_ROOT_LOG = "log"
48 50
@@ -65,6 +67,12 @@ class FilesDocumentsProvider : DocumentsProvider() {
65 Document.COLUMN_FLAGS, 67 Document.COLUMN_FLAGS,
66 Document.COLUMN_SIZE, 68 Document.COLUMN_SIZE,
67 ) 69 )
70
71 fun documentUri(documentId: String): Uri =
72 DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId)
73
74 fun childDocumentsUri(parentDocumentId: String): Uri =
75 DocumentsContract.buildChildDocumentsUri(URI_AUTHORITY, parentDocumentId)
68 } 76 }
69 77
70 override fun onCreate(): Boolean = true 78 override fun onCreate(): Boolean = true
@@ -95,7 +103,7 @@ class FilesDocumentsProvider : DocumentsProvider() {
95 sortOrder: String? 103 sortOrder: String?
96 ): Cursor = 104 ): Cursor =
97 MatrixCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION).apply { 105 MatrixCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION).apply {
98 setNotificationUrl(BrowseFilesIntents.childDocumentsUri(parentDocumentId!!)) 106 setNotificationUrl(childDocumentsUri(parentDocumentId!!))
99 when (parentDocumentId) { 107 when (parentDocumentId) {
100 ROOT_DOCUMENT_ID -> { 108 ROOT_DOCUMENT_ID -> {
101 addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE) 109 addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE)
@@ -130,7 +138,7 @@ class FilesDocumentsProvider : DocumentsProvider() {
130 override fun deleteDocument(documentId: String?) { 138 override fun deleteDocument(documentId: String?) {
131 fileForDocumentId(documentId!!).apply { 139 fileForDocumentId(documentId!!).apply {
132 if (!deleteRecursively()) throw FileSystemException(this) 140 if (!deleteRecursively()) throw FileSystemException(this)
133 notifyChange(BrowseFilesIntents.childDocumentsUri(documentIdForFile(parentFile))) 141 notifyChange(childDocumentsUri(documentIdForFile(parentFile!!)))
134 } 142 }
135 } 143 }
136 144
@@ -155,7 +163,7 @@ class FilesDocumentsProvider : DocumentsProvider() {
155 else -> createNewFile() 163 else -> createNewFile()
156 } 164 }
157 if (!success) throw FileSystemException(this) 165 if (!success) throw FileSystemException(this)
158 notifyChange(BrowseFilesIntents.childDocumentsUri(parentDocumentId)) 166 notifyChange(childDocumentsUri(parentDocumentId))
159 }.let { 167 }.let {
160 documentIdForFile(it) 168 documentIdForFile(it)
161 } 169 }