This commit is contained in:
kunfei 2023-08-01 22:46:18 +08:00
parent 0d6f71eebd
commit f96b03432a
3 changed files with 17 additions and 7 deletions

View File

@ -425,6 +425,7 @@ object ReadBookConfig {
} }
if (config.bgType == 2) { if (config.bgType == 2) {
val bgName = FileUtils.getName(config.bgStr) val bgName = FileUtils.getName(config.bgStr)
config.bgStr = bgName
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName)
if (!FileUtils.exist(bgPath)) { if (!FileUtils.exist(bgPath)) {
val bgFile = configDir.getFile(bgName) val bgFile = configDir.getFile(bgName)
@ -436,6 +437,7 @@ object ReadBookConfig {
} }
if (config.bgTypeNight == 2) { if (config.bgTypeNight == 2) {
val bgName = FileUtils.getName(config.bgStrNight) val bgName = FileUtils.getName(config.bgStrNight)
config.bgStrNight = bgName
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName)
if (!FileUtils.exist(bgPath)) { if (!FileUtils.exist(bgPath)) {
val bgFile = configDir.getFile(bgName) val bgFile = configDir.getFile(bgName)
@ -447,6 +449,7 @@ object ReadBookConfig {
} }
if (config.bgTypeEInk == 2) { if (config.bgTypeEInk == 2) {
val bgName = FileUtils.getName(config.bgStrEInk) val bgName = FileUtils.getName(config.bgStrEInk)
config.bgStrEInk = bgName
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName)
if (!FileUtils.exist(bgPath)) { if (!FileUtils.exist(bgPath)) {
val bgFile = configDir.getFile(bgName) val bgFile = configDir.getFile(bgName)
@ -570,10 +573,12 @@ object ReadBookConfig {
bgTypeEInk = bgType bgTypeEInk = bgType
bgStrEInk = bg bgStrEInk = bg
} }
AppConfig.isNightTheme -> { AppConfig.isNightTheme -> {
bgTypeNight = bgType bgTypeNight = bgType
bgStrNight = bg bgStrNight = bg
} }
else -> { else -> {
this.bgType = bgType this.bgType = bgType
bgStr = bg bgStr = bg
@ -611,8 +616,13 @@ object ReadBookConfig {
val bitmap = BitmapUtils.decodeAssetsBitmap(appCtx, path, width, height) val bitmap = BitmapUtils.decodeAssetsBitmap(appCtx, path, width, height)
BitmapDrawable(resources, bitmap?.resizeAndRecycle(width, height)) BitmapDrawable(resources, bitmap?.resizeAndRecycle(width, height))
} }
else -> { else -> {
val bitmap = BitmapUtils.decodeBitmap(curBgStr(), width, height) val path = curBgStr().let {
if (it.contains(File.separator)) it
else FileUtils.getPath(appCtx.externalFiles, "bg", curBgStr())
}
val bitmap = BitmapUtils.decodeBitmap(path, width, height)
BitmapDrawable(resources, bitmap?.resizeAndRecycle(width, height)) BitmapDrawable(resources, bitmap?.resizeAndRecycle(width, height))
} }
} }

View File

@ -367,7 +367,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
FileOutputStream(file).use { outputStream -> FileOutputStream(file).use { outputStream ->
inputStream.copyTo(outputStream) inputStream.copyTo(outputStream)
} }
ReadBookConfig.durConfig.setCurBg(2, file.absolutePath) ReadBookConfig.durConfig.setCurBg(2, fileName)
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
}.onFailure { }.onFailure {
appCtx.toastOnUi(it.localizedMessage) appCtx.toastOnUi(it.localizedMessage)

View File

@ -551,15 +551,15 @@ object FileUtils {
/** /**
* 获取文件或网址的名称包括后缀 * 获取文件或网址的名称包括后缀
*/ */
fun getName(pathOrUrl: String?): String { fun getName(path: String?): String {
if (pathOrUrl == null) { if (path == null) {
return "" return ""
} }
val pos = pathOrUrl.lastIndexOf('/') val pos = path.lastIndexOf(File.separator)
return if (0 <= pos) { return if (0 <= pos) {
pathOrUrl.substring(pos + 1) path.substring(pos + 1)
} else { } else {
System.currentTimeMillis().toString() + "." + getExtension(pathOrUrl) path
} }
} }