fix: 换源数据

pull/95/head
kunfei 5 years ago
parent 8ca073faba
commit 8cf16178d4
  1. 3
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 25
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -28,6 +28,9 @@ interface SearchBookDao {
@Query("select * from searchBooks where name = :name and author = :author and origin in (select bookSourceUrl from book_sources where enabled = 1) order by originOrder")
fun getByNameAuthorEnable(name: String, author: String): List<SearchBook>
@Query("select * from searchBooks where name = :name and author = :author and originName like '%'||:key||'%' and origin in (select bookSourceUrl from book_sources where enabled = 1) order by originOrder")
fun getChangeSourceSearch(name: String, author: String, key: String): List<SearchBook>
@Query(
"""select * from searchBooks
where name = :name and author = :author and origin in (select bookSourceUrl from book_sources where enabled = 1)

@ -56,6 +56,16 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
}
}
private fun searchFinish(searchBook: SearchBook) {
App.db.searchBookDao().insert(searchBook)
if (screenKey.isEmpty()) {
searchBooks.add(searchBook)
} else if (searchBook.originName.contains(screenKey)) {
searchBooks.add(searchBook)
}
upAdapter()
}
fun search() {
task = execute {
searchStateData.postValue(true)
@ -74,9 +84,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
loadChapter(searchBook.toBook())
}
} else {
App.db.searchBookDao().insert(searchBook)
searchBooks.add(searchBook)
upAdapter()
searchFinish(searchBook)
}
return@onSuccess
}
@ -111,10 +119,8 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
it?.let { chapters ->
if (chapters.isNotEmpty()) {
book.latestChapterTitle = chapters.last().title
val searchBook = book.toSearchBook()
App.db.searchBookDao().insert(searchBook)
searchBooks.add(searchBook)
upAdapter()
val searchBook: SearchBook = book.toSearchBook()
searchFinish(searchBook)
}
}
}.onError {
@ -133,7 +139,10 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
if (key.isNullOrEmpty()) {
loadDbSearchBook()
} else {
App.db.searchBookDao()
val items = App.db.searchBookDao().getChangeSourceSearch(name, author, screenKey)
searchBooks.clear()
searchBooks.addAll(items)
upAdapter()
}
}
}

Loading…
Cancel
Save