From 91810dfecfb96ddffac21edcdaf54ea62bee7726 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 25 Mar 2022 07:11:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BD=BF=E7=94=A8=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E6=89=93=E5=BC=80=E6=96=87=E4=BB=B6=E6=97=B6=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/AppPattern.kt | 3 +++ .../legado/app/ui/association/FileAssociationViewModel.kt | 6 ++++-- .../java/io/legado/app/ui/book/local/ImportBookViewModel.kt | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/AppPattern.kt b/app/src/main/java/io/legado/app/constant/AppPattern.kt index 258f30680..c9ed09ac0 100644 --- a/app/src/main/java/io/legado/app/constant/AppPattern.kt +++ b/app/src/main/java/io/legado/app/constant/AppPattern.kt @@ -21,6 +21,9 @@ object AppPattern { //书源调试信息中的各种符号 val debugMessageSymbolRegex = Regex("[⇒◇┌└≡]") + //本地书籍支持类型 + val bookFileRegex = Regex("(?i).*\\.(txt|epub|umd)") + /** * 所有标点 */ 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 a0ec71b1e..85ac06534 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,12 +4,12 @@ import android.app.Application import android.net.Uri import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData +import io.legado.app.constant.AppPattern.bookFileRegex import io.legado.app.exception.NoStackTraceException 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 class FileAssociationViewModel(application: Application) : BaseAssociationViewModel(application) { @@ -48,8 +48,10 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo importHttpTTS(content, finally) else -> errorLiveData.postValue("格式不对") } - } else { + } else if (uri.toString().matches(bookFileRegex)) { importBookLiveData.postValue(uri) + } else { + throw NoStackTraceException("暂未支持的本地书籍格式(TXT/UMD/EPUB)") } } else { onLineImportLive.postValue(uri) diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt index 5efef485b..22a1ca00b 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt @@ -4,6 +4,7 @@ import android.app.Application import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppPattern.bookFileRegex import io.legado.app.constant.PreferKey import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.* @@ -19,9 +20,7 @@ import kotlinx.coroutines.withContext import java.io.File import java.util.* - class ImportBookViewModel(application: Application) : BaseViewModel(application) { - private val bookFileRegex = Regex("(?i).*\\.(txt|epub|umd)") var sort = context.getPrefInt(PreferKey.localBookImportSort) var dataCallback: DataCallback? = null var dataFlowStart: (() -> Unit)? = null