pull/84/head
kunfei 5 years ago
parent 2435993916
commit 5e754a3130
  1. 8
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 1
      app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt
  3. 18
      app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt
  4. 10
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -28,6 +28,14 @@ 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") @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> fun getByNameAuthorEnable(name: String, author: String): List<SearchBook>
@Query(
"""select * from searchBooks
where name = :name and author = :author and origin in (select bookSourceUrl from book_sources where enabled = 1)
and coverUrl is not null and coverUrl <> ''
order by originOrder"""
)
fun getEnableHasCover(name: String, author: String): List<SearchBook>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg searchBook: SearchBook): List<Long> fun insert(vararg searchBook: SearchBook): List<Long>

@ -66,6 +66,7 @@ class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack {
recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) recycler_view.layoutManager = GridLayoutManager(requireContext(), 3)
adapter = CoverAdapter(requireContext()) adapter = CoverAdapter(requireContext())
recycler_view.adapter = adapter recycler_view.adapter = adapter
viewModel.initData()
} }
interface CallBack { interface CallBack {

@ -3,18 +3,32 @@ package io.legado.app.ui.changecover
import android.app.Application import android.app.Application
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.help.AppConfig
import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.Executors
class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { class ChangeCoverViewModel(application: Application) : BaseViewModel(application) {
private var searchPool =
Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher()
var callBack: CallBack? = null var callBack: CallBack? = null
var name: String = "" var name: String = ""
var author: String = "" var author: String = ""
fun initData() { fun initData() {
execute { execute {
App.db.searchBookDao().getByNameAuthorEnable(name, author).let { App.db.searchBookDao().getEnableHasCover(name, author).let {
callBack?.adapter?.setItems(it)
}
}
} }
fun search() {
} }
override fun onCleared() {
super.onCleared()
searchPool.close()
} }
interface CallBack { interface CallBack {

@ -42,7 +42,6 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
execute { execute {
callBack?.changeSourceAdapter?.let { callBack?.changeSourceAdapter?.let {
val books = searchBooks.toList() val books = searchBooks.toList()
books.sorted()
val diffResult = DiffUtil.calculateDiff(DiffCallBack(it.getItems(), books)) val diffResult = DiffUtil.calculateDiff(DiffCallBack(it.getItems(), books))
withContext(Main) { withContext(Main) {
synchronized(this) { synchronized(this) {
@ -130,12 +129,13 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
} }
} }
interface CallBack {
var changeSourceAdapter: ChangeSourceAdapter
}
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
searchPool.close() searchPool.close()
} }
interface CallBack {
var changeSourceAdapter: ChangeSourceAdapter
}
} }
Loading…
Cancel
Save