From 0f9e198f78f98f93e1e0acc5b8580c8bc5ac0ce7 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Mon, 9 May 2022 21:15:20 +0800 Subject: [PATCH] feat: add prompt when open local book --- .../ui/association/FileAssociationViewModel.kt | 16 ++++++++++++---- app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 3 +-- 8 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index 403412fd9..b45c7629d 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -4,13 +4,16 @@ 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.constant.AppPattern.bookFileRegex import io.legado.app.exception.NoStackTraceException +import io.legado.app.lib.dialogs.alert import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.isJson import io.legado.app.utils.printOnDebug import io.legado.app.utils.readText import java.io.File +import splitties.init.appCtx class FileAssociationViewModel(application: Application) : BaseAssociationViewModel(application) { val importBookLiveData = MutableLiveData() @@ -53,14 +56,19 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo importTextTocRule(content, finally) content.contains("name") && content.contains("url") -> importHttpTTS(content, finally) - else -> errorLiveData.postValue("格式不对") + else -> errorLiveData.postValue(appCtx.getString(R.string.wrong_format)) } } - fileName.matches(bookFileRegex) -> { - importBookLiveData.postValue(uri) + !fileName.matches(bookFileRegex) -> { + appCtx.alert(title = appCtx.getString(R.string.draw), message = appCtx.getString(R.string.file_not_supported, fileName)) { + okButton { + importBookLiveData.postValue(uri) + } + cancelButton() + } } else -> { - throw NoStackTraceException("$fileName 暂未支持的本地书籍格式(TXT/UMD/EPUB)") + importBookLiveData.postValue(uri) } } } else { diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 1c1ebb484..fe5df6c92 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -974,5 +974,6 @@ 输入验证码 验证码 超时毫秒数 + Continue to open although %1$s is not supported ? diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 02b599a14..353d069d9 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -977,5 +977,6 @@ 输入验证码 验证码 超时毫秒数 + Continue to open although %1$s is not supported ? diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index faba804f0..a48c48550 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -977,5 +977,6 @@ 输入验证码 验证码 超时毫秒数 + Continue to open although %1$s is not supported ? diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index c9262f925..7fc0a122c 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -974,5 +974,6 @@ 输入验证码 验证码 超时毫秒数 + 文件%1$s 不受支持,是否继续打开? diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0334fd0ab..e3268bd18 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -976,5 +976,6 @@ 输入验证码 验证码 超时毫秒数 + 文件%1$s 不受支持,是否继续打开? diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index f522e28bc..5e9a4d0c0 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -976,5 +976,6 @@ 输入验证码 验证码 超时毫秒数 + 文件%1$s 不受支持,是否继续打开? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4468bf740..d1b76d892 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -977,7 +977,6 @@ 输入验证码 验证码 超时毫秒数 - - + Continue to open although %1$s is not supported ?