优化
This commit is contained in:
@@ -4,6 +4,7 @@ import androidx.room.*
|
||||
import io.legado.app.constant.BookType
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookGroup
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
@@ -81,6 +82,11 @@ interface BookDao {
|
||||
@Query("SELECT * FROM books WHERE name = :name and author = :author")
|
||||
fun getBook(name: String, author: String): Book?
|
||||
|
||||
@Query("""select distinct bs.* from books, book_sources bs
|
||||
where origin == bookSourceUrl and origin not like '${BookType.localTag}%'
|
||||
and origin not like '${BookType.webDavTag}%'""")
|
||||
fun getAllUseBookSource(): List<BookSource>
|
||||
|
||||
@Query("SELECT * FROM books WHERE name = :name and origin = :origin")
|
||||
fun getBookByOrigin(name: String, origin: String): Book?
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookGroup
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.databinding.ActivityArrangeBookBinding
|
||||
import io.legado.app.databinding.DialogEditTextBinding
|
||||
import io.legado.app.help.DirectLinkUpload
|
||||
import io.legado.app.help.book.contains
|
||||
import io.legado.app.help.book.isLocal
|
||||
import io.legado.app.help.config.AppConfig
|
||||
@@ -31,6 +33,7 @@ import io.legado.app.lib.theme.primaryTextColor
|
||||
import io.legado.app.ui.book.group.GroupManageDialog
|
||||
import io.legado.app.ui.book.group.GroupSelectDialog
|
||||
import io.legado.app.ui.book.info.BookInfoActivity
|
||||
import io.legado.app.ui.file.HandleFileContract
|
||||
import io.legado.app.ui.widget.SelectActionBar
|
||||
import io.legado.app.ui.widget.dialog.WaitDialog
|
||||
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
|
||||
@@ -70,6 +73,23 @@ class BookshelfManageActivity :
|
||||
}
|
||||
private var books: List<Book>? = null
|
||||
private val waitDialog by lazy { WaitDialog(this) }
|
||||
private val exportDir = registerForActivityResult(HandleFileContract()) {
|
||||
it.uri?.let { uri ->
|
||||
alert(R.string.export_success) {
|
||||
if (uri.toString().isAbsUrl()) {
|
||||
setMessage(DirectLinkUpload.getSummary())
|
||||
}
|
||||
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.hint = getString(R.string.path)
|
||||
editView.setText(uri.toString())
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
sendToClip(uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
viewModel.groupId = intent.getLongExtra("groupId", -1)
|
||||
@@ -255,6 +275,17 @@ class BookshelfManageActivity :
|
||||
adapter.notifyItemRangeChanged(0, adapter.itemCount)
|
||||
}
|
||||
|
||||
R.id.menu_export_all_use_book_source -> viewModel.saveAllUseBookSourceToFile { file ->
|
||||
exportDir.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = HandleFileContract.FileData(
|
||||
"bookSource.json",
|
||||
file,
|
||||
"application/json"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
else -> if (item.groupId == R.id.menu_group) {
|
||||
viewModel.groupName = item.title.toString()
|
||||
upTitle()
|
||||
|
||||
@@ -14,7 +14,15 @@ import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.model.localBook.LocalBook
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.utils.FileUtils
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.stackTraceStr
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.writeToOutputStream
|
||||
import kotlinx.coroutines.delay
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
|
||||
class BookshelfManageViewModel(application: Application) : BaseViewModel(application) {
|
||||
@@ -50,6 +58,26 @@ class BookshelfManageViewModel(application: Application) : BaseViewModel(applica
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
fun saveAllUseBookSourceToFile(success: (file: File) -> Unit) {
|
||||
execute {
|
||||
val path = "${context.filesDir}/shareBookSource.json"
|
||||
FileUtils.delete(path)
|
||||
val file = FileUtils.createFileWithReplace(path)
|
||||
val sources = appDb.bookDao.getAllUseBookSource()
|
||||
FileOutputStream(file).use { out ->
|
||||
BufferedOutputStream(out, 64 * 1024).use {
|
||||
GSON.writeToOutputStream(it, sources)
|
||||
}
|
||||
}
|
||||
file
|
||||
}.onSuccess {
|
||||
success.invoke(it)
|
||||
}.onError {
|
||||
context.toastOnUi(it.stackTraceStr)
|
||||
}
|
||||
}
|
||||
|
||||
fun changeSource(books: List<Book>, source: BookSource) {
|
||||
batchChangeSourceCoroutine?.cancel()
|
||||
batchChangeSourceCoroutine = execute {
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_export_all_use_book_source"
|
||||
android:title="@string/export_all_use_book_source" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_open_book_info_by_click_title"
|
||||
android:checkable="true"
|
||||
|
||||
@@ -1130,4 +1130,5 @@
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="default_home_page">默认主页</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
@@ -1133,4 +1133,5 @@
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="default_home_page">默认主页</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
@@ -1133,4 +1133,5 @@
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="default_home_page">默认主页</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
@@ -1128,4 +1128,5 @@ Còn </string>
|
||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
</resources>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
@@ -1129,4 +1129,5 @@
|
||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
@@ -1131,4 +1131,5 @@
|
||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
@@ -1131,4 +1131,5 @@
|
||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
@@ -1133,4 +1133,5 @@
|
||||
<string name="export_wait">等待导出</string>
|
||||
<string name="default_home_page">默认主页</string>
|
||||
<string name="show_bookshelf_fast_scroller">显示快速滚动条</string>
|
||||
<string name="export_all_use_book_source">导出所有书的书源</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user