Skip to content

Commit

Permalink
Add getUri for AmazeFile
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelMess committed Apr 23, 2022
1 parent 90d4a65 commit ed97229
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -497,6 +498,11 @@ class AmazeFile : Comparable<AmazeFile?> {
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
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +32,7 @@ import java.security.NoSuchAlgorithmException
import kotlin.experimental.and

abstract class AmazeFilesystem {

/* -- Normalization and construction -- */
/** filesystem prefix */
abstract val prefix: String
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 = '/'

Expand Down

0 comments on commit ed97229

Please sign in to comment.