Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Dec 22, 2023
1 parent 36eb6be commit 456188a
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 36 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/io/legado/app/constant/PreferKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ object PreferKey {
const val showBookshelfFastScroller = "showBookshelfFastScroller"
const val importKeepEnable = "importKeepEnable"
const val previewImageByClick = "previewImageByClick"
const val volumeKeyPageOnLongPress = "volumeKeyPageOnLongPress"
const val volumeKeyPage = "volumeKeyPage"
const val volumeKeyPageOnPlay = "volumeKeyPageOnPlay"

const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/data/entities/Book.kt
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ data class Book(
appDb.bookDao.delete(this)
}

@Suppress("ConstPropertyName")
companion object {
const val hTag = 2L
const val rubyTag = 4L
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/io/legado/app/help/config/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import io.legado.app.utils.sysConfiguration
import io.legado.app.utils.toastOnUi
import splitties.init.appCtx

@Suppress("MemberVisibilityCanBePrivate")
@Suppress("MemberVisibilityCanBePrivate", "ConstPropertyName")
object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val isCronet = appCtx.getPrefBoolean(PreferKey.cronet)
var useAntiAlias = appCtx.getPrefBoolean(PreferKey.antiAlias)
Expand Down Expand Up @@ -468,6 +468,15 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val progressBarBehavior: String?
get() = appCtx.getPrefString(PreferKey.progressBarBehavior, "page")

val volumeKeyPageOnLongPress
get() = appCtx.getPrefBoolean(PreferKey.volumeKeyPageOnLongPress, false)

val volumeKeyPage
get() = appCtx.getPrefBoolean(PreferKey.volumeKeyPage, true)

val volumeKeyPageOnPlay
get() = appCtx.getPrefBoolean(PreferKey.volumeKeyPageOnPlay, true)

var searchScope: String
get() = appCtx.getPrefString("searchScope") ?: ""
set(value) {
Expand Down
44 changes: 25 additions & 19 deletions app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ import io.legado.app.ui.book.audio.AudioPlayActivity
import io.legado.app.ui.book.bookmark.BookmarkDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
import io.legado.app.ui.book.changesource.ChangeChapterSourceDialog
import io.legado.app.ui.book.read.config.*
import io.legado.app.ui.book.read.config.AutoReadDialog
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR
import io.legado.app.ui.book.read.config.MoreConfigDialog
import io.legado.app.ui.book.read.config.ReadAloudDialog
import io.legado.app.ui.book.read.config.ReadStyleDialog
import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_COLOR
import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_DIVIDER_COLOR
import io.legado.app.ui.book.read.page.ContentTextView
Expand Down Expand Up @@ -570,7 +573,7 @@ class ReadBookActivity : BaseReadBookActivity(),
/**
* 按键事件
*/
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (menuLayoutIsVisible) {
return super.onKeyDown(keyCode, event)
}
Expand All @@ -592,13 +595,13 @@ class ReadBookActivity : BaseReadBookActivity(),
}

keyCode == KeyEvent.KEYCODE_VOLUME_UP -> {
if (volumeKeyPage(PageDirection.PREV)) {
if (volumeKeyPage(PageDirection.PREV, event.repeatCount > 0)) {
return true
}
}

keyCode == KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (volumeKeyPage(PageDirection.NEXT)) {
if (volumeKeyPage(PageDirection.NEXT, event.repeatCount > 0)) {
return true
}
}
Expand Down Expand Up @@ -628,10 +631,10 @@ class ReadBookActivity : BaseReadBookActivity(),
/**
* 松开按键事件
*/
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (volumeKeyPage(PageDirection.NONE)) {
if (volumeKeyPage(PageDirection.NONE, event.repeatCount > 0)) {
return true
}
}
Expand Down Expand Up @@ -824,20 +827,23 @@ class ReadBookActivity : BaseReadBookActivity(),
/**
* 音量键翻页
*/
private fun volumeKeyPage(direction: PageDirection): Boolean {
if (!binding.readMenu.isVisible) {
if (getPrefBoolean("volumeKeyPage", true)) {
if (getPrefBoolean("volumeKeyPageOnPlay")
|| !BaseReadAloudService.isPlay()
) {
binding.readView.cancelSelect()
binding.readView.pageDelegate?.isCancel = false
binding.readView.pageDelegate?.keyTurnPage(direction)
return true
}
}
private fun volumeKeyPage(direction: PageDirection, longPress: Boolean): Boolean {
if (menuLayoutIsVisible) {
return false
}
return false
if (!AppConfig.volumeKeyPage) {
return false
}
if (!AppConfig.volumeKeyPageOnPlay && BaseReadAloudService.isPlay()) {
return false
}
if (!AppConfig.volumeKeyPageOnLongPress && longPress) {
return false
}
binding.readView.cancelSelect()
binding.readView.pageDelegate?.isCancel = false
binding.readView.pageDelegate?.keyTurnPage(direction)
return true
}

override fun upMenuView() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-es-rES/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<string-array name="screen_time_out">
<item>Predeterminado</item>
<item>1 min</item>
<item>2 min</item>
<item>3 min</item>
<item>5 min</item>
<item>10 min</item>
<item>Siempre</item>
</string-array>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1139,4 +1139,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功,3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1142,4 +1142,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功,3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values-pt-rBR/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<string-array name="screen_time_out">
<item>Padrão</item>
<item>1 min</item>
<item>2 min</item>
<item>3 min</item>
<item>5 min</item>
<item>10 min</item>
<item>Sempre</item>
</string-array>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1142,4 +1142,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功,3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values-vi/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<string-array name="screen_time_out">
<item>Mặc định</item>
<item>1 phút</item>
<item>2 phút</item>
<item>3 phút</item>
<item>5 phút</item>
<item>10 phút</item>
<item>Thường Sáng</item>
</string-array>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1138,4 +1138,5 @@ Còn </string>
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功,3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values-zh-rHK/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<string-array name="screen_time_out">
<item>默認</item>
<item>1分鐘</item>
<item>2分鐘</item>
<item>3分鐘</item>
<item>5分鐘</item>
<item>10分鐘</item>
<item>常亮</item>
</string-array>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1139,4 +1139,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功,3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values-zh-rTW/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<string-array name="screen_time_out">
<item>預設</item>
<item>1分鐘</item>
<item>2分鐘</item>
<item>3分鐘</item>
<item>5分鐘</item>
<item>10分鐘</item>
<item>常亮</item>
</string-array>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1141,4 +1141,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功,3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values-zh/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<string-array name="screen_time_out">
<item>默认</item>
<item>1分钟</item>
<item>2分钟</item>
<item>3分钟</item>
<item>5分钟</item>
<item>10分钟</item>
<item>常亮</item>
</string-array>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1141,4 +1141,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功,3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/array_values.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<string-array name="screen_time_out_value">
<item>0</item>
<item>60</item>
<item>120</item>
<item>180</item>
<item>300</item>
<item>600</item>
<item>-1</item>
</string-array>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<string-array name="screen_time_out">
<item>Default</item>
<item>1 min</item>
<item>2 min</item>
<item>3 min</item>
<item>5 min</item>
<item>10 min</item>
<item>Always</item>
</string-array>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1142,4 +1142,5 @@
<string name="adjust_chapter_page">Adjust of chapter page</string>
<string name="adjust_chapter_index">Adjust of chapter index</string>
<string name="clear_webview_data_success">Cleared successfully, automatically restarts the application after 3 seconds</string>
<string name="volume_key_page_on_long_press">Press and hold the volume key to turn the page</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/xml/pref_config_read.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
app:iconSpaceReserved="false"
app:isBottomBackground="true" />

<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="volumeKeyPageOnLongPress"
android:title="@string/volume_key_page_on_long_press"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />

<io.legado.app.lib.prefs.Preference
android:key="pageTouchSlop"
android:summary="@string/page_touch_slop_summary"
Expand Down

0 comments on commit 456188a

Please sign in to comment.