pull/84/head
kunfei 5 years ago
parent 207d18340f
commit 08ce86ba40
  1. 28
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -38,6 +38,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
} }
fun addBookByUrl(bookUrls: String) { fun addBookByUrl(bookUrls: String) {
var successCount = 0
execute { execute {
var hasBookUrlPattern: List<BookSource>? = null var hasBookUrlPattern: List<BookSource>? = null
val urls = bookUrls.split("\n") val urls = bookUrls.split("\n")
@ -59,17 +60,30 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
} }
} }
source?.let { bookSource -> source?.let { bookSource ->
val book = Book(bookUrl = bookUrl) val book = Book(
WebBook(bookSource).getBookInfo(book, this) bookUrl = bookUrl,
.onSuccess(IO) { origin = bookSource.bookSourceUrl,
it?.let { book -> originName = bookSource.bookSourceName
App.db.bookDao().insert(book) )
suspend {
WebBook(bookSource).getBookInfo(book, this)
.onSuccess(IO) {
it?.let { book ->
App.db.bookDao().insert(book)
successCount++
}
}.onError {
throw Exception(it.localizedMessage)
} }
} }
} }
} }
}.onSuccess { }.onSuccess {
toast(R.string.success) if (successCount > 0) {
toast(R.string.success)
} else {
toast("ERROR")
}
}.onError { }.onError {
toast(it.localizedMessage ?: "ERROR") toast(it.localizedMessage ?: "ERROR")
} }

Loading…
Cancel
Save