From b7ac1f4be34427c3bf5ffe1f0808e2331f2c92ed Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 12 Aug 2020 15:49:13 +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 --- .../app/ui/association/ImportBookSourceActivity.kt | 4 ++-- .../ui/association/ImportBookSourceViewModel.kt | 14 ++++++-------- .../ui/association/ImportReplaceRuleViewModel.kt | 6 ++++-- .../app/ui/association/ImportRssSourceActivity.kt | 4 ++-- .../app/ui/association/ImportRssSourceViewModel.kt | 3 ++- app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index 570d65af4..f1d1b4a66 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -78,7 +78,7 @@ class ImportBookSourceActivity : VMBaseActivity( } else -> { rotate_loading.hide() - toast("格式不对") + toast(R.string.wrong_format) finish() } } @@ -86,7 +86,7 @@ class ImportBookSourceActivity : VMBaseActivity( } private fun errorDialog(msg: String) { - alert("导入出错", msg) { + alert(getString(R.string.error), msg) { okButton { } }.show().applyTint().setOnDismissListener { finish() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index 662d6ff70..babcd269c 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -6,14 +6,13 @@ import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData import com.jayway.jsonpath.JsonPath import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.BookSource import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.Restore import io.legado.app.utils.* -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext import java.io.File class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { @@ -42,12 +41,11 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { if (content != null) { importSource(content) } else { - withContext(Dispatchers.Main) { - errorLiveData.postValue("打开文件出错") - } + errorLiveData.postValue(context.getString(R.string.error_read_file)) } }.onError { - errorLiveData.postValue(it.localizedMessage ?: "打开文件出错") + it.printStackTrace() + errorLiveData.postValue(context.getString(R.string.error_read_file)) } } @@ -80,7 +78,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { text1.isAbsUrl() -> { importSourceUrl(text1) } - else -> throw Exception("格式不对") + else -> throw Exception(context.getString(R.string.wrong_format)) } }.onError { it.printStackTrace() @@ -93,7 +91,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { private fun importSourceUrl(url: String) { HttpHelper.simpleGet(url, "UTF-8").let { body -> if (body == null) { - throw Exception("访问网站失败") + throw Exception(context.getString(R.string.error_get_data)) } val items: List> = Restore.jsonPath.parse(body).read("$") for (item in items) { 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 d9f43fc8f..960bafa9b 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 @@ -4,6 +4,7 @@ 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.http.HttpHelper @@ -36,10 +37,11 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { if (content != null) { import(content) } else { - errorLiveData.postValue("打开文件出错") + errorLiveData.postValue(context.getString(R.string.error_read_file)) } }.onError { - errorLiveData.postValue(it.localizedMessage ?: "打开文件出错") + it.printStackTrace() + errorLiveData.postValue(context.getString(R.string.error_read_file)) } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt index bbeed0b2d..e0fb6bc63 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt @@ -78,7 +78,7 @@ class ImportRssSourceActivity : VMBaseActivity( } else -> { rotate_loading.hide() - toast("格式不对") + toast(R.string.wrong_format) finish() } } @@ -86,7 +86,7 @@ class ImportRssSourceActivity : VMBaseActivity( } private fun errorDialog(msg: String) { - alert("导入出错", msg) { + alert(getString(R.string.error), msg) { okButton { } }.show().applyTint().setOnDismissListener { finish() 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 7a1a82338..8b6baae29 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 @@ -6,6 +6,7 @@ import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData import com.jayway.jsonpath.JsonPath import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource import io.legado.app.help.http.HttpHelper @@ -76,7 +77,7 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { text1.isAbsUrl() -> { importSourceUrl(text1) } - else -> throw Exception("格式不对") + else -> throw Exception(context.getString(R.string.wrong_format)) } }.onError { errorLiveData.postValue("ImportError:${it.localizedMessage}") diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 92c60043d..68413189b 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -739,4 +739,6 @@ 夜间底栏不能太亮 强调色不能和背景颜色相似 强调色不能和文字颜色相似 + 格式不对 + 错误 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 9152d604e..8e48622e5 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -739,5 +739,7 @@ 夜间底栏不能太亮 强调色不能和背景颜色相似 强调色不能和文字颜色相似 + 格式不对 + 错误 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index a3d7e28ff..ceed039ae 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -739,4 +739,6 @@ 夜间底栏不能太亮 强调色不能和背景颜色相似 强调色不能和文字颜色相似 + 格式不对 + 错误 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4ee8a7719..6475b1f22 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -740,5 +740,7 @@ 夜间底栏不能太亮 强调色不能和背景颜色相似 强调色不能和文字颜色相似 + 格式不对 + 错误 \ No newline at end of file