diff --git a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt index 34c856ddd..c07bb3157 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt @@ -219,6 +219,12 @@ object ReadBookConfig { config.textBold = value } + var titleBold: Int + get() = config.titleBold + set(value) { + config.titleBold = value + } + var textItalic: Boolean get() = config.textItalic set(value) { @@ -490,6 +496,7 @@ object ReadBookConfig { var titleSize: Int = 0, var titleTopSpacing: Int = 0, var titleBottomSpacing: Int = 0, + var titleBold: Int = 500, var paragraphIndent: String = "  ",//段落缩进 var underline: Boolean = false, //下划线 var paddingBottom: Int = 6, diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index c2d7b4a19..011ca1fbf 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -10,6 +10,7 @@ import io.legado.app.constant.EventBus import io.legado.app.databinding.DialogTipConfigBinding import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadTipConfig +import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector import io.legado.app.utils.hexString import io.legado.app.utils.observeEvent @@ -47,6 +48,35 @@ class TipConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_tip_config 2 -> binding.rgTitleMode.check(R.id.rb_title_mode3) else -> { } } + val weightOptions = context?.resources?.getStringArray(R.array.text_font_weight) + val weightValues = listOf(2, 1, 0) + val initialIndex = weightValues.indexOf(ReadBookConfig.titleBold) + binding.textFontWeightConverter.text = weightOptions?.getOrNull(initialIndex) ?: "自定义" + binding.textFontWeightConverter.setOnClickListener { + context?.alert(titleResource = R.string.text_font_weight_converter) { + weightOptions?.let { options -> + items(options.toList()) { _, i -> + ReadBookConfig.titleBold = weightValues[i] + binding.sliderFontWeight.value = + ReadBookConfig.titleBold.toFloat().coerceAtLeast(100f) + binding.textFontWeightConverter.text = options.getOrNull(i) ?: "" + postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6)) + } + } + } + } + + binding.sliderFontWeight.apply { + valueFrom = 100f + valueTo = 900f + stepSize = 1f + value = ReadBookConfig.titleBold.toFloat().coerceAtLeast(100f) + addOnChangeListener { _, newValue, _ -> + binding.textFontWeightConverter.text = "自定义" + ReadBookConfig.titleBold = newValue.toInt() + postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6)) + } + } binding.dsbTitleSize.progress = ReadBookConfig.titleSize binding.dsbTitleTop.progress = ReadBookConfig.titleTopSpacing diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 314b53fc3..7b7f5788d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -915,40 +915,52 @@ object ChapterProvider { private fun getPaints(typeface: Typeface?): Pair { val bold = Typeface.create(typeface, Typeface.BOLD) val normal = Typeface.create(typeface, Typeface.NORMAL) - val (titleFont, textFont) = when (ReadBookConfig.textBold) { - 1 -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) - Pair(Typeface.create(typeface, 900, false), bold) - else - Pair(bold, bold) - } + val titleFont = when (ReadBookConfig.titleBold) { + 1 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Typeface.create(typeface, 900, false) + else + bold - 2 -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) - Pair(normal, Typeface.create(typeface, 300, false)) - else - Pair(normal, normal) - } + 2 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Typeface.create(typeface, 300, false) + else + normal - in 100..900 -> { + in 100..900 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Typeface.create(typeface, ReadBookConfig.titleBold, false) + else + normal - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - Pair(normal, Typeface.create(typeface, ReadBookConfig.textBold, false)) - } else { - Pair(normal, normal) - } - } - - else -> Pair(bold, normal) + else -> bold } + val textFont = when (ReadBookConfig.textBold) { + 1 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Typeface.create(typeface, 900, false) + else + bold + + 2 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Typeface.create(typeface, 300, false) + else + normal + + in 100..900 -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + Typeface.create(typeface, ReadBookConfig.textBold, false) + else + normal + + else -> bold + } + + //标题 val tPaint = TextPaint() tPaint.color = ReadBookConfig.textColor tPaint.letterSpacing = ReadBookConfig.letterSpacing tPaint.typeface = titleFont - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.textBold in 100..900) - tPaint.setFontVariationSettings("'wght' ${ReadBookConfig.textBold}") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.titleBold in 100..900) + tPaint.setFontVariationSettings("'wght' ${ReadBookConfig.titleBold}") tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.toFloat().spToPx() tPaint.isAntiAlias = true if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q && AppConfig.optimizeRender) { diff --git a/app/src/main/res/layout/dialog_tip_config.xml b/app/src/main/res/layout/dialog_tip_config.xml index e692975d0..e2ac8d1a6 100644 --- a/app/src/main/res/layout/dialog_tip_config.xml +++ b/app/src/main/res/layout/dialog_tip_config.xml @@ -75,11 +75,36 @@ + + + + + + + + +