pull/915/head
gedoor 4 years ago
parent 2b891ccf2b
commit 751a886f19
  1. 31
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt
  2. 27
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt

@ -1,19 +1,13 @@
package io.legado.app.ui.association
import android.app.Application
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.storage.OldReplace
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.readText
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toText
import java.io.File
class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) {
val errorLiveData = MutableLiveData<String>()
@ -21,31 +15,6 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) {
private val allRules = arrayListOf<ReplaceRule>()
fun importFromFilePath(path: String) {
execute {
val content = if (path.isContentScheme()) {
//在前面被解码了,如果不进行编码,中文会无法识别
val newPath = Uri.encode(path, ":/.")
DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context)
} else {
val file = File(path)
if (file.exists()) {
file.readText()
} else {
null
}
}
if (content != null) {
import(content)
} else {
errorLiveData.postValue(context.getString(R.string.error_read_file))
}
}.onError {
it.printStackTrace()
errorLiveData.postValue(context.getString(R.string.error_read_file))
}
}
fun import(text: String) {
execute {
if (text.isAbsUrl()) {

@ -1,8 +1,6 @@
package io.legado.app.ui.association
import android.app.Application
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath
import io.legado.app.R
@ -15,7 +13,6 @@ import io.legado.app.help.storage.Restore
import io.legado.app.utils.*
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toText
import java.io.File
class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
var groupName: String? = null
@ -70,30 +67,6 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
}
}
fun importSourceFromFilePath(path: String) {
execute {
val content = if (path.isContentScheme()) {
//在前面被解码了,如果不进行编码,中文会无法识别
val newPath = Uri.encode(path, ":/.")
DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context)
} else {
val file = File(path)
if (file.exists()) {
file.readText()
} else {
null
}
}
if (null != content) {
GSON.fromJsonArray<RssSource>(content)?.let {
allSources.addAll(it)
}
}
}.onSuccess {
comparisonSource()
}
}
fun importSource(text: String) {
execute {
val mText = text.trim()

Loading…
Cancel
Save