pull/783/head
gedoor 4 years ago
parent f954dd20b9
commit c43b9b2b07
  1. 14
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -72,6 +72,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
bookMap["name"] = it.name
bookMap["author"] = it.author
bookMap["bookUrl"] = it.bookUrl
bookMap["coverUrl"] = it.coverUrl
bookMap["tocUrl"] = it.tocUrl
bookMap["kind"] = it.kind
bookMap["intro"] = it.getDisplayIntro()
@ -88,16 +89,19 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun importBookshelf(str: String, groupId: Long) {
execute {
val text = str.trim()
if (text.isAbsUrl()) {
when {
text.isAbsUrl() -> {
RxHttp.get(text).toText().await().let {
importBookshelf(it, groupId)
}
} else if (text.isJsonArray()) {
}
text.isJsonArray() -> {
GSON.fromJsonArray<Map<String, String?>>(text)?.forEach {
val book = Book(
bookUrl = it["bookUrl"] ?: "",
name = it["name"] ?: "",
author = it["author"] ?: "",
coverUrl = it["coverUrl"],
tocUrl = it["tocUrl"] ?: "",
kind = it["kind"],
intro = it["intro"] ?: "",
@ -107,11 +111,15 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
if (groupId > 0) {
book.group = groupId
}
if (App.db.bookDao.getBook(book.name, book.author) == null) {
App.db.bookDao.insert(book)
}
} else {
}
}
else -> {
throw Exception("格式不对")
}
}
}.onError {
toast(it.localizedMessage ?: "ERROR")
}

Loading…
Cancel
Save