mirror of
https://github.com/gedoor/legado.git
synced 2025-01-08 11:47:32 +08:00
优化
This commit is contained in:
parent
436628c3a8
commit
5f8d44818e
@ -276,6 +276,9 @@ interface BookSourceDao {
|
||||
@Query("select count(*) from book_sources")
|
||||
fun allCount(): Int
|
||||
|
||||
@Query("SELECT EXISTS(select 1 from book_sources where bookSourceUrl = :key)")
|
||||
fun has(key: String): Boolean
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg bookSource: BookSource)
|
||||
|
||||
|
@ -429,6 +429,10 @@ class BookInfoActivity :
|
||||
tvOrigin.setOnClickListener {
|
||||
viewModel.getBook()?.let { book ->
|
||||
if (book.isLocal) return@let
|
||||
if (!appDb.bookSourceDao.has(book.origin)) {
|
||||
toastOnUi(R.string.error_no_source)
|
||||
return@let
|
||||
}
|
||||
editSourceResult.launch {
|
||||
putExtra("sourceUrl", book.origin)
|
||||
}
|
||||
|
@ -73,8 +73,16 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
|
||||
kotlin.runCatching {
|
||||
WebBook.getBookInfoAwait(bookSource, book)
|
||||
}.onSuccess {
|
||||
it.order = appDb.bookDao.minOrder - 1
|
||||
it.save()
|
||||
val dbBook = appDb.bookDao.getBook(it.name, it.author)
|
||||
if (dbBook != null) {
|
||||
val toc = WebBook.getChapterListAwait(bookSource, it).getOrThrow()
|
||||
dbBook.migrateTo(it, toc)
|
||||
appDb.bookDao.insert(it)
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
} else {
|
||||
it.order = appDb.bookDao.minOrder - 1
|
||||
it.save()
|
||||
}
|
||||
successCount++
|
||||
addBookProgressLiveData.postValue(successCount)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user