kunfei 3 gadi atpakaļ
vecāks
revīzija
8db31eeb9c

+ 8 - 9
app/src/main/java/io/legado/app/data/dao/BookDao.kt

@@ -2,7 +2,6 @@ package io.legado.app.data.dao
 
 
 import androidx.room.*
 import androidx.room.*
 import io.legado.app.constant.BookType
 import io.legado.app.constant.BookType
-import io.legado.app.data.appDb
 import io.legado.app.data.entities.Book
 import io.legado.app.data.entities.Book
 import io.legado.app.data.entities.BookGroup
 import io.legado.app.data.entities.BookGroup
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.Flow
@@ -12,14 +11,14 @@ interface BookDao {
 
 
     fun flowByGroup(groupId: Long): Flow<List<Book>> {
     fun flowByGroup(groupId: Long): Flow<List<Book>> {
         return when (groupId) {
         return when (groupId) {
-            BookGroup.IdRoot -> appDb.bookDao.flowRoot()
-            BookGroup.IdAll -> appDb.bookDao.flowAll()
-            BookGroup.IdLocal -> appDb.bookDao.flowLocal()
-            BookGroup.IdAudio -> appDb.bookDao.flowAudio()
-            BookGroup.IdNetNone -> appDb.bookDao.flowNetNoGroup()
-            BookGroup.IdLocalNone -> appDb.bookDao.flowLocalNoGroup()
-            BookGroup.IdError -> appDb.bookDao.flowUpdateError()
-            else -> appDb.bookDao.flowByUserGroup(groupId)
+            BookGroup.IdRoot -> flowRoot()
+            BookGroup.IdAll -> flowAll()
+            BookGroup.IdLocal -> flowLocal()
+            BookGroup.IdAudio -> flowAudio()
+            BookGroup.IdNetNone -> flowNetNoGroup()
+            BookGroup.IdLocalNone -> flowLocalNoGroup()
+            BookGroup.IdError -> flowUpdateError()
+            else -> flowByUserGroup(groupId)
         }
         }
     }
     }
 
 

+ 11 - 3
app/src/main/java/io/legado/app/ui/book/bookmark/AllBookmarkActivity.kt

@@ -10,7 +10,6 @@ import io.legado.app.data.appDb
 import io.legado.app.data.entities.Bookmark
 import io.legado.app.data.entities.Bookmark
 import io.legado.app.databinding.ActivityAllBookmarkBinding
 import io.legado.app.databinding.ActivityAllBookmarkBinding
 import io.legado.app.ui.file.HandleFileContract
 import io.legado.app.ui.file.HandleFileContract
-import io.legado.app.utils.launch
 import io.legado.app.utils.showDialogFragment
 import io.legado.app.utils.showDialogFragment
 import io.legado.app.utils.viewbindingdelegate.viewBinding
 import io.legado.app.utils.viewbindingdelegate.viewBinding
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
@@ -25,7 +24,10 @@ class AllBookmarkActivity : VMBaseActivity<ActivityAllBookmarkBinding, AllBookma
     }
     }
     private val exportDir = registerForActivityResult(HandleFileContract()) {
     private val exportDir = registerForActivityResult(HandleFileContract()) {
         it.uri?.let { uri ->
         it.uri?.let { uri ->
-            viewModel.saveToFile(uri)
+            when (it.requestCode) {
+                1 -> viewModel.exportBookmark(uri)
+                2 -> viewModel.exportBookmarkMd(uri)
+            }
         }
         }
     }
     }
 
 
@@ -50,7 +52,13 @@ class AllBookmarkActivity : VMBaseActivity<ActivityAllBookmarkBinding, AllBookma
 
 
     override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
     override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
         when (item.itemId) {
         when (item.itemId) {
-            R.id.menu_export -> exportDir.launch()
+            R.id.menu_export -> exportDir.launch {
+                requestCode = 1
+            }
+
+            R.id.menu_export_md -> exportDir.launch {
+                requestCode = 2
+            }
         }
         }
         return super.onCompatOptionsItemSelected(item)
         return super.onCompatOptionsItemSelected(item)
     }
     }

+ 30 - 2
app/src/main/java/io/legado/app/ui/book/bookmark/AllBookmarkViewModel.kt

@@ -21,10 +21,10 @@ class AllBookmarkViewModel(application: Application) : BaseViewModel(application
     /**
     /**
      * 导出书签
      * 导出书签
      */
      */
-    fun saveToFile(treeUri: Uri) {
+    fun exportBookmark(treeUri: Uri) {
         execute {
         execute {
             val dateFormat = SimpleDateFormat("yyMMddHHmmss", Locale.getDefault())
             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)
             val dirDoc = FileDoc.fromUri(treeUri, true)
             dirDoc.createFileIfNotExist(fileName).openOutputStream().getOrThrow().use {
             dirDoc.createFileIfNotExist(fileName).openOutputStream().getOrThrow().use {
                 GSON.writeToOutputStream(it, appDb.bookmarkDao.all)
                 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("导出成功")
+        }
+    }
+
 }
 }

+ 1 - 1
app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt

@@ -76,7 +76,7 @@ class TocViewModel(application: Application) : BaseViewModel(application) {
         execute {
         execute {
             val book = bookData.value
             val book = bookData.value
                 ?: throw NoStackTraceException(context.getString(R.string.no_book))
                 ?: throw NoStackTraceException(context.getString(R.string.no_book))
-            val fileName = "bookmark-${book.name} ${book.author}"
+            val fileName = "bookmark-${book.name} ${book.author}.json"
             val doc = FileDoc.fromUri(treeUri, true)
             val doc = FileDoc.fromUri(treeUri, true)
             doc.createFileIfNotExist(fileName).writeText(
             doc.createFileIfNotExist(fileName).writeText(
                 GSON.toJson(
                 GSON.toJson(

+ 4 - 0
app/src/main/res/menu/bookmark.xml

@@ -5,4 +5,8 @@
         android:id="@+id/menu_export"
         android:id="@+id/menu_export"
         android:title="@string/export" />
         android:title="@string/export" />
 
 
+    <item
+        android:id="@+id/menu_export_md"
+        android:title="@string/export_md" />
+
 </menu>
 </menu>

+ 1 - 0
app/src/main/res/values-es-rES/strings.xml

@@ -1124,4 +1124,5 @@
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-ja-rJP/strings.xml

@@ -1127,4 +1127,5 @@
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-pt-rBR/strings.xml

@@ -1127,4 +1127,5 @@
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-vi/strings.xml

@@ -1123,4 +1123,5 @@ Còn </string>
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -1124,4 +1124,5 @@
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -1126,4 +1126,5 @@
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-zh/strings.xml

@@ -1126,4 +1126,5 @@
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1127,4 +1127,5 @@
     <string name="effective_replaces">起效的替换</string>
     <string name="effective_replaces">起效的替换</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book">导出书籍</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
     <string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
+    <string name="export_md">导出(MD)</string>
 </resources>
 </resources>