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