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