优化 #5584
This commit is contained in:
@@ -39,6 +39,8 @@ import io.legado.app.help.LifecycleHelp
|
||||
import io.legado.app.help.RuleBigDataHelp
|
||||
import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.help.config.ThemeConfig
|
||||
import io.legado.app.help.config.ThemeConfig.applyDayNight
|
||||
import io.legado.app.help.config.ThemeConfig.applyDayNightInit
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
@@ -105,6 +107,8 @@ class App : Application() {
|
||||
RuleBigDataHelp.clearInvalid()
|
||||
BookHelp.clearInvalidCache()
|
||||
Backup.clearCache()
|
||||
ReadBookConfig.clearBgAndCache()
|
||||
ThemeConfig.clearBg()
|
||||
//初始化简繁转换引擎
|
||||
when (AppConfig.chineseConverterType) {
|
||||
1 -> {
|
||||
|
||||
@@ -162,6 +162,25 @@ object ReadBookConfig {
|
||||
return false
|
||||
}
|
||||
|
||||
fun clearBgAndCache() {
|
||||
val bgs = hashSetOf<String>()
|
||||
configList.forEach { config ->
|
||||
repeat(3) {
|
||||
config.getBgPath(it)?.let { path ->
|
||||
bgs.add(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
appCtx.externalFiles.getFile("bg").listFiles()?.forEach {
|
||||
if (!bgs.contains(it.absolutePath)) {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
FileUtils.delete(appCtx.externalCache.getFile("readConfig"))
|
||||
val configZipPath = FileUtils.getPath(appCtx.externalCache, "readConfig.zip")
|
||||
FileUtils.delete(configZipPath)
|
||||
}
|
||||
|
||||
private fun resetAll() {
|
||||
DefaultData.readConfigs.let {
|
||||
configList.clear()
|
||||
@@ -704,5 +723,29 @@ object ReadBookConfig {
|
||||
}
|
||||
return bgDrawable ?: ColorDrawable(appCtx.getCompatColor(R.color.background))
|
||||
}
|
||||
|
||||
fun getBgPath(bgIndex: Int): String? {
|
||||
val bgType = when (bgIndex) {
|
||||
0 -> bgType
|
||||
1 -> bgTypeNight
|
||||
2 -> bgTypeEInk
|
||||
else -> error("unknown bgIndex: $bgIndex")
|
||||
}
|
||||
if (bgType != 2) {
|
||||
return null
|
||||
}
|
||||
val bgStr = when (bgIndex) {
|
||||
0 -> bgStr
|
||||
1 -> bgStrNight
|
||||
2 -> bgStrEInk
|
||||
else -> error("unknown bgIndex: $bgIndex")
|
||||
}
|
||||
val path = if (bgStr.contains(File.separator)) {
|
||||
bgStr
|
||||
} else {
|
||||
FileUtils.getPath(appCtx.externalFiles, "bg", bgStr)
|
||||
}
|
||||
return path
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,11 @@ import io.legado.app.utils.BitmapUtils
|
||||
import io.legado.app.utils.ColorUtils
|
||||
import io.legado.app.utils.FileUtils
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.externalFiles
|
||||
import io.legado.app.utils.fromJsonArray
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
import io.legado.app.utils.getCompatColor
|
||||
import io.legado.app.utils.getFile
|
||||
import io.legado.app.utils.getPrefInt
|
||||
import io.legado.app.utils.getPrefString
|
||||
import io.legado.app.utils.hexString
|
||||
@@ -292,6 +294,21 @@ object ThemeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
fun clearBg() {
|
||||
val bgImagePath = appCtx.getPrefString(PreferKey.bgImage)
|
||||
appCtx.externalFiles.getFile(PreferKey.bgImage).listFiles()?.forEach {
|
||||
if (it.absolutePath != bgImagePath) {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
val bgImageNPath = appCtx.getPrefString(PreferKey.bgImageN)
|
||||
appCtx.externalFiles.getFile(PreferKey.bgImageN).listFiles()?.forEach {
|
||||
if (it.absolutePath != bgImageNPath) {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
data class Config(
|
||||
var themeName: String,
|
||||
|
||||
@@ -286,38 +286,10 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
exportFiles.add(fontExportFile)
|
||||
}
|
||||
}
|
||||
if (ReadBookConfig.durConfig.bgType == 2) {
|
||||
val bgName = FileUtils.getName(ReadBookConfig.durConfig.bgStr)
|
||||
val bgFile = File(ReadBookConfig.durConfig.bgStr)
|
||||
if (bgFile.exists()) {
|
||||
val bgExportFile = File(FileUtils.getPath(configDir, bgName))
|
||||
if (!bgExportFile.exists()) {
|
||||
bgFile.copyTo(bgExportFile)
|
||||
exportFiles.add(bgExportFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ReadBookConfig.durConfig.bgTypeNight == 2) {
|
||||
val bgName = FileUtils.getName(ReadBookConfig.durConfig.bgStrNight)
|
||||
val bgFile = File(ReadBookConfig.durConfig.bgStrNight)
|
||||
if (bgFile.exists()) {
|
||||
val bgExportFile = File(FileUtils.getPath(configDir, bgName))
|
||||
if (!bgExportFile.exists()) {
|
||||
bgFile.copyTo(bgExportFile)
|
||||
exportFiles.add(bgExportFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ReadBookConfig.durConfig.bgTypeEInk == 2) {
|
||||
val bgName = FileUtils.getName(ReadBookConfig.durConfig.bgStrEInk)
|
||||
val bgFile = File(ReadBookConfig.durConfig.bgStrEInk)
|
||||
if (bgFile.exists()) {
|
||||
val bgExportFile = File(FileUtils.getPath(configDir, bgName))
|
||||
if (!bgExportFile.exists()) {
|
||||
bgFile.copyTo(bgExportFile)
|
||||
exportFiles.add(bgExportFile)
|
||||
}
|
||||
}
|
||||
repeat(3) {
|
||||
val path = ReadBookConfig.durConfig.getBgPath(it) ?: return@repeat
|
||||
val bgExportFile = copyBgImage(path, configDir) ?: return@repeat
|
||||
exportFiles.add(bgExportFile)
|
||||
}
|
||||
val configZipPath = FileUtils.getPath(requireContext().externalCache, configFileName)
|
||||
if (ZipUtils.zipFiles(exportFiles, File(configZipPath))) {
|
||||
@@ -346,6 +318,19 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyBgImage(path: String, configDir: File): File? {
|
||||
val bgName = FileUtils.getName(path)
|
||||
val bgFile = File(path)
|
||||
if (bgFile.exists()) {
|
||||
val bgExportFile = File(FileUtils.getPath(configDir, bgName))
|
||||
if (!bgExportFile.exists()) {
|
||||
bgFile.copyTo(bgExportFile)
|
||||
return bgExportFile
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private fun importNetConfigAlert() {
|
||||
alert("输入地址") {
|
||||
|
||||
Reference in New Issue
Block a user