|
|
@ -1,12 +1,16 @@ |
|
|
|
package io.legado.app.ui.association |
|
|
|
package io.legado.app.ui.association |
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application |
|
|
|
import android.app.Application |
|
|
|
|
|
|
|
import androidx.core.net.toUri |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.help.config.ReadBookConfig |
|
|
|
import io.legado.app.help.config.ReadBookConfig |
|
|
|
import io.legado.app.help.http.newCallResponseBody |
|
|
|
import io.legado.app.help.http.newCallResponseBody |
|
|
|
import io.legado.app.help.http.okHttpClient |
|
|
|
import io.legado.app.help.http.okHttpClient |
|
|
|
import io.legado.app.help.http.text |
|
|
|
import io.legado.app.help.http.text |
|
|
|
|
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
|
|
|
|
import io.legado.app.utils.externalFiles |
|
|
|
import okhttp3.MediaType.Companion.toMediaType |
|
|
|
import okhttp3.MediaType.Companion.toMediaType |
|
|
|
|
|
|
|
import splitties.init.appCtx |
|
|
|
|
|
|
|
|
|
|
|
class OnLineImportViewModel(app: Application) : BaseAssociationViewModel(app) { |
|
|
|
class OnLineImportViewModel(app: Application) : BaseAssociationViewModel(app) { |
|
|
|
|
|
|
|
|
|
|
@ -72,8 +76,18 @@ class OnLineImportViewModel(app: Application) : BaseAssociationViewModel(app) { |
|
|
|
importReadConfig(rs.bytes(), finally) |
|
|
|
importReadConfig(rs.bytes(), finally) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
val json = rs.text("utf-8") |
|
|
|
val inputStream = rs.byteStream() |
|
|
|
importJson(json) |
|
|
|
val file = FileUtils.createFileIfNotExist( |
|
|
|
|
|
|
|
appCtx.externalFiles, |
|
|
|
|
|
|
|
"book_cache", |
|
|
|
|
|
|
|
"scheme_import_cache.json" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
file.outputStream().use { out -> |
|
|
|
|
|
|
|
inputStream.use { |
|
|
|
|
|
|
|
it.copyTo(out) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
importJson(file.toUri()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|