Merge pull request #238 from hingbong/master

正文字体的粗细选择增加可以选择细体(Android O生效)
pull/241/head
kunfei 5 years ago committed by GitHub
commit 5bfecea0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/build.gradle
  2. 4
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  3. 7
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  4. 5
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  5. 55
      app/src/main/java/io/legado/app/ui/book/read/config/TextFontWeightConverter.kt
  6. 30
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  7. 6
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  8. 5
      app/src/main/res/layout/dialog_read_book_style.xml
  9. 5
      app/src/main/res/values-zh-rHK/arrays.xml
  10. 1
      app/src/main/res/values-zh-rHK/strings.xml
  11. 5
      app/src/main/res/values-zh-rTW/arrays.xml
  12. 1
      app/src/main/res/values-zh-rTW/strings.xml
  13. 6
      app/src/main/res/values/arrays.xml
  14. 1
      app/src/main/res/values/strings.xml

@ -153,7 +153,7 @@ dependencies {
implementation 'com.jeremyliao:live-event-bus-x:1.5.7' implementation 'com.jeremyliao:live-event-bus-x:1.5.7'
// //
def coroutines_version = '1.3.3' def coroutines_version = '1.3.7'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

@ -147,7 +147,7 @@ object ReadBookConfig {
private val config get() = if (shareLayout) getConfig(5) else durConfig private val config get() = if (shareLayout) getConfig(5) else durConfig
var textBold: Boolean var textBold: Int
get() = config.textBold get() = config.textBold
set(value) { set(value) {
config.textBold = value config.textBold = value
@ -294,7 +294,7 @@ object ReadBookConfig {
private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏 private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏
private var textColor: String = "#3E3D3B",//白天文字颜色 private var textColor: String = "#3E3D3B",//白天文字颜色
private var textColorNight: String = "#ADADAD",//夜间文字颜色 private var textColorNight: String = "#ADADAD",//夜间文字颜色
var textBold: Boolean = false,//是否粗体字 var textBold: Int = 0,//是否粗体字 0:正常, 1:粗体, 2:细体
var textSize: Int = 20,//文字大小 var textSize: Int = 20,//文字大小
var letterSpacing: Float = 0.5f,//字间距 var letterSpacing: Float = 0.5f,//字间距
var lineSpacingExtra: Int = 12,//行间距 var lineSpacingExtra: Int = 12,//行间距

@ -1,11 +1,13 @@
package io.legado.app.service.help package io.legado.app.service.help
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -292,6 +294,11 @@ object ReadBook {
) { ) {
Coroutine.async { Coroutine.async {
if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) {
chapter.title = when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese(chapter.title)
2 -> HanLP.convertToTraditionalChinese(chapter.title)
else -> chapter.title
}
val contents = BookHelp.disposeContent( val contents = BookHelp.disposeContent(
chapter.title, chapter.title,
book!!.name, book!!.name,

@ -103,9 +103,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
tv_title_mode.onClick { tv_title_mode.onClick {
showTitleConfig() showTitleConfig()
} }
tv_text_bold.onClick { text_font_weight_converter.onChanged {
ReadBookConfig.textBold = !ReadBookConfig.textBold
tv_text_bold.isSelected = ReadBookConfig.textBold
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
tv_text_font.onClick { tv_text_font.onClick {
@ -215,7 +213,6 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
private fun upStyle() { private fun upStyle() {
ReadBookConfig.let { ReadBookConfig.let {
tv_text_bold.isSelected = it.textBold
dsb_text_size.progress = it.textSize - 5 dsb_text_size.progress = it.textSize - 5
dsb_text_letter_spacing.progress = (it.letterSpacing * 100).toInt() + 50 dsb_text_letter_spacing.progress = (it.letterSpacing * 100).toInt() + 50
dsb_line_size.progress = it.lineSpacingExtra dsb_line_size.progress = it.lineSpacingExtra

@ -0,0 +1,55 @@
package io.legado.app.ui.book.read.config
import android.content.Context
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.AttributeSet
import io.legado.app.R
import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.widget.text.StrokeTextView
import org.jetbrains.anko.sdk27.listeners.onClick
class TextFontWeightConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) {
private val spannableString = SpannableString("中/粗/细")
private var enabledSpan: ForegroundColorSpan = ForegroundColorSpan(context.accentColor)
private var onChanged: (() -> Unit)? = null
init {
text = spannableString
if (!isInEditMode) {
upUi(ReadBookConfig.textBold)
}
onClick {
selectType()
}
}
private fun upUi(type: Int) {
spannableString.removeSpan(enabledSpan)
when (type) {
0 -> spannableString.setSpan(enabledSpan, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
1 -> spannableString.setSpan(enabledSpan, 2, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
2 -> spannableString.setSpan(enabledSpan, 4, 5, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
}
text = spannableString
}
private fun selectType() {
context.alert(titleResource = R.string.text_font_weight_converter) {
items(context.resources.getStringArray(R.array.text_font_weight).toList()) { _, i ->
ReadBookConfig.textBold = i
upUi(i)
onChanged?.invoke()
}
}.show()
}
fun onChanged(unit: () -> Unit) {
onChanged = unit
}
}

@ -6,6 +6,7 @@ import android.text.Layout
import android.text.StaticLayout import android.text.StaticLayout
import android.text.TextPaint import android.text.TextPaint
import android.text.TextUtils import android.text.TextUtils
import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
@ -78,6 +79,7 @@ object ChapterProvider {
item.title = bookChapter.title item.title = bookChapter.title
item.upLinesPosition() item.upLinesPosition()
} }
return TextChapter( return TextChapter(
bookChapter.index, bookChapter.index,
bookChapter.title, bookChapter.title,
@ -270,23 +272,37 @@ object ChapterProvider {
App.INSTANCE.removePref(PreferKey.readBookFont) App.INSTANCE.removePref(PreferKey.readBookFont)
Typeface.SANS_SERIF Typeface.SANS_SERIF
} }
// 字体统一处理
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)
}
2 -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
Pair(normal, Typeface.create(typeface, 300, false))
else
Pair(normal, normal)
}
else -> Pair(bold, normal)
}
//标题 //标题
titlePaint = TextPaint() titlePaint = TextPaint()
titlePaint.color = ReadBookConfig.durConfig.textColor() titlePaint.color = ReadBookConfig.durConfig.textColor()
titlePaint.letterSpacing = ReadBookConfig.letterSpacing titlePaint.letterSpacing = ReadBookConfig.letterSpacing
titlePaint.typeface = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { titlePaint.typeface = titleFont
Typeface.create(typeface, if (ReadBookConfig.textBold) 900 else 700, false)
} else {
Typeface.create(typeface, Typeface.BOLD)
}
titlePaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat() titlePaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat()
titlePaint.isAntiAlias = true titlePaint.isAntiAlias = true
//正文 //正文
contentPaint = TextPaint() contentPaint = TextPaint()
contentPaint.color = ReadBookConfig.durConfig.textColor() contentPaint.color = ReadBookConfig.durConfig.textColor()
contentPaint.letterSpacing = ReadBookConfig.letterSpacing contentPaint.letterSpacing = ReadBookConfig.letterSpacing
val style = if (ReadBookConfig.textBold) Typeface.BOLD else Typeface.NORMAL contentPaint.typeface = textFont
contentPaint.typeface = Typeface.create(typeface, style)
contentPaint.textSize = ReadBookConfig.textSize.sp.toFloat() contentPaint.textSize = ReadBookConfig.textSize.sp.toFloat()
contentPaint.isAntiAlias = true contentPaint.isAntiAlias = true
//间距 //间距

@ -207,11 +207,7 @@ class ContentView(context: Context) : FrameLayout(context) {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun setProgress(textPage: TextPage) = textPage.apply { fun setProgress(textPage: TextPage) = textPage.apply {
val title = when (AppConfig.chineseConverterType) { val title = textPage.title
1 -> HanLP.convertToSimplifiedChinese(textPage.title)
2 -> HanLP.convertToTraditionalChinese(textPage.title)
else -> textPage.title
}
tvTitle?.text = title tvTitle?.text = title
tvPage?.text = "${index.plus(1)}/$pageSize" tvPage?.text = "${index.plus(1)}/$pageSize"
tvTotalProgress?.text = readProgress tvTotalProgress?.text = readProgress

@ -37,15 +37,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" /> android:layout_weight="1" />
<io.legado.app.ui.widget.text.StrokeTextView <io.legado.app.ui.book.read.config.TextFontWeightConverter
android:id="@+id/tv_text_bold" android:id="@+id/text_font_weight_converter"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="6dp" android:paddingLeft="6dp"
android:paddingRight="6dp" android:paddingRight="6dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:text="@string/text_bold"
android:gravity="center" android:gravity="center"
android:textSize="14sp" android:textSize="14sp"
app:radius="3dp" /> app:radius="3dp" />

@ -49,4 +49,9 @@
<item>系統等寬字體</item> <item>系統等寬字體</item>
</string-array> </string-array>
<string-array name="text_font_weight">
<item>正常</item>
<item>粗體</item>
<item>細體</item>
</string-array>
</resources> </resources>

@ -694,4 +694,5 @@
<string name="text_full_justify">文字兩端對齊</string> <string name="text_full_justify">文字兩端對齊</string>
<string name="auto_page_speed">自動翻頁速度</string> <string name="auto_page_speed">自動翻頁速度</string>
<string name="sort_by_url">地址排序</string> <string name="sort_by_url">地址排序</string>
<string name="text_font_weight_converter">文章字體轉換</string>
</resources> </resources>

@ -106,4 +106,9 @@
<item>頁數及進度</item> <item>頁數及進度</item>
</string-array> </string-array>
<string-array name="text_font_weight">
<item>正常</item>
<item>粗體</item>
<item>細體</item>
</string-array>
</resources> </resources>

@ -696,5 +696,6 @@
<string name="text_full_justify">文字兩端對齊</string> <string name="text_full_justify">文字兩端對齊</string>
<string name="auto_page_speed">自動翻頁速度</string> <string name="auto_page_speed">自動翻頁速度</string>
<string name="sort_by_url">地址排序</string> <string name="sort_by_url">地址排序</string>
<string name="text_font_weight_converter">文章字體轉換</string>
</resources> </resources>

@ -106,4 +106,10 @@
<item>页数及进度</item> <item>页数及进度</item>
</string-array> </string-array>
<string-array name="text_font_weight">
<item>正常</item>
<item>粗体</item>
<item>细体</item>
</string-array>
</resources> </resources>

@ -676,6 +676,7 @@
<string name="hideHeader">隐藏页眉</string> <string name="hideHeader">隐藏页眉</string>
<string name="hideFooter">隐藏页脚</string> <string name="hideFooter">隐藏页脚</string>
<string name="switchLayout">切换布局</string> <string name="switchLayout">切换布局</string>
<string name="text_font_weight_converter">文章字重切换</string>
<!--color--> <!--color-->
<string name="primary">主色调</string> <string name="primary">主色调</string>

Loading…
Cancel
Save