From eb3bfd4db7ad0dfa6fe551d642044909df932f52 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Sep 2019 20:40:49 +0800 Subject: [PATCH] up --- .../app/ui/explore/ExploreShowActivity.kt | 4 +++- .../app/ui/explore/ExploreShowViewModel.kt | 24 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt index 695d9ac68..577e57682 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt @@ -8,8 +8,10 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.SearchBook +import io.legado.app.ui.bookinfo.BookInfoActivity import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_explore_show.* +import org.jetbrains.anko.startActivity class ExploreShowActivity : VMBaseActivity(R.layout.activity_explore_show), ExploreShowAdapter.CallBack { @@ -38,6 +40,6 @@ class ExploreShowActivity : VMBaseActivity(R.layout.activi } override fun showBookInfo(bookUrl: String) { - + startActivity(Pair("searchBookUrl", bookUrl)) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt index b3d692ca3..7aa89da91 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt @@ -8,25 +8,35 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.model.WebBook +import kotlinx.coroutines.Dispatchers.IO class ExploreShowViewModel(application: Application) : BaseViewModel(application) { val booksData = MutableLiveData>() - var bookSource: BookSource? = null - var page = 1 + private var bookSource: BookSource? = null + private var exploreUrl: String? = null + private var page = 1 fun initData(intent: Intent) { execute { val sourceUrl = intent.getStringExtra("sourceUrl") - val exploreUrl = intent.getStringExtra("exploreUrl") + exploreUrl = intent.getStringExtra("exploreUrl") if (bookSource == null) { bookSource = App.db.bookSourceDao().getBookSource(sourceUrl) } - bookSource?.let { - WebBook(it).exploreBook(exploreUrl, page, this) - .onSuccess { searchBooks -> + explore() + } + } + + fun explore() { + bookSource?.let { source -> + exploreUrl?.let { url -> + WebBook(source).exploreBook(url, page, this) + .onSuccess(IO) { searchBooks -> searchBooks?.let { - booksData.value = searchBooks + booksData.postValue(searchBooks) + App.db.searchBookDao().insert(*searchBooks.toTypedArray()) + page++ } } }