|
|
@ -133,44 +133,52 @@ object BookHelp { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getContent(book: Book, bookChapter: BookChapter): String? { |
|
|
|
fun getContent(book: Book, bookChapter: BookChapter): String? { |
|
|
|
if (book.isLocalBook()) { |
|
|
|
when { |
|
|
|
return AnalyzeTxtFile.getContent(book, bookChapter) |
|
|
|
book.isLocalBook() -> { |
|
|
|
} else if (downloadUri.isDocumentUri(App.INSTANCE)) { |
|
|
|
return AnalyzeTxtFile.getContent(book, bookChapter) |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
|
|
|
|
return DocumentUtils.getDirDocument( |
|
|
|
|
|
|
|
root, |
|
|
|
|
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
|
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
|
|
|
|
?.uri?.readText(App.INSTANCE) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
downloadUri.isDocumentUri(App.INSTANCE) -> { |
|
|
|
val file = FileUtils.getFile( |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
File(downloadPath), |
|
|
|
return DocumentUtils.getDirDocument( |
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
|
root, |
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
) |
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
if (file.exists()) { |
|
|
|
?.uri?.readText(App.INSTANCE) |
|
|
|
return file.readText() |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
val file = FileUtils.getFile( |
|
|
|
|
|
|
|
File(downloadPath), |
|
|
|
|
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
|
|
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
if (file.exists()) { |
|
|
|
|
|
|
|
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 { |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
book.isLocalBook() -> return |
|
|
|
DocumentUtils.getDirDocument( |
|
|
|
downloadUri.isDocumentUri(App.INSTANCE) -> { |
|
|
|
root, |
|
|
|
DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> |
|
|
|
|
|
|
|
DocumentUtils.getDirDocument( |
|
|
|
|
|
|
|
root, |
|
|
|
|
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
|
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
|
|
|
|
?.delete() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
|
|
|
|
File(downloadPath), |
|
|
|
|
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
)?.findFile("${bookChapterName(bookChapter)}.nb") |
|
|
|
).delete() |
|
|
|
?.delete() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
|
|
|
|
File(downloadPath), |
|
|
|
|
|
|
|
"${bookChapterName(bookChapter)}.nb", |
|
|
|
|
|
|
|
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) |
|
|
|
|
|
|
|
).delete() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|