mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
优化
This commit is contained in:
parent
0d6f71eebd
commit
f96b03432a
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user