Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Nov 7, 2024
1 parent 436628c commit 5f8d448
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 5f8d448

Please sign in to comment.