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. 132
      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>

@ -2,79 +2,85 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<io.legado.app.ui.widget.prefs.NameListPreference <io.legado.app.ui.widget.prefs.NameListPreference
android:key="@string/pk_requested_direction" android:key="@string/pk_requested_direction"
android:defaultValue="0" android:defaultValue="0"
android:title="@string/screen_direction" android:title="@string/screen_direction"
android:entries="@array/screen_direction_title" android:entries="@array/screen_direction_title"
android:entryValues="@array/screen_direction_value" android:entryValues="@array/screen_direction_value"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.NameListPreference <io.legado.app.ui.widget.prefs.NameListPreference
android:key="keep_light" android:key="keep_light"
android:defaultValue="0" android:defaultValue="0"
android:entryValues="@array/screen_time_out_value" android:entryValues="@array/screen_time_out_value"
android:entries="@array/screen_time_out" android:entries="@array/screen_time_out"
android:title="@string/keep_light" android:title="@string/keep_light"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/pt_hide_status_bar" android:title="@string/pt_hide_status_bar"
android:key="hideStatusBar" android:key="hideStatusBar"
app:iconSpaceReserved="false" /> 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/read_body_to_lh" android:title="@string/read_body_to_lh"
android:key="readBodyToLh" android:key="readBodyToLh"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/pt_hide_navigation_bar" android:title="@string/pt_hide_navigation_bar"
android:key="hideNavigationBar" android:key="hideNavigationBar"
app:iconSpaceReserved="false" /> 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/text_full_justify"
android:key="volumeKeyPage" android:key="textFullJustify"
app:iconSpaceReserved="false" /> 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/click_turn_page" android:title="@string/volume_key_page"
android:key="clickTurnPage" android:key="volumeKeyPage"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="true"
android:title="@string/click_all_next_page" android:title="@string/click_turn_page"
android:key="clickAllNext" android:key="clickTurnPage"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:title="@string/volume_key_page_on_play" android:title="@string/click_all_next_page"
android:key="volumeKeyPageOnPlay" android:key="clickAllNext"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="false"
android:title="@string/auto_change_source" android:title="@string/volume_key_page_on_play"
android:key="autoChangeSource" android:key="volumeKeyPageOnPlay"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="true"
android:title="@string/selectText" android:title="@string/auto_change_source"
android:key="selectText" android:key="autoChangeSource"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.SwitchPreference
android:key="customPageKey" android:defaultValue="false"
android:title="@string/custom_page_key" android:title="@string/selectText"
app:iconSpaceReserved="false" /> android:key="selectText"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference
android:key="customPageKey"
android:title="@string/custom_page_key"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>
Loading…
Cancel
Save