|
|
@@ -14,6 +14,7 @@ import io.legado.app.model.localBook.LocalBook
|
|
|
import io.legado.app.utils.FileDoc
|
|
|
import io.legado.app.utils.GSON
|
|
|
import io.legado.app.utils.createFileIfNotExist
|
|
|
+import io.legado.app.utils.openOutputStream
|
|
|
import io.legado.app.utils.toastOnUi
|
|
|
import io.legado.app.utils.writeText
|
|
|
|
|
|
@@ -90,6 +91,30 @@ class TocViewModel(application: Application) : BaseViewModel(application) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun saveBookmarkMd(treeUri: Uri) {
|
|
|
+ execute {
|
|
|
+ val book = bookData.value
|
|
|
+ ?: throw NoStackTraceException(context.getString(R.string.no_book))
|
|
|
+ val fileName = "bookmark-${book.name} ${book.author}.md"
|
|
|
+ val treeDoc = FileDoc.fromUri(treeUri, true)
|
|
|
+ val fileDoc = treeDoc.createFileIfNotExist(fileName)
|
|
|
+ .openOutputStream()
|
|
|
+ .getOrThrow()
|
|
|
+ fileDoc.use { outputStream ->
|
|
|
+ outputStream.write("## ${book.name} ${book.author}\n\n".toByteArray())
|
|
|
+ appDb.bookmarkDao.getByBook(book.name, book.author).forEach {
|
|
|
+ outputStream.write("#### ${it.chapterName}\n\n".toByteArray())
|
|
|
+ outputStream.write("###### 原文\n ${it.bookText}\n\n".toByteArray())
|
|
|
+ outputStream.write("###### 摘要\n ${it.content}\n\n".toByteArray())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.onError {
|
|
|
+ AppLog.put("导出失败\n${it.localizedMessage}", it, true)
|
|
|
+ }.onSuccess {
|
|
|
+ context.toastOnUi("导出成功")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
interface ChapterListCallBack {
|
|
|
fun upChapterList(searchKey: String?)
|
|
|
|