修复排版导入背景失败bug

pull/423/head
gedoor 4 years ago
parent 03675580b6
commit a4702a4f6b
  1. 56
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 58
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt

@ -42,7 +42,7 @@ object ReadBookConfig {
var bg: Drawable? = null var bg: Drawable? = null
var bgMeanColor: Int = 0 var bgMeanColor: Int = 0
val textColor: Int get() = durConfig.textColor() val textColor: Int get() = durConfig.curTextColor()
init { init {
initConfigs() initConfigs()
@ -168,9 +168,9 @@ object ReadBookConfig {
val config get() = if (shareLayout) shareConfig else durConfig val config get() = if (shareLayout) shareConfig else durConfig
var pageAnim: Int var pageAnim: Int
get() = config.pageAnim() get() = config.curPageAnim()
set(value) { set(value) {
config.setPageAnim(value) config.setCurPageAnim(value)
isScroll = pageAnim == 3 isScroll = pageAnim == 3
} }
@ -365,20 +365,20 @@ object ReadBookConfig {
@Keep @Keep
@Parcelize @Parcelize
class Config( class Config(
private var bgStr: String = "#EEEEEE",//白天背景 var bgStr: String = "#EEEEEE",//白天背景
private var bgStrNight: String = "#000000",//夜间背景 var bgStrNight: String = "#000000",//夜间背景
private var bgStrEInk: String = "#FFFFFF", var bgStrEInk: String = "#FFFFFF",
private var bgType: Int = 0,//白天背景类型 0:颜色, 1:assets图片, 2其它图片 var bgType: Int = 0,//白天背景类型 0:颜色, 1:assets图片, 2其它图片
private var bgTypeNight: Int = 0,//夜间背景类型 var bgTypeNight: Int = 0,//夜间背景类型
private var bgTypeEInk: Int = 0, var bgTypeEInk: Int = 0,
private var darkStatusIcon: Boolean = true,//白天是否暗色状态栏 var darkStatusIcon: Boolean = true,//白天是否暗色状态栏
private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏 var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏
private var darkStatusIconEInk: Boolean = true, var darkStatusIconEInk: Boolean = true,
private var textColor: String = "#3E3D3B",//白天文字颜色 var textColor: String = "#3E3D3B",//白天文字颜色
private var textColorNight: String = "#ADADAD",//夜间文字颜色 var textColorNight: String = "#ADADAD",//夜间文字颜色
private var textColorEInk: String = "#000000", var textColorEInk: String = "#000000",
private var pageAnim: Int = 0, var pageAnim: Int = 0,
private var pageAnimEInk: Int = 3, var pageAnimEInk: Int = 3,
var textFont: String = "",//字体 var textFont: String = "",//字体
var textBold: Int = 0,//是否粗体字 0:正常, 1:粗体, 2:细体 var textBold: Int = 0,//是否粗体字 0:正常, 1:粗体, 2:细体
var textSize: Int = 20,//文字大小 var textSize: Int = 20,//文字大小
@ -413,7 +413,7 @@ object ReadBookConfig {
var hideHeader: Boolean = true, var hideHeader: Boolean = true,
var hideFooter: Boolean = false var hideFooter: Boolean = false
) : Parcelable { ) : Parcelable {
fun setBg(bgType: Int, bg: String) { fun setCurBg(bgType: Int, bg: String) {
when { when {
AppConfig.isEInkMode -> { AppConfig.isEInkMode -> {
bgTypeEInk = bgType bgTypeEInk = bgType
@ -430,7 +430,7 @@ object ReadBookConfig {
} }
} }
fun setTextColor(color: Int) { fun setCurTextColor(color: Int) {
when { when {
AppConfig.isEInkMode -> textColorEInk = "#${color.hexString}" AppConfig.isEInkMode -> textColorEInk = "#${color.hexString}"
AppConfig.isNightTheme -> textColorNight = "#${color.hexString}" AppConfig.isNightTheme -> textColorNight = "#${color.hexString}"
@ -455,21 +455,21 @@ object ReadBookConfig {
} }
} }
fun setPageAnim(anim: Int) { fun setCurPageAnim(anim: Int) {
when { when {
AppConfig.isEInkMode -> pageAnimEInk = anim AppConfig.isEInkMode -> pageAnimEInk = anim
else -> pageAnim = anim else -> pageAnim = anim
} }
} }
fun pageAnim(): Int { fun curPageAnim(): Int {
return when { return when {
AppConfig.isEInkMode -> pageAnimEInk AppConfig.isEInkMode -> pageAnimEInk
else -> pageAnim else -> pageAnim
} }
} }
fun textColor(): Int { fun curTextColor(): Int {
return when { return when {
AppConfig.isEInkMode -> Color.parseColor(textColorEInk) AppConfig.isEInkMode -> Color.parseColor(textColorEInk)
AppConfig.isNightTheme -> Color.parseColor(textColorNight) AppConfig.isNightTheme -> Color.parseColor(textColorNight)
@ -477,7 +477,7 @@ object ReadBookConfig {
} }
} }
fun bgStr(): String { fun curBgStr(): String {
return when { return when {
AppConfig.isEInkMode -> bgStrEInk AppConfig.isEInkMode -> bgStrEInk
AppConfig.isNightTheme -> bgStrNight AppConfig.isNightTheme -> bgStrNight
@ -485,7 +485,7 @@ object ReadBookConfig {
} }
} }
fun bgType(): Int { fun curBgType(): Int {
return when { return when {
AppConfig.isEInkMode -> bgTypeEInk AppConfig.isEInkMode -> bgTypeEInk
AppConfig.isNightTheme -> bgTypeNight AppConfig.isNightTheme -> bgTypeNight
@ -497,14 +497,14 @@ object ReadBookConfig {
var bgDrawable: Drawable? = null var bgDrawable: Drawable? = null
val resources = App.INSTANCE.resources val resources = App.INSTANCE.resources
try { try {
bgDrawable = when (bgType()) { bgDrawable = when (curBgType()) {
0 -> ColorDrawable(Color.parseColor(bgStr())) 0 -> ColorDrawable(Color.parseColor(curBgStr()))
1 -> { 1 -> {
BitmapDrawable( BitmapDrawable(
resources, resources,
BitmapUtils.decodeAssetsBitmap( BitmapUtils.decodeAssetsBitmap(
App.INSTANCE, App.INSTANCE,
"bg" + File.separator + bgStr(), "bg" + File.separator + curBgStr(),
width, width,
height height
) )
@ -512,7 +512,7 @@ object ReadBookConfig {
} }
else -> BitmapDrawable( else -> BitmapDrawable(
resources, resources,
BitmapUtils.decodeBitmap(bgStr(), width, height) BitmapUtils.decodeBitmap(curBgStr(), width, height)
) )
} }
} catch (e: Exception) { } catch (e: Exception) {

@ -741,11 +741,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.durConfig) { override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.durConfig) {
when (dialogId) { when (dialogId) {
TEXT_COLOR -> { TEXT_COLOR -> {
setTextColor(color) setCurTextColor(color)
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }
BG_COLOR -> { BG_COLOR -> {
setBg(0, "#${color.hexString}") setCurBg(0, "#${color.hexString}")
ReadBookConfig.upBg() ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }

@ -133,7 +133,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
} }
tv_text_color.onClick { tv_text_color.onClick {
ColorPickerDialog.newBuilder() ColorPickerDialog.newBuilder()
.setColor(textColor()) .setColor(curTextColor())
.setShowAlphaSlider(false) .setShowAlphaSlider(false)
.setDialogType(ColorPickerDialog.TYPE_CUSTOM) .setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setDialogId(TEXT_COLOR) .setDialogId(TEXT_COLOR)
@ -141,7 +141,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
} }
tv_bg_color.onClick { tv_bg_color.onClick {
val bgColor = val bgColor =
if (bgType() == 0) Color.parseColor(bgStr()) if (curBgType() == 0) Color.parseColor(curBgStr())
else Color.parseColor("#015A86") else Color.parseColor("#015A86")
ColorPickerDialog.newBuilder() ColorPickerDialog.newBuilder()
.setColor(bgColor) .setColor(bgColor)
@ -206,7 +206,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
holder.itemView.apply { holder.itemView.apply {
this.onClick { this.onClick {
getItemByLayoutPosition(holder.layoutPosition)?.let { getItemByLayoutPosition(holder.layoutPosition)?.let {
ReadBookConfig.durConfig.setBg(1, it) ReadBookConfig.durConfig.setCurBg(1, it)
ReadBookConfig.upBg() ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }
@ -237,9 +237,27 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
exportFiles.add(fontExportFile) exportFiles.add(fontExportFile)
} }
} }
if (ReadBookConfig.durConfig.bgType() == 2) { if (ReadBookConfig.durConfig.bgType == 2) {
val bgName = FileUtils.getName(ReadBookConfig.durConfig.bgStr()) val bgName = FileUtils.getName(ReadBookConfig.durConfig.bgStr)
val bgFile = File(ReadBookConfig.durConfig.bgStr()) val bgFile = File(ReadBookConfig.durConfig.bgStr)
if (bgFile.exists()) {
val bgExportFile = File(FileUtils.getPath(configDir, bgName))
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))
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()) { if (bgFile.exists()) {
val bgExportFile = File(FileUtils.getPath(configDir, bgName)) val bgExportFile = File(FileUtils.getPath(configDir, bgName))
bgFile.copyTo(bgExportFile) bgFile.copyTo(bgExportFile)
@ -329,8 +347,28 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
} }
config.textFont = fontPath config.textFont = fontPath
} }
if (config.bgType() == 2) { if (config.bgType == 2) {
val bgName = FileUtils.getName(config.bgStr()) val bgName = FileUtils.getName(config.bgStr)
val bgPath = FileUtils.getPath(requireContext().externalFilesDir, "bg", bgName)
if (!FileUtils.exist(bgPath)) {
val bgFile = FileUtils.getFile(configDir, bgName)
if (bgFile.exists()) {
bgFile.copyTo(File(bgPath))
}
}
}
if (config.bgTypeNight == 2) {
val bgName = FileUtils.getName(config.bgStrNight)
val bgPath = FileUtils.getPath(requireContext().externalFilesDir, "bg", bgName)
if (!FileUtils.exist(bgPath)) {
val bgFile = FileUtils.getFile(configDir, bgName)
if (bgFile.exists()) {
bgFile.copyTo(File(bgPath))
}
}
}
if (config.bgTypeEInk == 2) {
val bgName = FileUtils.getName(config.bgStrEInk)
val bgPath = FileUtils.getPath(requireContext().externalFilesDir, "bg", bgName) val bgPath = FileUtils.getPath(requireContext().externalFilesDir, "bg", bgName)
if (!FileUtils.exist(bgPath)) { if (!FileUtils.exist(bgPath)) {
val bgFile = FileUtils.getFile(configDir, bgName) val bgFile = FileUtils.getFile(configDir, bgName)
@ -387,7 +425,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
DocumentUtils.readBytes(requireContext(), doc.uri) DocumentUtils.readBytes(requireContext(), doc.uri)
}.getOrNull()?.let { byteArray -> }.getOrNull()?.let { byteArray ->
file.writeBytes(byteArray) file.writeBytes(byteArray)
ReadBookConfig.durConfig.setBg(2, file.absolutePath) ReadBookConfig.durConfig.setCurBg(2, file.absolutePath)
ReadBookConfig.upBg() ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} ?: toast("获取文件出错") } ?: toast("获取文件出错")
@ -401,7 +439,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
.rationale(R.string.bg_image_per) .rationale(R.string.bg_image_per)
.onGranted { .onGranted {
RealPathUtil.getPath(requireContext(), uri)?.let { path -> RealPathUtil.getPath(requireContext(), uri)?.let { path ->
ReadBookConfig.durConfig.setBg(2, path) ReadBookConfig.durConfig.setCurBg(2, path)
ReadBookConfig.upBg() ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }

@ -246,13 +246,13 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
holder.itemView.apply { holder.itemView.apply {
iv_style.setTextColor(item.textColor()) iv_style.setTextColor(item.curTextColor())
iv_style.setImageDrawable(item.bgDrawable(100, 150)) iv_style.setImageDrawable(item.bgDrawable(100, 150))
if (ReadBookConfig.styleSelect == holder.layoutPosition) { if (ReadBookConfig.styleSelect == holder.layoutPosition) {
iv_style.borderColor = accentColor iv_style.borderColor = accentColor
iv_style.setTextBold(true) iv_style.setTextBold(true)
} else { } else {
iv_style.borderColor = item.textColor() iv_style.borderColor = item.curTextColor()
iv_style.setTextBold(false) iv_style.setTextBold(false)
} }
} }

Loading…
Cancel
Save