diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index 7e623bfcc..fd3f69951 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.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") fun getByNameAuthorEnable(name: String, author: String): List + @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 + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg searchBook: SearchBook): List diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 4d3176695..cc8554a7f 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -66,6 +66,7 @@ class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) adapter = CoverAdapter(requireContext()) recycler_view.adapter = adapter + viewModel.initData() } interface CallBack { diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 4e59d4d00..6c5fb759b 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -3,20 +3,34 @@ package io.legado.app.ui.changecover import android.app.Application import io.legado.app.App 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) { + private var searchPool = + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() var callBack: CallBack? = null var name: String = "" var author: String = "" fun initData() { 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 { var adapter: CoverAdapter } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index cccdd0e71..1b6a4e679 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -42,7 +42,6 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio execute { callBack?.changeSourceAdapter?.let { val books = searchBooks.toList() - books.sorted() val diffResult = DiffUtil.calculateDiff(DiffCallBack(it.getItems(), books)) withContext(Main) { synchronized(this) { @@ -130,12 +129,13 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } } - interface CallBack { - var changeSourceAdapter: ChangeSourceAdapter - } - override fun onCleared() { super.onCleared() searchPool.close() } + + interface CallBack { + var changeSourceAdapter: ChangeSourceAdapter + } + } \ No newline at end of file