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

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

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

Loading…
Cancel
Save