pull/32/head
kunfei 5 years ago
parent c56ba47cfb
commit eb3bfd4db7
  1. 4
      app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt
  2. 24
      app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.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<ExploreShowViewModel>(R.layout.activity_explore_show),
ExploreShowAdapter.CallBack {
@ -38,6 +40,6 @@ class ExploreShowActivity : VMBaseActivity<ExploreShowViewModel>(R.layout.activi
}
override fun showBookInfo(bookUrl: String) {
startActivity<BookInfoActivity>(Pair("searchBookUrl", bookUrl))
}
}

@ -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<List<SearchBook>>()
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++
}
}
}

Loading…
Cancel
Save