|
|
@ -133,9 +133,11 @@ object BookHelp { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getContent(book: Book, bookChapter: BookChapter): String? { |
|
|
|
fun getContent(book: Book, bookChapter: BookChapter): String? { |
|
|
|
if (book.isLocalBook()) { |
|
|
|
when { |
|
|
|
|
|
|
|
book.isLocalBook() -> { |
|
|
|
return AnalyzeTxtFile.getContent(book, bookChapter) |
|
|
|
return AnalyzeTxtFile.getContent(book, bookChapter) |
|
|
|
} else if (downloadUri.isDocumentUri(App.INSTANCE)) { |
|
|
|
} |
|
|
|
|
|
|
|
downloadUri.isDocumentUri(App.INSTANCE) -> { |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
return DocumentUtils.getDirDocument( |
|
|
|
return DocumentUtils.getDirDocument( |
|
|
|
root, |
|
|
|
root, |
|
|
@ -143,7 +145,8 @@ object BookHelp { |
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
?.uri?.readText(App.INSTANCE) |
|
|
|
?.uri?.readText(App.INSTANCE) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
val file = FileUtils.getFile( |
|
|
|
val file = FileUtils.getFile( |
|
|
|
File(downloadPath), |
|
|
|
File(downloadPath), |
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
@ -153,11 +156,14 @@ object BookHelp { |
|
|
|
return file.readText() |
|
|
|
return file.readText() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun delContent(book: Book, bookChapter: BookChapter) { |
|
|
|
fun delContent(book: Book, bookChapter: BookChapter) { |
|
|
|
if (downloadUri.isDocumentUri(App.INSTANCE)) { |
|
|
|
when { |
|
|
|
|
|
|
|
book.isLocalBook() -> return |
|
|
|
|
|
|
|
downloadUri.isDocumentUri(App.INSTANCE) -> { |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
DocumentUtils.getDirDocument( |
|
|
|
DocumentUtils.getDirDocument( |
|
|
|
root, |
|
|
|
root, |
|
|
@ -165,7 +171,8 @@ object BookHelp { |
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
?.delete() |
|
|
|
?.delete() |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
File(downloadPath), |
|
|
|
File(downloadPath), |
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
@ -173,6 +180,7 @@ object BookHelp { |
|
|
|
).delete() |
|
|
|
).delete() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun formatFolderName(folderName: String): String { |
|
|
|
private fun formatFolderName(folderName: String): String { |
|
|
|
return folderName.replace("[\\\\/:*?\"<>|.]".toRegex(), "") |
|
|
|
return folderName.replace("[\\\\/:*?\"<>|.]".toRegex(), "") |
|
|
|