|
|
@@ -21,10 +21,10 @@ class AllBookmarkViewModel(application: Application) : BaseViewModel(application
|
|
|
/**
|
|
|
* 导出书签
|
|
|
*/
|
|
|
- fun saveToFile(treeUri: Uri) {
|
|
|
+ fun exportBookmark(treeUri: Uri) {
|
|
|
execute {
|
|
|
val dateFormat = SimpleDateFormat("yyMMddHHmmss", Locale.getDefault())
|
|
|
- val fileName = "bookmark-${dateFormat.format(Date())}"
|
|
|
+ val fileName = "bookmark-${dateFormat.format(Date())}.json"
|
|
|
val dirDoc = FileDoc.fromUri(treeUri, true)
|
|
|
dirDoc.createFileIfNotExist(fileName).openOutputStream().getOrThrow().use {
|
|
|
GSON.writeToOutputStream(it, appDb.bookmarkDao.all)
|
|
|
@@ -36,4 +36,32 @@ class AllBookmarkViewModel(application: Application) : BaseViewModel(application
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ fun exportBookmarkMd(treeUri: Uri) {
|
|
|
+ execute {
|
|
|
+ val dateFormat = SimpleDateFormat("yyMMddHHmmss", Locale.getDefault())
|
|
|
+ val fileName = "bookmark-${dateFormat.format(Date())}.md"
|
|
|
+ val dirDoc = FileDoc.fromUri(treeUri, true)
|
|
|
+ val fileDoc = dirDoc.createFileIfNotExist(fileName).openOutputStream().getOrThrow()
|
|
|
+ fileDoc.use { outputStream ->
|
|
|
+ var name = ""
|
|
|
+ var author = ""
|
|
|
+ appDb.bookmarkDao.all.forEach {
|
|
|
+ if (it.bookName != name && it.bookAuthor != author) {
|
|
|
+ name = it.bookName
|
|
|
+ author = it.bookAuthor
|
|
|
+ outputStream.write("## ${it.bookName} ${it.bookAuthor}\n\n".toByteArray())
|
|
|
+ }
|
|
|
+ outputStream.write("#### ${it.chapterName}\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("导出成功")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|