优化
This commit is contained in:
@@ -276,6 +276,9 @@ interface BookSourceDao {
|
|||||||
@Query("select count(*) from book_sources")
|
@Query("select count(*) from book_sources")
|
||||||
fun allCount(): Int
|
fun allCount(): Int
|
||||||
|
|
||||||
|
@Query("SELECT EXISTS(select 1 from book_sources where bookSourceUrl = :key)")
|
||||||
|
fun has(key: String): Boolean
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insert(vararg bookSource: BookSource)
|
fun insert(vararg bookSource: BookSource)
|
||||||
|
|
||||||
|
|||||||
@@ -429,6 +429,10 @@ class BookInfoActivity :
|
|||||||
tvOrigin.setOnClickListener {
|
tvOrigin.setOnClickListener {
|
||||||
viewModel.getBook()?.let { book ->
|
viewModel.getBook()?.let { book ->
|
||||||
if (book.isLocal) return@let
|
if (book.isLocal) return@let
|
||||||
|
if (!appDb.bookSourceDao.has(book.origin)) {
|
||||||
|
toastOnUi(R.string.error_no_source)
|
||||||
|
return@let
|
||||||
|
}
|
||||||
editSourceResult.launch {
|
editSourceResult.launch {
|
||||||
putExtra("sourceUrl", book.origin)
|
putExtra("sourceUrl", book.origin)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,16 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
|
|||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
WebBook.getBookInfoAwait(bookSource, book)
|
WebBook.getBookInfoAwait(bookSource, book)
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
it.order = appDb.bookDao.minOrder - 1
|
val dbBook = appDb.bookDao.getBook(it.name, it.author)
|
||||||
it.save()
|
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++
|
successCount++
|
||||||
addBookProgressLiveData.postValue(successCount)
|
addBookProgressLiveData.postValue(successCount)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user