pull/525/head
gedoor 4 years ago
parent 39286d296d
commit 87693d4e3b
  1. 16
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  2. 16
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt

@ -81,23 +81,23 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
fun importSource(text: String) { fun importSource(text: String) {
execute { execute {
val text1 = text.trim() val mText = text.trim()
when { when {
text1.isJsonObject() -> { mText.isJsonObject() -> {
val json = JsonPath.parse(text1) val json = JsonPath.parse(mText)
val urls = json.read<List<String>>("$.sourceUrls") val urls = json.read<List<String>>("$.sourceUrls")
if (!urls.isNullOrEmpty()) { if (!urls.isNullOrEmpty()) {
urls.forEach { urls.forEach {
importSourceUrl(it) importSourceUrl(it)
} }
} else { } else {
OldRule.jsonToBookSource(text1)?.let { OldRule.jsonToBookSource(mText)?.let {
allSources.add(it) allSources.add(it)
} }
} }
} }
text1.isJsonArray() -> { mText.isJsonArray() -> {
val items: List<Map<String, Any>> = Restore.jsonPath.parse(text1).read("$") val items: List<Map<String, Any>> = Restore.jsonPath.parse(mText).read("$")
for (item in items) { for (item in items) {
val jsonItem = Restore.jsonPath.parse(item) val jsonItem = Restore.jsonPath.parse(item)
OldRule.jsonToBookSource(jsonItem.jsonString())?.let { OldRule.jsonToBookSource(jsonItem.jsonString())?.let {
@ -105,8 +105,8 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
} }
} }
} }
text1.isAbsUrl() -> { mText.isAbsUrl() -> {
importSourceUrl(text1) importSourceUrl(mText)
} }
else -> throw Exception(context.getString(R.string.wrong_format)) else -> throw Exception(context.getString(R.string.wrong_format))
} }

@ -77,23 +77,23 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
fun importSource(text: String) { fun importSource(text: String) {
execute { execute {
val text1 = text.trim() val mText = text.trim()
when { when {
text1.isJsonObject() -> { mText.isJsonObject() -> {
val json = JsonPath.parse(text1) val json = JsonPath.parse(mText)
val urls = json.read<List<String>>("$.sourceUrls") val urls = json.read<List<String>>("$.sourceUrls")
if (!urls.isNullOrEmpty()) { if (!urls.isNullOrEmpty()) {
urls.forEach { urls.forEach {
importSourceUrl(it) importSourceUrl(it)
} }
} else { } else {
GSON.fromJsonArray<RssSource>(text1)?.let { GSON.fromJsonArray<RssSource>(mText)?.let {
allSources.addAll(it) allSources.addAll(it)
} }
} }
} }
text1.isJsonArray() -> { mText.isJsonArray() -> {
val items: List<Map<String, Any>> = Restore.jsonPath.parse(text1).read("$") val items: List<Map<String, Any>> = Restore.jsonPath.parse(mText).read("$")
for (item in items) { for (item in items) {
val jsonItem = Restore.jsonPath.parse(item) val jsonItem = Restore.jsonPath.parse(item)
GSON.fromJsonObject<RssSource>(jsonItem.jsonString())?.let { GSON.fromJsonObject<RssSource>(jsonItem.jsonString())?.let {
@ -101,8 +101,8 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
} }
} }
} }
text1.isAbsUrl() -> { mText.isAbsUrl() -> {
importSourceUrl(text1) importSourceUrl(mText)
} }
else -> throw Exception(context.getString(R.string.wrong_format)) else -> throw Exception(context.getString(R.string.wrong_format))
} }

Loading…
Cancel
Save