From 03b7c3b6e7ae89d58affe9430fb3a0830e451273 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 27 Aug 2019 21:36:01 +0800 Subject: [PATCH] up --- .../legado/app/ui/changesource/ChangeSourceDialog.kt | 1 + .../app/ui/changesource/ChangeSourceViewModel.kt | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index 854532d17..4ff4b8838 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -62,6 +62,7 @@ class ChangeSourceDialog : DialogFragment(), initRecyclerView() initSearchView() viewModel.initData() + viewModel.search() } override fun onStart() { 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 df3041c6c..2cf667a29 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 @@ -10,6 +10,7 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.delay import kotlinx.coroutines.withContext import org.jetbrains.anko.debug @@ -18,6 +19,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio var curBookUrl = "" var name: String = "" var author: String = "" + var screenKey: String = "" private val searchBooks = linkedSetOf() fun initData() { @@ -25,7 +27,6 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio App.db.searchBookDao().getByNameAuthorEnable(name, author).let { searchBooks.addAll(it) upAdapter() - search() } } } @@ -50,6 +51,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio execute { val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { + delay(100) //task取消时自动取消 by (scope = this@execute) WebBook(item).searchBook(name, scope = this@execute) .timeout(30000L) @@ -93,9 +95,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio if (chapters.isNotEmpty()) { book.latestChapterTitle = chapters.last().title val searchBook = book.toSearchBook() + App.db.searchBookDao().insert(searchBook) searchBooks.add(searchBook) upAdapter() - App.db.searchBookDao().insert(searchBook) } } }.onError { @@ -105,9 +107,13 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } } + /** + * 筛选 + */ fun screen(key: String?) { + screenKey = key ?: "" if (key.isNullOrEmpty()) { - + initData() } else { }