Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
dependencies {
classpath "com.android.tools.build:gradle:9.0.0"

classpath "org.jetbrains.dokka:dokka-gradle-plugin:2.1.0"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:2.2.0"
classpath "com.vanniktech:gradle-maven-publish-plugin:0.36.0"
}
}
Expand All @@ -23,7 +23,7 @@ allprojects {
}

plugins.withId("com.vanniktech.maven.publish.base") {
version = "1.5"
version = "1.6"
group = "com.lazygeniouz"

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ abstract class DocumentFileCompat(
/**
* Rename a Document File / Folder.
*
* Will throw [UnsupportedOperationException] when called on a [SingleDocumentFileCompat].
* Succeeds when the underlying Uri carries `FLAG_SUPPORTS_RENAME`.
*
* @return True if the rename was successful, False otherwise.
* @throws UnsupportedOperationException
*/
abstract fun renameTo(name: String): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ internal class SingleDocumentFileCompat(
}

/**
* [SingleDocumentFileCompat] has limited access and permissions to the [uri].
* Rename succeeds when the underlying Uri carries `FLAG_SUPPORTS_RENAME`;
* ideally true for documents obtained from a tree grant via [DocumentFileCompat.listFiles].
*
* @throws UnsupportedOperationException
* @return True if the rename was successful, False otherwise.
*/
override fun renameTo(name: String): Boolean {
throw UnsupportedOperationException()
val newUri = fileController.renameTo(name)
val success = newUri != null
if (success) uri = newUri
return success
}

// Copies current file to the destination uri.
Expand Down
35 changes: 23 additions & 12 deletions dfc/src/main/java/com/lazygeniouz/dfc/resolver/ResolverCompat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.net.Uri
import android.provider.DocumentsContract
import android.provider.DocumentsContract.Document
import com.lazygeniouz.dfc.file.DocumentFileCompat
import com.lazygeniouz.dfc.file.internals.SingleDocumentFileCompat
import com.lazygeniouz.dfc.file.internals.TreeDocumentFileCompat
import com.lazygeniouz.dfc.logger.ErrorLogger

Expand Down Expand Up @@ -125,10 +126,11 @@ internal object ResolverCompat {
val childrenUri = createChildrenUri(uri)
val listOfDocuments = arrayListOf<DocumentFileCompat>()

// ensure `Document.COLUMN_DOCUMENT_ID` is always included
val finalProjection = if (Document.COLUMN_DOCUMENT_ID !in projection) {
arrayOf(Document.COLUMN_DOCUMENT_ID, *projection)
} else projection
val finalProjection = arrayOf(
Document.COLUMN_DOCUMENT_ID, /* identifier */
Document.COLUMN_MIME_TYPE, /* for supporting rename via `isDirectory` check */
*projection
).distinct().toTypedArray()

val cursor = getCursor(context, childrenUri, finalProjection) ?: return emptyList()

Expand Down Expand Up @@ -168,14 +170,23 @@ internal object ResolverCompat {
*/
val documentFlags = getLongOrDefault(cursor, flagsIndex, 0L).toInt()

TreeDocumentFileCompat(
context, documentUri, documentName,
documentSize, lastModifiedTime,
documentMimeType, documentFlags
).also { childFile ->
childFile.parentFile = file
listOfDocuments.add(childFile)
}
/* return correct document type */
val childFile: DocumentFileCompat =
if (documentMimeType == Document.MIME_TYPE_DIR) {
TreeDocumentFileCompat(
context, documentUri, documentName,
documentSize, lastModifiedTime,
documentMimeType, documentFlags
)
} else {
SingleDocumentFileCompat(
context, documentUri, documentName,
documentSize, lastModifiedTime,
documentMimeType, documentFlags
)
}
childFile.parentFile = file
listOfDocuments.add(childFile)
}
}

Expand Down
Loading