mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -146,30 +146,31 @@ class ContentProcessor private constructor(
|
||||
effectiveReplaceRules = arrayListOf()
|
||||
mContent = mContent.lines().joinToString("\n") { it.trim() }
|
||||
getContentReplaceRules().forEach { item ->
|
||||
if (item.pattern.isNotEmpty()) {
|
||||
try {
|
||||
val tmp = if (item.isRegex) {
|
||||
mContent.replace(
|
||||
item.pattern.toRegex(),
|
||||
item.replacement,
|
||||
item.getValidTimeoutMillisecond()
|
||||
)
|
||||
} else {
|
||||
mContent.replace(item.pattern, item.replacement)
|
||||
}
|
||||
if (mContent != tmp) {
|
||||
effectiveReplaceRules.add(item)
|
||||
mContent = tmp
|
||||
}
|
||||
} catch (e: RegexTimeoutException) {
|
||||
item.isEnabled = false
|
||||
appDb.replaceRuleDao.update(item)
|
||||
mContent = item.name + e.stackTraceStr
|
||||
} catch (_: CancellationException) {
|
||||
} catch (e: Exception) {
|
||||
AppLog.put("替换净化: 规则 ${item.name}替换出错.\n${mContent}", e)
|
||||
appCtx.toastOnUi("替换净化: 规则 ${item.name}替换出错")
|
||||
if (item.pattern.isEmpty()) {
|
||||
return@forEach
|
||||
}
|
||||
try {
|
||||
val tmp = if (item.isRegex) {
|
||||
mContent.replace(
|
||||
item.pattern.toRegex(),
|
||||
item.replacement,
|
||||
item.getValidTimeoutMillisecond()
|
||||
)
|
||||
} else {
|
||||
mContent.replace(item.pattern, item.replacement)
|
||||
}
|
||||
if (mContent != tmp) {
|
||||
effectiveReplaceRules.add(item)
|
||||
mContent = tmp
|
||||
}
|
||||
} catch (e: RegexTimeoutException) {
|
||||
item.isEnabled = false
|
||||
appDb.replaceRuleDao.update(item)
|
||||
mContent = item.name + e.stackTraceStr
|
||||
} catch (_: CancellationException) {
|
||||
} catch (e: Exception) {
|
||||
AppLog.put("替换净化: 规则 ${item.name}替换出错.\n${mContent}", e)
|
||||
appCtx.toastOnUi("替换净化: 规则 ${item.name}替换出错")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,6 +258,7 @@ object Restore {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
LauncherIconHelp.changeIcon(appCtx.getPrefString(PreferKey.launcherIcon))
|
||||
}
|
||||
ThemeConfig.applyDayNight(appCtx)
|
||||
postEvent(EventBus.RECREATE, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ class PermissionActivity : AppCompatActivity() {
|
||||
Request.TYPE_MANAGE_ALL_FILES_ACCESS -> showSettingDialog(permissions, rationale) {
|
||||
try {
|
||||
if (Permissions.isManageExternalStorage()) {
|
||||
val settingIntent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
|
||||
val settingIntent =
|
||||
Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
|
||||
settingActivityResult.launch(settingIntent)
|
||||
} else {
|
||||
throw NoStackTraceException("no MANAGE_ALL_FILES_ACCESS_PERMISSION")
|
||||
@@ -53,6 +54,7 @@ class PermissionActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
Request.TYPE_REQUEST_NOTIFICATIONS -> showSettingDialog(permissions, rationale) {
|
||||
kotlin.runCatching {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
@@ -135,6 +137,10 @@ class PermissionActivity : AppCompatActivity() {
|
||||
)
|
||||
finish()
|
||||
}.setOnCancelListener {
|
||||
RequestPlugins.sRequestCallback?.onRequestPermissionsResult(
|
||||
permissions,
|
||||
IntArray(0)
|
||||
)
|
||||
finish()
|
||||
}
|
||||
.show()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.legado.app.lib.permission
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
@@ -49,6 +50,7 @@ internal class Request : OnRequestPermissionsResultCallback {
|
||||
this.rationale = rationale
|
||||
}
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
fun start() {
|
||||
RequestPlugins.setOnRequestPermissionsCallback(this)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user