diff --git a/app/src/main/java/me/zhanghai/android/files/provider/content/ContentFileSystem.kt b/app/src/main/java/me/zhanghai/android/files/provider/content/ContentFileSystem.kt index c09219ba9..e6834598f 100644 --- a/app/src/main/java/me/zhanghai/android/files/provider/content/ContentFileSystem.kt +++ b/app/src/main/java/me/zhanghai/android/files/provider/content/ContentFileSystem.kt @@ -31,9 +31,7 @@ internal class ContentFileSystem(private val provider: ContentFileSystemProvider override fun isReadOnly(): Boolean = false - override fun getSeparator(): String { - throw UnsupportedOperationException() - } + override fun getSeparator(): String = SEPARATOR_STRING override fun getRootDirectories(): Iterable = emptyList() @@ -80,6 +78,9 @@ internal class ContentFileSystem(private val provider: ContentFileSystemProvider override fun writeToParcel(dest: Parcel, flags: Int) {} companion object { + const val SEPARATOR = '/'.code.toByte() + private const val SEPARATOR_STRING = SEPARATOR.toInt().toChar().toString() + @JvmField val CREATOR = object : Parcelable.Creator { override fun createFromParcel(source: Parcel): ContentFileSystem = diff --git a/app/src/main/java/me/zhanghai/android/files/provider/content/ContentPath.kt b/app/src/main/java/me/zhanghai/android/files/provider/content/ContentPath.kt index d1e8d323c..363263f30 100644 --- a/app/src/main/java/me/zhanghai/android/files/provider/content/ContentPath.kt +++ b/app/src/main/java/me/zhanghai/android/files/provider/content/ContentPath.kt @@ -32,14 +32,15 @@ internal class ContentPath : ByteStringListPath { val uri: Uri? constructor(fileSystem: ContentFileSystem, uri: Uri) : super( - 0.toByte(), true, listOf(uri.displayNameOrUri) + ContentFileSystem.SEPARATOR, true, + listOf(Uri.encode(uri.toString()).toByteString(), uri.bestFileName) ) { this.fileSystem = fileSystem this.uri = uri } private constructor(fileSystem: ContentFileSystem, segments: List) : super( - 0.toByte(), false, segments + ContentFileSystem.SEPARATOR, false, segments ) { this.fileSystem = fileSystem uri = null @@ -149,14 +150,14 @@ internal class ContentPath : ByteStringListPath { } companion object { - private val Uri.displayNameOrUri: ByteString + private val Uri.bestFileName: ByteString get() = (try { Resolver.getDisplayName(this) } catch (e: ResolverException) { e.printStackTrace() null - } ?: lastPathSegment ?: toString()).toByteString() + } ?: lastPathSegment ?: "file").toByteString() @JvmField val CREATOR = object : Parcelable.Creator {