|
|
|
@ -9,6 +9,7 @@ import io.legado.app.base.BaseViewModel |
|
|
|
|
import io.legado.app.constant.AppPattern |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
|
import io.legado.app.help.storage.WebDavHelp |
|
|
|
|
import io.legado.app.utils.* |
|
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
@ -34,8 +35,19 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun export(doc: DocumentFile, book: Book) { |
|
|
|
|
DocumentUtils.createFileIfNotExist(doc, "${book.name} 作者:${book.author}.txt") |
|
|
|
|
?.writeText(context, getAllContents(book)) |
|
|
|
|
val filename = "${book.name} by ${book.author}.txt" |
|
|
|
|
val content = getAllContents(book) |
|
|
|
|
DocumentUtils.createFileIfNotExist(doc, filename) |
|
|
|
|
?.writeText(context, content) |
|
|
|
|
//写出文件到cache目录 |
|
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
|
File(FileUtils.getCachePath()), |
|
|
|
|
filename |
|
|
|
|
).writeText(content) |
|
|
|
|
//导出到webdav |
|
|
|
|
WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) |
|
|
|
|
//上传完删除cache文件 |
|
|
|
|
FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") |
|
|
|
|
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> |
|
|
|
|
BookHelp.getContent(book, chapter).let { content -> |
|
|
|
|
content?.split("\n")?.forEachIndexed { index, text -> |
|
|
|
@ -61,8 +73,10 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun export(file: File, book: Book) { |
|
|
|
|
FileUtils.createFileIfNotExist(file, "${book.name} 作者:${book.author}.txt") |
|
|
|
|
val filename = "${book.name} by ${book.author}.txt" |
|
|
|
|
FileUtils.createFileIfNotExist(file, filename) |
|
|
|
|
.writeText(getAllContents(book)) |
|
|
|
|
WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav |
|
|
|
|
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> |
|
|
|
|
BookHelp.getContent(book, chapter).let { content -> |
|
|
|
|
content?.split("\n")?.forEachIndexed { index, text -> |
|
|
|
|