|
|
@ -21,18 +21,21 @@ import java.io.File |
|
|
|
@Keep |
|
|
|
@Keep |
|
|
|
object ReadBookConfig { |
|
|
|
object ReadBookConfig { |
|
|
|
const val configFileName = "readConfig.json" |
|
|
|
const val configFileName = "readConfig.json" |
|
|
|
|
|
|
|
const val shareConfigFileName = "shareReadConfig.json" |
|
|
|
val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName) |
|
|
|
val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName) |
|
|
|
|
|
|
|
val shareConfigFilePath = FileUtils.getPath(App.INSTANCE.filesDir, shareConfigFileName) |
|
|
|
val configList: ArrayList<Config> = arrayListOf() |
|
|
|
val configList: ArrayList<Config> = arrayListOf() |
|
|
|
|
|
|
|
lateinit var shareConfig: Config |
|
|
|
private val defaultConfigs by lazy { |
|
|
|
private val defaultConfigs by lazy { |
|
|
|
val json = String(App.INSTANCE.assets.open(configFileName).readBytes()) |
|
|
|
val json = String(App.INSTANCE.assets.open(configFileName).readBytes()) |
|
|
|
GSON.fromJsonArray<Config>(json)!! |
|
|
|
GSON.fromJsonArray<Config>(json)!! |
|
|
|
} |
|
|
|
} |
|
|
|
var durConfig |
|
|
|
var durConfig |
|
|
|
get() = getConfig(styleSelect + 1) |
|
|
|
get() = getConfig(styleSelect) |
|
|
|
set(value) { |
|
|
|
set(value) { |
|
|
|
configList[styleSelect + 1] = value |
|
|
|
configList[styleSelect] = value |
|
|
|
if (shareLayout) { |
|
|
|
if (shareLayout) { |
|
|
|
configList[5] = value |
|
|
|
shareConfig = value |
|
|
|
} |
|
|
|
} |
|
|
|
upBg() |
|
|
|
upBg() |
|
|
|
} |
|
|
|
} |
|
|
@ -42,7 +45,8 @@ object ReadBookConfig { |
|
|
|
val textColor: Int get() = durConfig.textColor() |
|
|
|
val textColor: Int get() = durConfig.textColor() |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
upConfig() |
|
|
|
initConfigs() |
|
|
|
|
|
|
|
initShareConfig() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
@ -50,30 +54,38 @@ object ReadBookConfig { |
|
|
|
if (configList.size < 5) { |
|
|
|
if (configList.size < 5) { |
|
|
|
resetAll() |
|
|
|
resetAll() |
|
|
|
} |
|
|
|
} |
|
|
|
if (configList.size < 6) { |
|
|
|
return configList.getOrNull(index) ?: configList[0] |
|
|
|
configList.add(0, Config()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return configList[index] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun upConfig() { |
|
|
|
fun initConfigs() { |
|
|
|
(getConfigs() ?: defaultConfigs).let { |
|
|
|
val configFile = File(configFilePath) |
|
|
|
|
|
|
|
var configs: List<Config>? = null |
|
|
|
|
|
|
|
if (configFile.exists()) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
val json = configFile.readText() |
|
|
|
|
|
|
|
configs = GSON.fromJsonArray(json) |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
e.printStackTrace() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
(configs ?: defaultConfigs).let { |
|
|
|
configList.clear() |
|
|
|
configList.clear() |
|
|
|
configList.addAll(it) |
|
|
|
configList.addAll(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getConfigs(): List<Config>? { |
|
|
|
fun initShareConfig() { |
|
|
|
val configFile = File(configFilePath) |
|
|
|
val configFile = File(configFilePath) |
|
|
|
|
|
|
|
var c: Config? = null |
|
|
|
if (configFile.exists()) { |
|
|
|
if (configFile.exists()) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
val json = configFile.readText() |
|
|
|
val json = configFile.readText() |
|
|
|
return GSON.fromJsonArray(json) |
|
|
|
c = GSON.fromJsonObject(json) |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
e.printStackTrace() |
|
|
|
e.printStackTrace() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null |
|
|
|
shareConfig = c ?: configList.getOrNull(5) ?: Config() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun upBg() { |
|
|
|
fun upBg() { |
|
|
@ -160,7 +172,7 @@ object ReadBookConfig { |
|
|
|
var hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) |
|
|
|
var hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) |
|
|
|
var hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) |
|
|
|
var hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) |
|
|
|
|
|
|
|
|
|
|
|
val config get() = if (shareLayout) getConfig(0) else durConfig |
|
|
|
val config get() = if (shareLayout) shareConfig else durConfig |
|
|
|
|
|
|
|
|
|
|
|
var textFont: String |
|
|
|
var textFont: String |
|
|
|
get() = config.textFont |
|
|
|
get() = config.textFont |
|
|
@ -308,39 +320,38 @@ object ReadBookConfig { |
|
|
|
fun getExportConfig(): Config { |
|
|
|
fun getExportConfig(): Config { |
|
|
|
val exportConfig = GSON.fromJsonObject<Config>(GSON.toJson(durConfig))!! |
|
|
|
val exportConfig = GSON.fromJsonObject<Config>(GSON.toJson(durConfig))!! |
|
|
|
if (shareLayout) { |
|
|
|
if (shareLayout) { |
|
|
|
val shearConfig = getConfig(0) |
|
|
|
exportConfig.textFont = shareConfig.textFont |
|
|
|
exportConfig.textFont = shearConfig.textFont |
|
|
|
exportConfig.textBold = shareConfig.textBold |
|
|
|
exportConfig.textBold = shearConfig.textBold |
|
|
|
exportConfig.textSize = shareConfig.textSize |
|
|
|
exportConfig.textSize = shearConfig.textSize |
|
|
|
exportConfig.letterSpacing = shareConfig.letterSpacing |
|
|
|
exportConfig.letterSpacing = shearConfig.letterSpacing |
|
|
|
exportConfig.lineSpacingExtra = shareConfig.lineSpacingExtra |
|
|
|
exportConfig.lineSpacingExtra = shearConfig.lineSpacingExtra |
|
|
|
exportConfig.paragraphSpacing = shareConfig.paragraphSpacing |
|
|
|
exportConfig.paragraphSpacing = shearConfig.paragraphSpacing |
|
|
|
exportConfig.titleMode = shareConfig.titleMode |
|
|
|
exportConfig.titleMode = shearConfig.titleMode |
|
|
|
exportConfig.titleSize = shareConfig.titleSize |
|
|
|
exportConfig.titleSize = shearConfig.titleSize |
|
|
|
exportConfig.titleTopSpacing = shareConfig.titleTopSpacing |
|
|
|
exportConfig.titleTopSpacing = shearConfig.titleTopSpacing |
|
|
|
exportConfig.titleBottomSpacing = shareConfig.titleBottomSpacing |
|
|
|
exportConfig.titleBottomSpacing = shearConfig.titleBottomSpacing |
|
|
|
exportConfig.paddingBottom = shareConfig.paddingBottom |
|
|
|
exportConfig.paddingBottom = shearConfig.paddingBottom |
|
|
|
exportConfig.paddingLeft = shareConfig.paddingLeft |
|
|
|
exportConfig.paddingLeft = shearConfig.paddingLeft |
|
|
|
exportConfig.paddingRight = shareConfig.paddingRight |
|
|
|
exportConfig.paddingRight = shearConfig.paddingRight |
|
|
|
exportConfig.paddingTop = shareConfig.paddingTop |
|
|
|
exportConfig.paddingTop = shearConfig.paddingTop |
|
|
|
exportConfig.headerPaddingBottom = shareConfig.headerPaddingBottom |
|
|
|
exportConfig.headerPaddingBottom = shearConfig.headerPaddingBottom |
|
|
|
exportConfig.headerPaddingLeft = shareConfig.headerPaddingLeft |
|
|
|
exportConfig.headerPaddingLeft = shearConfig.headerPaddingLeft |
|
|
|
exportConfig.headerPaddingRight = shareConfig.headerPaddingRight |
|
|
|
exportConfig.headerPaddingRight = shearConfig.headerPaddingRight |
|
|
|
exportConfig.headerPaddingTop = shareConfig.headerPaddingTop |
|
|
|
exportConfig.headerPaddingTop = shearConfig.headerPaddingTop |
|
|
|
exportConfig.footerPaddingBottom = shareConfig.footerPaddingBottom |
|
|
|
exportConfig.footerPaddingBottom = shearConfig.footerPaddingBottom |
|
|
|
exportConfig.footerPaddingLeft = shareConfig.footerPaddingLeft |
|
|
|
exportConfig.footerPaddingLeft = shearConfig.footerPaddingLeft |
|
|
|
exportConfig.footerPaddingRight = shareConfig.footerPaddingRight |
|
|
|
exportConfig.footerPaddingRight = shearConfig.footerPaddingRight |
|
|
|
exportConfig.footerPaddingTop = shareConfig.footerPaddingTop |
|
|
|
exportConfig.footerPaddingTop = shearConfig.footerPaddingTop |
|
|
|
exportConfig.showHeaderLine = shareConfig.showHeaderLine |
|
|
|
exportConfig.showHeaderLine = shearConfig.showHeaderLine |
|
|
|
exportConfig.showFooterLine = shareConfig.showFooterLine |
|
|
|
exportConfig.showFooterLine = shearConfig.showFooterLine |
|
|
|
exportConfig.tipHeaderLeft = shareConfig.tipHeaderLeft |
|
|
|
exportConfig.tipHeaderLeft = shearConfig.tipHeaderLeft |
|
|
|
exportConfig.tipHeaderMiddle = shareConfig.tipHeaderMiddle |
|
|
|
exportConfig.tipHeaderMiddle = shearConfig.tipHeaderMiddle |
|
|
|
exportConfig.tipHeaderRight = shareConfig.tipHeaderRight |
|
|
|
exportConfig.tipHeaderRight = shearConfig.tipHeaderRight |
|
|
|
exportConfig.tipFooterLeft = shareConfig.tipFooterLeft |
|
|
|
exportConfig.tipFooterLeft = shearConfig.tipFooterLeft |
|
|
|
exportConfig.tipFooterMiddle = shareConfig.tipFooterMiddle |
|
|
|
exportConfig.tipFooterMiddle = shearConfig.tipFooterMiddle |
|
|
|
exportConfig.tipFooterRight = shareConfig.tipFooterRight |
|
|
|
exportConfig.tipFooterRight = shearConfig.tipFooterRight |
|
|
|
exportConfig.hideHeader = shareConfig.hideHeader |
|
|
|
exportConfig.hideHeader = shearConfig.hideHeader |
|
|
|
exportConfig.hideFooter = shareConfig.hideFooter |
|
|
|
exportConfig.hideFooter = shearConfig.hideFooter |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return exportConfig |
|
|
|
return exportConfig |
|
|
|
} |
|
|
|
} |
|
|
@ -365,7 +376,7 @@ object ReadBookConfig { |
|
|
|
var textSize: Int = 20,//文字大小 |
|
|
|
var textSize: Int = 20,//文字大小 |
|
|
|
var letterSpacing: Float = 0.1f,//字间距 |
|
|
|
var letterSpacing: Float = 0.1f,//字间距 |
|
|
|
var lineSpacingExtra: Int = 12,//行间距 |
|
|
|
var lineSpacingExtra: Int = 12,//行间距 |
|
|
|
var paragraphSpacing: Int = 4,//段距 |
|
|
|
var paragraphSpacing: Int = 2,//段距 |
|
|
|
var titleMode: Int = 0,//标题居中 |
|
|
|
var titleMode: Int = 0,//标题居中 |
|
|
|
var titleSize: Int = 0, |
|
|
|
var titleSize: Int = 0, |
|
|
|
var titleTopSpacing: Int = 0, |
|
|
|
var titleTopSpacing: Int = 0, |
|
|
|