From a63f59f2bc8f58140923abb459a98c595dbcb7f4 Mon Sep 17 00:00:00 2001 From: euxane Date: Wed, 18 Sep 2024 23:41:13 +0200 Subject: storageprovider: move documents URI from intent util --- .../tincapp/storageprovider/BrowseFilesIntents.kt | 14 ++------------ .../tincapp/storageprovider/FilesDocumentsProvider.kt | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'app/src/main/java/org') 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 import android.content.Context import android.content.Intent import android.net.Uri -import android.provider.DocumentsContract import android.provider.DocumentsContract.Document -import org.pacien.tincapp.BuildConfig object BrowseFilesIntents { - private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files" - - fun documentUri(documentId: String) = - DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId) - - fun childDocumentsUri(parentDocumentId: String) = - DocumentsContract.buildChildDocumentsUri(URI_AUTHORITY, parentDocumentId) - fun openDocumentTree(context: Context, documentId: String) = - openDocumentTree(context, documentUri(documentId)) + openDocumentTree(context, FilesDocumentsProvider.documentUri(documentId)) - fun openDocumentTree(context: Context, contentUri: Uri) { + private fun openDocumentTree(context: Context, contentUri: Uri) { val intent = Intent(Intent.ACTION_VIEW).apply { setDataAndType(contentUri, Document.MIME_TYPE_DIR) 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 import android.provider.DocumentsContract.Root import android.provider.DocumentsProvider import androidx.annotation.RequiresApi +import org.pacien.tincapp.BuildConfig import org.pacien.tincapp.R import org.pacien.tincapp.context.AppPaths import org.pacien.tincapp.utils.isParentOf @@ -41,8 +42,9 @@ import kotlin.io.path.relativeTo class FilesDocumentsProvider : DocumentsProvider() { companion object { - const val ROOT_ID = "" - const val ROOT_DOCUMENT_ID = "/" + private const val URI_AUTHORITY = BuildConfig.APPLICATION_ID + ".files" + private const val ROOT_ID = "" + private const val ROOT_DOCUMENT_ID = "/" const val VIRTUAL_ROOT_NETWORKS = "networks" const val VIRTUAL_ROOT_LOG = "log" @@ -65,6 +67,12 @@ class FilesDocumentsProvider : DocumentsProvider() { Document.COLUMN_FLAGS, Document.COLUMN_SIZE, ) + + fun documentUri(documentId: String): Uri = + DocumentsContract.buildDocumentUri(URI_AUTHORITY, documentId) + + fun childDocumentsUri(parentDocumentId: String): Uri = + DocumentsContract.buildChildDocumentsUri(URI_AUTHORITY, parentDocumentId) } override fun onCreate(): Boolean = true @@ -95,7 +103,7 @@ class FilesDocumentsProvider : DocumentsProvider() { sortOrder: String? ): Cursor = MatrixCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION).apply { - setNotificationUrl(BrowseFilesIntents.childDocumentsUri(parentDocumentId!!)) + setNotificationUrl(childDocumentsUri(parentDocumentId!!)) when (parentDocumentId) { ROOT_DOCUMENT_ID -> { addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE) @@ -130,7 +138,7 @@ class FilesDocumentsProvider : DocumentsProvider() { override fun deleteDocument(documentId: String?) { fileForDocumentId(documentId!!).apply { if (!deleteRecursively()) throw FileSystemException(this) - notifyChange(BrowseFilesIntents.childDocumentsUri(documentIdForFile(parentFile))) + notifyChange(childDocumentsUri(documentIdForFile(parentFile!!))) } } @@ -155,7 +163,7 @@ class FilesDocumentsProvider : DocumentsProvider() { else -> createNewFile() } if (!success) throw FileSystemException(this) - notifyChange(BrowseFilesIntents.childDocumentsUri(parentDocumentId)) + notifyChange(childDocumentsUri(parentDocumentId)) }.let { documentIdForFile(it) } -- cgit v1.2.3