pull/83/head
kunfei 6 years ago
parent de35674c43
commit 15cb3feee4
  1. 2
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 4
      app/src/main/java/io/legado/app/utils/DocumentUtils.kt

@ -83,7 +83,7 @@ object BookHelp {
fun getChapterCount(book: Book): Int { fun getChapterCount(book: Book): Int {
if (downloadUri.isDocumentUri(App.INSTANCE)) { if (downloadUri.isDocumentUri(App.INSTANCE)) {
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let {
return DocumentUtils.createFileIfNotExist( return DocumentUtils.createFolderIfNotExist(
it, it,
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) subDirs = *arrayOf(cacheFolderName, bookFolderName(book))
)?.listFiles()?.size ?: 0 )?.listFiles()?.size ?: 0

@ -17,11 +17,11 @@ object DocumentUtils {
mimeType: String = "", mimeType: String = "",
vararg subDirs: String vararg subDirs: String
): DocumentFile? { ): DocumentFile? {
val parent: DocumentFile? = createFileIfNotExist(root, *subDirs) val parent: DocumentFile? = createFolderIfNotExist(root, *subDirs)
return parent?.createFile(mimeType, fileName) return parent?.createFile(mimeType, fileName)
} }
fun createFileIfNotExist(root: DocumentFile, vararg subDirs: String): DocumentFile? { fun createFolderIfNotExist(root: DocumentFile, vararg subDirs: String): DocumentFile? {
var parent: DocumentFile? = root var parent: DocumentFile? = root
for (subDirName in subDirs) { for (subDirName in subDirs) {
val subDir = parent?.findFile(subDirName) val subDir = parent?.findFile(subDirName)

Loading…
Cancel
Save