mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
feat:使用阅读打开文件时检查后缀
This commit is contained in:
@@ -21,6 +21,9 @@ object AppPattern {
|
||||
//书源调试信息中的各种符号
|
||||
val debugMessageSymbolRegex = Regex("[⇒◇┌└≡]")
|
||||
|
||||
//本地书籍支持类型
|
||||
val bookFileRegex = Regex("(?i).*\\.(txt|epub|umd)")
|
||||
|
||||
/**
|
||||
* 所有标点
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user