From 751a886f19b15c911633eec59e1e8dcb34047e26 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 27 Mar 2021 16:25:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../association/ImportReplaceRuleViewModel.kt | 31 ------------------- .../association/ImportRssSourceViewModel.kt | 27 ---------------- 2 files changed, 58 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt index e5e29392f..a9a937114 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.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() @@ -21,31 +15,6 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { private val allRules = arrayListOf() - 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()) { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt index 06cf2da11..0db5f7af0 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt @@ -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(content)?.let { - allSources.addAll(it) - } - } - }.onSuccess { - comparisonSource() - } - } - fun importSource(text: String) { execute { val mText = text.trim()