From d30598bb5834101de87d7eeeba1ac9d9e6134392 Mon Sep 17 00:00:00 2001 From: EmmanuelMess Date: Fri, 22 Apr 2022 18:05:28 -0300 Subject: [PATCH] Add getUri for AmazeFile --- .../filesystem/otg/OtgAmazeFilesystem.kt | 16 ++++++++++++++++ .../filesystem/filetypes/AmazeFile.kt | 6 ++++++ .../filesystem/filetypes/AmazeFilesystem.kt | 13 +++++++++++++ 3 files changed, 35 insertions(+) diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt b/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt index 8373e1d112..e668343ff8 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt +++ b/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt @@ -1,6 +1,9 @@ package com.amaze.filemanager.filesystem.otg +import android.net.Uri +import android.os.Build import android.util.Log +import androidx.core.content.FileProvider import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFile import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFilesystem import com.amaze.filemanager.file_operations.filesystem.filetypes.ContextProvider @@ -29,6 +32,19 @@ object OtgAmazeFilesystem : AmazeFilesystem() { return simpleUnixNormalize(path) } + override fun getUriForFile(f: AmazeFile, contextProvider: ContextProvider): Uri? { + val context = contextProvider.getContext() ?: return null + + val documentFile = getDocumentFile(f.path, context, true) + + if(documentFile == null) { + Log.e(TAG, "Null DocumentFile getting Uri!") + return null + } + + return documentFile.uri + } + override fun resolve(parent: String, child: String): String { val prefix = parent.substring(0, prefixLength(parent)) val simplePathParent = parent.substring(prefixLength(parent)) diff --git a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt index 482313c440..7442fd773b 100644 --- a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt +++ b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt @@ -20,6 +20,7 @@ package com.amaze.filemanager.file_operations.filesystem.filetypes +import android.net.Uri import android.os.Parcel import android.util.Log import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.box.BoxAmazeFilesystem @@ -497,6 +498,11 @@ class AmazeFile : Comparable { val canonPath = canonicalPath return AmazeFile(canonPath, fs.prefixLength(canonPath)) } + + fun getUriForFile(contextProvider: ContextProvider): Uri? { + return fs.getUriForFile(this, contextProvider) + } + /* -- Attribute accessors -- */ // Android-changed. Removed javadoc comment about special privileges // that doesn't make sense on android /** diff --git a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt index 1c62298cbe..036d25639c 100644 --- a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt +++ b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt @@ -20,6 +20,8 @@ package com.amaze.filemanager.file_operations.filesystem.filetypes +import android.net.Uri +import android.util.Log import java.io.File import java.io.IOException import java.io.InputStream @@ -30,6 +32,7 @@ import java.security.NoSuchAlgorithmException import kotlin.experimental.and abstract class AmazeFilesystem { + /* -- Normalization and construction -- */ /** filesystem prefix */ abstract val prefix: String @@ -57,6 +60,14 @@ abstract class AmazeFilesystem { return f.path } + /** + * Convert the given [AmazeFile]'s path to an [Uri]. + */ + open fun getUriForFile(f: AmazeFile, contextProvider: ContextProvider): Uri? { + Log.e(TAG, "get Uri failed for file") + return null + } + /** * Compute the length of this pathname string's prefix. The pathname string must be in normal * form. @@ -297,6 +308,8 @@ abstract class AmazeFilesystem { } companion object { + private val TAG = AmazeFilesystem::class.java.simpleName + /** Return the local filesystem's name-separator character. */ const val STANDARD_SEPARATOR = '/'