书源兼容旧版

pull/1261/head
gedoor 3 years ago
parent 388d9bc5a2
commit e4c0af598b
  1. 1441
      app/schemas/io.legado.app.data.AppDatabase/36.json
  2. 29
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt

File diff suppressed because it is too large Load Diff

@ -5,9 +5,11 @@ import android.content.Intent
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient
import io.legado.app.help.storage.BookSourceAnalyzer import io.legado.app.help.storage.BookSourceAnalyzer
import io.legado.app.utils.getClipText import io.legado.app.help.storage.Restore
import io.legado.app.utils.toastOnUi import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { class BookSourceEditViewModel(application: Application) : BaseViewModel(application) {
@ -63,12 +65,31 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
fun importSource(text: String, finally: (source: BookSource) -> Unit) { fun importSource(text: String, finally: (source: BookSource) -> Unit) {
execute { execute {
val text1 = text.trim() importSource(text)
BookSourceAnalyzer.jsonToBookSource(text1)
}.onSuccess { }.onSuccess {
it?.let(finally) ?: context.toastOnUi("格式不对") it?.let(finally) ?: context.toastOnUi("格式不对")
}.onError { }.onError {
context.toastOnUi(it.localizedMessage ?: "Error") context.toastOnUi(it.localizedMessage ?: "Error")
} }
} }
suspend fun importSource(text: String): BookSource? {
return when {
text.isAbsUrl() -> {
val text1 = okHttpClient.newCallStrResponse { url(text) }.body
text1?.let { importSource(text1) }
}
text.isJsonArray() -> {
val items: List<Map<String, Any>> = Restore.jsonPath.parse(text).read("$")
val jsonItem = Restore.jsonPath.parse(items[0])
BookSourceAnalyzer.jsonToBookSource(jsonItem.jsonString())
}
text.isJsonObject() -> {
BookSourceAnalyzer.jsonToBookSource(text)
}
else -> {
null
}
}
}
} }
Loading…
Cancel
Save