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