优化
This commit is contained in:
@@ -52,7 +52,7 @@ class AllBookmarkViewModel(application: Application) : BaseViewModel(application
|
|||||||
author = it.bookAuthor
|
author = it.bookAuthor
|
||||||
outputStream.write("## ${it.bookName} ${it.bookAuthor}\n\n".toByteArray())
|
outputStream.write("## ${it.bookName} ${it.bookAuthor}\n\n".toByteArray())
|
||||||
}
|
}
|
||||||
outputStream.write("#### ${it.chapterName}\n".toByteArray())
|
outputStream.write("#### ${it.chapterName}\n\n".toByteArray())
|
||||||
outputStream.write("###### 原文\n ${it.bookText}\n\n".toByteArray())
|
outputStream.write("###### 原文\n ${it.bookText}\n\n".toByteArray())
|
||||||
outputStream.write("###### 摘要\n ${it.content}\n\n".toByteArray())
|
outputStream.write("###### 摘要\n ${it.content}\n\n".toByteArray())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
|
|||||||
private val waitDialog by lazy { WaitDialog(this) }
|
private val waitDialog by lazy { WaitDialog(this) }
|
||||||
private val exportDir = registerForActivityResult(HandleFileContract()) {
|
private val exportDir = registerForActivityResult(HandleFileContract()) {
|
||||||
it.uri?.let { uri ->
|
it.uri?.let { uri ->
|
||||||
viewModel.saveBookmark(uri)
|
when (it.requestCode) {
|
||||||
|
1 -> viewModel.saveBookmark(uri)
|
||||||
|
2 -> viewModel.saveBookmarkMd(uri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +160,13 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
|
|||||||
viewModel.chapterListCallBack?.upChapterList(searchView?.query?.toString())
|
viewModel.chapterListCallBack?.upChapterList(searchView?.query?.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.menu_export_bookmark -> exportDir.launch()
|
R.id.menu_export_bookmark -> exportDir.launch {
|
||||||
|
requestCode = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
R.id.menu_export_md -> exportDir.launch {
|
||||||
|
requestCode = 2
|
||||||
|
}
|
||||||
|
|
||||||
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.legado.app.model.localBook.LocalBook
|
|||||||
import io.legado.app.utils.FileDoc
|
import io.legado.app.utils.FileDoc
|
||||||
import io.legado.app.utils.GSON
|
import io.legado.app.utils.GSON
|
||||||
import io.legado.app.utils.createFileIfNotExist
|
import io.legado.app.utils.createFileIfNotExist
|
||||||
|
import io.legado.app.utils.openOutputStream
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import io.legado.app.utils.writeText
|
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 {
|
interface ChapterListCallBack {
|
||||||
fun upChapterList(searchKey: String?)
|
fun upChapterList(searchKey: String?)
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,11 @@
|
|||||||
android:title="@string/export"
|
android:title="@string/export"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_export_md"
|
||||||
|
android:title="@string/export_md"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
|
|||||||
Reference in New Issue
Block a user