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

View File

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

View File

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