pull/32/head
kunfei 5 years ago
parent 184142c35c
commit 091755b50d
  1. 13
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.model.WebBook
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import org.jetbrains.anko.debug
@ -66,6 +67,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
}
private fun loadBookInfo(book: Book) {
execute {
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getBookInfo(book, this)
.onSuccess {
@ -75,23 +77,28 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
}
} ?: debug { context.getString(R.string.error_no_source) }
}
}
private fun loadChapter(book: Book) {
execute {
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getChapterList(book, this)
.onSuccess(Dispatchers.IO) {
it?.map { chapter ->
book.latestChapterTitle = chapter.title
.onSuccess(IO) {
it?.let { chapters ->
if (chapters.isNotEmpty()) {
book.latestChapterTitle = chapters.last().title
val searchBook = book.toSearchBook()
searchBooks.add(searchBook)
upAdapter()
App.db.searchBookDao().insert(searchBook)
}
}
}.onError {
debug { context.getString(R.string.error_get_chapter_list) }
}
} ?: debug { R.string.error_no_source }
}
}
fun screen(key: String?) {
if (key.isNullOrEmpty()) {

Loading…
Cancel
Save