格式化代码
This commit is contained in:
@@ -10,6 +10,7 @@ object AppPattern {
|
||||
|
||||
//匹配格式化后的图片格式
|
||||
val imgPattern: Pattern = Pattern.compile("<img[^>]*src=\"([^\"]*(?:\"[^>]+\\})?)\"[^>]*>")
|
||||
|
||||
//dataURL图片类型
|
||||
val dataUriRegex = Regex("data:.*?;base64,(.*)")
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# 存储数据用
|
||||
|
||||
* dao 数据操作
|
||||
* entities 数据模型
|
||||
* \Book 书籍信息
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
package io.legado.app.help
|
||||
|
||||
|
||||
@Suppress("RegExpRedundantEscape")
|
||||
object RuleComplete {
|
||||
// 需要补全
|
||||
private val needComplete =Regex(
|
||||
"""(?<!(@|/|^|[|%&]{2})(attr|text|ownText|textNodes|href|content|html|alt|all|value|src)(\(\))?)(?<seq>\&{2}|%%|\|{2}|$)""")
|
||||
private val needComplete = Regex(
|
||||
"""(?<!(@|/|^|[|%&]{2})(attr|text|ownText|textNodes|href|content|html|alt|all|value|src)(\(\))?)(?<seq>\&{2}|%%|\|{2}|$)"""
|
||||
)
|
||||
|
||||
// 不能补全 存在js/json/{{xx}}的复杂情况
|
||||
private val notComplete = Regex("""^:|^##|\{\{|@js:|<js>|@Json:|\$\.""")
|
||||
|
||||
// 修正从图片获取信息
|
||||
private val fixImgInfo = Regex("""(?<=(^|tag\.|[\+/@>~| &]))img(?<at>(\[@?.+\]|\.[-\w]+)?)[@/]+text(\(\))?(?<seq>\&{2}|%%|\|{2}|$)""")
|
||||
private val fixImgInfo =
|
||||
Regex("""(?<=(^|tag\.|[\+/@>~| &]))img(?<at>(\[@?.+\]|\.[-\w]+)?)[@/]+text(\(\))?(?<seq>\&{2}|%%|\|{2}|$)""")
|
||||
|
||||
private val isXpath= Regex("^//|^@Xpath:")
|
||||
private val isXpath = Regex("^//|^@Xpath:")
|
||||
|
||||
/**
|
||||
* 对简单规则进行补全,简化部分书源规则的编写
|
||||
@@ -31,33 +34,38 @@ object RuleComplete {
|
||||
preRule: String? = null,
|
||||
type: Int = 1
|
||||
): String? {
|
||||
if (rules.isNullOrEmpty()||rules.contains(notComplete) || preRule?.contains(notComplete) ?: false){
|
||||
if (rules.isNullOrEmpty() || rules.contains(notComplete) || preRule?.contains(notComplete) == true) {
|
||||
return rules
|
||||
}
|
||||
|
||||
/** 尾部##分割的正则或由,分割的参数 */
|
||||
val tailStr: String
|
||||
|
||||
/** 分割字符 */
|
||||
val splitStr:String
|
||||
val splitStr: String
|
||||
|
||||
/** 用于获取文字时添加的规则 */
|
||||
val textRule: String
|
||||
|
||||
/** 用于获取链接时添加的规则 */
|
||||
val linkRule: String
|
||||
|
||||
/** 用于获取图片时添加的规则 */
|
||||
val imgRule: String
|
||||
|
||||
/** 用于获取图片alt属性时添加的规则 */
|
||||
val imgText: String
|
||||
|
||||
// 分离尾部规则
|
||||
val regexSplit=rules.split("""##|,\{""".toRegex(),2)
|
||||
val cleanedRule=regexSplit[0]
|
||||
if (regexSplit.size>1){
|
||||
splitStr="""##|,\{""".toRegex().find(rules)?.value ?: ""
|
||||
val regexSplit = rules.split("""##|,\{""".toRegex(), 2)
|
||||
val cleanedRule = regexSplit[0]
|
||||
if (regexSplit.size > 1) {
|
||||
splitStr = """##|,\{""".toRegex().find(rules)?.value ?: ""
|
||||
tailStr = splitStr + regexSplit[1]
|
||||
}else{
|
||||
} else {
|
||||
tailStr = ""
|
||||
}
|
||||
if (cleanedRule.contains(isXpath)){
|
||||
if (cleanedRule.contains(isXpath)) {
|
||||
textRule = "//text()\${seq}"
|
||||
linkRule = "//@href\${seq}"
|
||||
imgRule = "//@src\${seq}"
|
||||
|
||||
@@ -173,7 +173,7 @@ public final class OkhttpCacheDataSource implements DataSource {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Factory setDefaultRequestProperties(Map<String, String> defaultRequestProperties){
|
||||
public Factory setDefaultRequestProperties(Map<String, String> defaultRequestProperties) {
|
||||
if (this.upstreamDataSourceFactory != null) {
|
||||
this.upstreamDataSourceFactory.setDefaultRequestProperties(defaultRequestProperties);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ val okHttpClient: OkHttpClient by lazy {
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.writeTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
.callTimeout(60,TimeUnit.SECONDS)
|
||||
.callTimeout(60, TimeUnit.SECONDS)
|
||||
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager)
|
||||
.retryOnConnectionFailure(true)
|
||||
.hostnameVerifier(SSLHelper.unsafeHostnameVerifier)
|
||||
|
||||
@@ -34,6 +34,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
|
||||
private var cpuAbi: String? = null
|
||||
private var md5: String
|
||||
var download = false
|
||||
|
||||
@Volatile
|
||||
private var cacheInstall = false
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# 放置一些copy过来的库
|
||||
|
||||
* dialogs 弹出框
|
||||
* icu4j 编码识别库
|
||||
* permission 权限申请库
|
||||
|
||||
@@ -11,6 +11,7 @@ import splitties.init.appCtx
|
||||
|
||||
object CheckSource {
|
||||
var keyword = "我的"
|
||||
|
||||
//校验设置
|
||||
var timeout = CacheManager.getLong("checkSourceTimeout") ?: 180000L
|
||||
var checkSearch = CacheManager.get("checkSearch")?.toBoolean() ?: true
|
||||
@@ -53,6 +54,10 @@ object CheckSource {
|
||||
if (checkInfo) checkItem = "$checkItem ${appCtx.getString(R.string.source_tab_info)}"
|
||||
if (checkCategory) checkItem = "$checkItem ${appCtx.getString(R.string.chapter_list)}"
|
||||
if (checkContent) checkItem = "$checkItem ${appCtx.getString(R.string.main_body)}"
|
||||
return appCtx.getString(R.string.check_source_config_summary, (timeout / 1000).toString(), checkItem)
|
||||
return appCtx.getString(
|
||||
R.string.check_source_config_summary,
|
||||
(timeout / 1000).toString(),
|
||||
checkItem
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ object Debug {
|
||||
if (showTime && debugTimeMap[sourceUrl] != null) {
|
||||
val time =
|
||||
debugTimeFormat.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!))
|
||||
printMsg = printMsg.replace(AppPattern.debugMessageSymbolRegex,"")
|
||||
printMsg = printMsg.replace(AppPattern.debugMessageSymbolRegex, "")
|
||||
|
||||
debugMessageMap[sourceUrl] = "$time $printMsg"
|
||||
}
|
||||
@@ -93,7 +93,8 @@ object Debug {
|
||||
fun updateFinalMessage(sourceUrl: String, state: String) {
|
||||
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
|
||||
val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!!
|
||||
debugTimeMap[sourceUrl] = if (state == "校验成功") spendingTime else CheckSource.timeout + spendingTime
|
||||
debugTimeMap[sourceUrl] =
|
||||
if (state == "校验成功") spendingTime else CheckSource.timeout + spendingTime
|
||||
val printTime = debugTimeFormat.format(Date(spendingTime))
|
||||
debugMessageMap[sourceUrl] = "$printTime $state"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# 放置一些模块类
|
||||
|
||||
* analyzeRule 书源规则解析
|
||||
* localBook 本地书籍解析
|
||||
* rss 订阅规则解析
|
||||
|
||||
@@ -181,7 +181,7 @@ class CheckSourceService : BaseService() {
|
||||
if (finalCheckMessage.isNotBlank()) throw NoStackTraceException(finalCheckMessage)
|
||||
}.timeout(CheckSource.timeout)
|
||||
.onError(searchCoroutine) {
|
||||
when(it) {
|
||||
when (it) {
|
||||
is TimeoutCancellationException -> source.addGroup("校验超时")
|
||||
is ScriptException, is WrappedException -> source.addGroup("js失效")
|
||||
!is NoStackTraceException -> source.addGroup("网站失效")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# android服务
|
||||
|
||||
* AudioPlayService 音频播放服务
|
||||
* CheckSourceService 书源检测服务
|
||||
* DownloadService 缓存服务
|
||||
|
||||
@@ -28,7 +28,8 @@ fun TimerDialog(state: MutableState<Boolean>, parent: View) {
|
||||
Card(Modifier.fillMaxWidth()) {
|
||||
Slider(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
value = timeMinute.value.toFloat(), onValueChange = {
|
||||
value = timeMinute.value.toFloat(),
|
||||
onValueChange = {
|
||||
timeMinute.value = it.toInt()
|
||||
AudioPlay.setTimer(it.toInt())
|
||||
},
|
||||
|
||||
@@ -45,7 +45,7 @@ abstract class BaseReadBookActivity :
|
||||
override val binding by viewBinding(ActivityBookReadBinding::inflate)
|
||||
override val viewModel by viewModels<ReadBookViewModel>()
|
||||
var bottomDialog = 0
|
||||
private val selectBookFolderResult = registerForActivityResult(HandleFileContract()){
|
||||
private val selectBookFolderResult = registerForActivityResult(HandleFileContract()) {
|
||||
it.uri?.let {
|
||||
ReadBook.book?.let { book ->
|
||||
viewModel.loadChapterList(book)
|
||||
|
||||
@@ -145,7 +145,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
drawImage(canvas, it, lineTop, lineBottom, isImageLine)
|
||||
} else {
|
||||
textPaint.color = textColor
|
||||
if(it.isSearchResult) {
|
||||
if (it.isSearchResult) {
|
||||
textPaint.color = context.accentColor
|
||||
}
|
||||
canvas.drawText(it.charData, it.start, lineBase, textPaint)
|
||||
|
||||
@@ -49,7 +49,10 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
||||
else -> chapter.title
|
||||
}
|
||||
mContent = contentProcessor!!.getContent(
|
||||
book, chapter, chapterContent, chineseConvert = false, reSegment = false, useReplace = false
|
||||
book, chapter, chapterContent,
|
||||
chineseConvert = false,
|
||||
reSegment = false,
|
||||
useReplace = false
|
||||
).joinToString("")
|
||||
}
|
||||
val positions = searchPosition(query)
|
||||
@@ -90,7 +93,11 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
|
||||
return position
|
||||
}
|
||||
|
||||
private fun getResultAndQueryIndex(content: String, queryIndexInContent: Int, query: String): Pair<Int, String> {
|
||||
private fun getResultAndQueryIndex(
|
||||
content: String,
|
||||
queryIndexInContent: Int,
|
||||
query: String
|
||||
): Pair<Int, String> {
|
||||
// 左右移动20个字符,构建关键词周边文字,在搜索结果里显示
|
||||
// todo: 判断段落,只在关键词所在段落内分割
|
||||
// todo: 利用标点符号分割完整的句
|
||||
|
||||
@@ -35,6 +35,7 @@ data class SearchResult(
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.colorTextForHtml(textColor: String) = "<font color=#${textColor}>$this</font>"
|
||||
private fun String.colorTextForHtml(textColor: String) =
|
||||
"<font color=#${textColor}>$this</font>"
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import splitties.views.onClick
|
||||
class CheckSourceConfig : BaseDialogFragment(R.layout.dialog_check_source_config) {
|
||||
|
||||
private val binding by viewBinding(DialogCheckSourceConfigBinding::bind)
|
||||
|
||||
//允许的最小超时时间,秒
|
||||
private val minTimeout = 0L
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ class DictViewModel(application: Application) : BaseViewModel(application) {
|
||||
var dictHtmlData: MutableLiveData<String> = MutableLiveData()
|
||||
|
||||
fun dict(word: String) {
|
||||
if(isChinese(word)){
|
||||
if (isChinese(word)) {
|
||||
baiduDict(word)
|
||||
}else{
|
||||
} else {
|
||||
haiciDict(word)
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,10 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
|
||||
* @param saveTime 保存的时间,单位:秒
|
||||
*/
|
||||
fun put(key: String, value: String, saveTime: Int) {
|
||||
if (saveTime == 0) put(key, value) else put(key, Utils.newStringWithDateInfo(saveTime, value))
|
||||
if (saveTime == 0) put(key, value) else put(
|
||||
key,
|
||||
Utils.newStringWithDateInfo(saveTime, value)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +248,8 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
|
||||
* @param saveTime 保存的时间,单位:秒
|
||||
*/
|
||||
fun put(key: String, value: ByteArray, saveTime: Int) {
|
||||
if (saveTime == 0) put(key, value) else put(key, Utils.newByteArrayWithDateInfo(saveTime, value))
|
||||
if (saveTime == 0) put(key, value)
|
||||
else put(key, Utils.newByteArrayWithDateInfo(saveTime, value))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -327,6 +327,7 @@ fun Context.openFileUri(uri: Uri, type: String? = null) {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val Context.isWifiConnect: Boolean
|
||||
get() {
|
||||
val info = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
|
||||
|
||||
Reference in New Issue
Block a user