feat: 优化

pull/277/head
kunfei 5 years ago
parent 204ebe072f
commit 910646e599
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 1
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  4. 8
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  5. 1
      app/src/main/res/values-zh-rHK/strings.xml
  6. 1
      app/src/main/res/values/strings.xml
  7. 6
      app/src/main/res/xml/pref_config_read.xml

@ -43,4 +43,5 @@ object PreferKey {
const val readStyleSelect = "readStyleSelect" const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces" const val systemTypefaces = "system_typefaces"
const val readBodyToLh = "readBodyToLh" const val readBodyToLh = "readBodyToLh"
const val textFullJustify = "textFullJustify"
} }

@ -127,6 +127,7 @@ object ReadBookConfig {
} }
var isScroll = pageAnim == 3 var isScroll = pageAnim == 3
val clickTurnPage get() = App.INSTANCE.getPrefBoolean(PreferKey.clickTurnPage, true) val clickTurnPage get() = App.INSTANCE.getPrefBoolean(PreferKey.clickTurnPage, true)
val textFullJustify get() = App.INSTANCE.getPrefBoolean(PreferKey.textFullJustify, true)
var bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2) var bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2)
set(value) { set(value) {
field = value field = value

@ -111,6 +111,9 @@ class MoreConfigDialog : DialogFragment() {
Help.setOrientation(it) Help.setOrientation(it)
} }
} }
PreferKey.textFullJustify -> {
postEvent(EventBus.UP_CONFIG, true)
}
} }
} }

@ -161,6 +161,10 @@ object ChapterProvider {
desiredWidth: Float desiredWidth: Float
) { ) {
var x = 0f var x = 0f
if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, x)
return
}
val bodyIndent = ReadBookConfig.bodyIndent val bodyIndent = ReadBookConfig.bodyIndent
val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length
bodyIndent.toStringArray().forEach { bodyIndent.toStringArray().forEach {
@ -186,6 +190,10 @@ object ChapterProvider {
desiredWidth: Float, desiredWidth: Float,
startX: Float startX: Float
) { ) {
if (!ReadBookConfig.textFullJustify) {
addCharsToLineLast(textLine, words, textPaint, startX)
return
}
val gapCount: Int = words.length - 1 val gapCount: Int = words.length - 1
val d = (visibleWidth - desiredWidth) / gapCount val d = (visibleWidth - desiredWidth) / gapCount
var x = startX var x = startX

@ -691,4 +691,5 @@
<string name="hideFooter">隱藏頁脚</string> <string name="hideFooter">隱藏頁脚</string>
<string name="auto_change_source">自動換源</string> <string name="auto_change_source">自動換源</string>
<string name="to_bottom">置底</string> <string name="to_bottom">置底</string>
<string name="text_full_justify">文字兩端對齊</string>
</resources> </resources>

@ -693,5 +693,6 @@
<string name="night_background_color">夜间,背景色</string> <string name="night_background_color">夜间,背景色</string>
<string name="night_navbar_color">夜间,底栏色</string> <string name="night_navbar_color">夜间,底栏色</string>
<string name="auto_change_source">自动换源</string> <string name="auto_change_source">自动换源</string>
<string name="text_full_justify">文字两端对齐</string>
</resources> </resources>

@ -36,6 +36,12 @@
android:key="hideNavigationBar" android:key="hideNavigationBar"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:title="@string/text_full_justify"
android:key="textFullJustify"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/volume_key_page" android:title="@string/volume_key_page"

Loading…
Cancel
Save