pull/2385/head
Horis 2 years ago
parent e0aa45b7f5
commit a0f281f0ee
  1. 1
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 1
      app/src/main/java/io/legado/app/help/book/ContentProcessor.kt
  4. 3
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  5. 25
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  6. 44
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  7. 3
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  8. 3
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  9. 1
      app/src/main/res/values-es-rES/strings.xml
  10. 1
      app/src/main/res/values-ja-rJP/strings.xml
  11. 1
      app/src/main/res/values-pt-rBR/strings.xml
  12. 1
      app/src/main/res/values-zh-rHK/strings.xml
  13. 1
      app/src/main/res/values-zh-rTW/strings.xml
  14. 1
      app/src/main/res/values-zh/strings.xml
  15. 5
      app/src/main/res/values/array_values.xml
  16. 5
      app/src/main/res/values/arrays.xml
  17. 1
      app/src/main/res/values/strings.xml
  18. 9
      app/src/main/res/xml/pref_config_read.xml

@ -30,4 +30,5 @@ object EventBus {
const val SEARCH_RESULT = "searchResult" const val SEARCH_RESULT = "searchResult"
const val FILE_SOURCE_DOWNLOAD_DONE = "fileSourceDownloadDone" const val FILE_SOURCE_DOWNLOAD_DONE = "fileSourceDownloadDone"
const val updateReadActionBar = "updateReadActionBar" const val updateReadActionBar = "updateReadActionBar"
const val UP_SEEK_BAR = "upSeekBar"
} }

@ -114,6 +114,7 @@ object PreferKey {
const val asyncLoadImage = "asyncLoadImage" const val asyncLoadImage = "asyncLoadImage"
const val ignoreAudioFocus = "ignoreAudioFocus" const val ignoreAudioFocus = "ignoreAudioFocus"
const val parallelExportBook = "parallelExportBook" const val parallelExportBook = "parallelExportBook"
const val progressBarBehavior = "progressBarBehavior"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -136,6 +136,7 @@ class ContentProcessor private constructor(
suspend fun replaceContent(content: String): String { suspend fun replaceContent(content: String): String {
var mContent = content var mContent = content
mContent = mContent.lines().joinToString("\n") { it.trim() }
getContentReplaceRules().forEach { item -> getContentReplaceRules().forEach { item ->
if (item.pattern.isNotEmpty()) { if (item.pattern.isNotEmpty()) {
try { try {

@ -339,6 +339,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val doublePageHorizontal: String? val doublePageHorizontal: String?
get() = appCtx.getPrefString(PreferKey.doublePageHorizontal) get() = appCtx.getPrefString(PreferKey.doublePageHorizontal)
val progressBarBehavior: String?
get() = appCtx.getPrefString(PreferKey.progressBarBehavior, "page")
var searchGroup: String var searchGroup: String
get() = appCtx.getPrefString("searchGroup") ?: "" get() = appCtx.getPrefString("searchGroup") ?: ""
set(value) { set(value) {

@ -757,7 +757,7 @@ class ReadBookActivity : BaseReadBookActivity(),
launch { launch {
autoPageProgress = 0 autoPageProgress = 0
binding.readView.upContent(relativePosition, resetPageOffset) binding.readView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(ReadBook.durPageIndex) upSeekBarProgress()
loadStates = false loadStates = false
success?.invoke() success?.invoke()
} }
@ -775,11 +775,22 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun pageChanged() { override fun pageChanged() {
launch { launch {
autoPageProgress = 0 autoPageProgress = 0
binding.readMenu.setSeekPage(ReadBook.durPageIndex) upSeekBarProgress()
startBackupJob() startBackupJob()
} }
} }
/**
* 更新进度条位置
*/
private fun upSeekBarProgress() {
val progress = when (AppConfig.progressBarBehavior) {
"page" -> ReadBook.durPageIndex
else /* chapter */ -> ReadBook.durChapterIndex
}
binding.readMenu.setSeekPage(progress)
}
/** /**
* 显示菜单 * 显示菜单
*/ */
@ -915,6 +926,13 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
/**
* 跳转到指定章节
*/
override fun skipToChapter(index: Int) {
viewModel.openChapter(index)
}
/** /**
* 打开搜索界面 * 打开搜索界面
*/ */
@ -1282,6 +1300,9 @@ class ReadBookActivity : BaseReadBookActivity(),
observeEvent<Boolean>(EventBus.updateReadActionBar) { observeEvent<Boolean>(EventBus.updateReadActionBar) {
binding.readMenu.reset() binding.readMenu.reset()
} }
observeEvent<Boolean>(EventBus.UP_SEEK_BAR) {
binding.readMenu.upSeekBar()
}
} }
private fun upScreenTimeOut() { private fun upScreenTimeOut() {

@ -45,6 +45,7 @@ class ReadMenu @JvmOverloads constructor(
var cnaShowMenu: Boolean = false var cnaShowMenu: Boolean = false
private val callBack: CallBack get() = activity as CallBack private val callBack: CallBack get() = activity as CallBack
private val binding = ViewReadMenuBinding.inflate(LayoutInflater.from(context), this, true) private val binding = ViewReadMenuBinding.inflate(LayoutInflater.from(context), this, true)
private var confirmSkipToChapter: Boolean = false
private val menuTopIn: Animation by lazy { private val menuTopIn: Animation by lazy {
loadAnimation(context, R.anim.anim_readbook_top_in) loadAnimation(context, R.anim.anim_readbook_top_in)
} }
@ -370,7 +371,27 @@ class ReadMenu @JvmOverloads constructor(
seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener { seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener {
override fun onStopTrackingTouch(seekBar: SeekBar) { override fun onStopTrackingTouch(seekBar: SeekBar) {
ReadBook.skipToPage(seekBar.progress) when (AppConfig.progressBarBehavior) {
"page" -> ReadBook.skipToPage(seekBar.progress)
"chapter" -> {
if (confirmSkipToChapter) {
callBack.skipToChapter(seekBar.progress)
} else {
context.alert("章节跳转确认", "确定要跳转章节吗?") {
yesButton {
confirmSkipToChapter = true
callBack.skipToChapter(seekBar.progress)
}
noButton {
upSeekBar()
}
onCancelled {
upSeekBar()
}
}
}
}
}
} }
}) })
@ -453,8 +474,7 @@ class ReadMenu @JvmOverloads constructor(
} else { } else {
binding.tvChapterUrl.gone() binding.tvChapterUrl.gone()
} }
binding.seekReadPage.max = it.pageSize.minus(1) upSeekBar()
binding.seekReadPage.progress = ReadBook.durPageIndex
binding.tvPre.isEnabled = ReadBook.durChapterIndex != 0 binding.tvPre.isEnabled = ReadBook.durChapterIndex != 0
binding.tvNext.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1 binding.tvNext.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
} ?: let { } ?: let {
@ -463,6 +483,23 @@ class ReadMenu @JvmOverloads constructor(
} }
} }
fun upSeekBar() {
binding.seekReadPage.apply {
when (AppConfig.progressBarBehavior) {
"page" -> {
ReadBook.curTextChapter?.let {
max = it.pageSize.minus(1)
progress = ReadBook.durPageIndex
}
}
"chapter" -> {
max = ReadBook.chapterSize - 1
progress = ReadBook.durChapterIndex
}
}
}
}
fun setSeekPage(seek: Int) { fun setSeekPage(seek: Int) {
binding.seekReadPage.progress = seek binding.seekReadPage.progress = seek
} }
@ -493,6 +530,7 @@ class ReadMenu @JvmOverloads constructor(
fun showLogin() fun showLogin()
fun payAction() fun payAction()
fun disableSource() fun disableSource()
fun skipToChapter(index: Int)
} }
} }

@ -137,6 +137,9 @@ class MoreConfigDialog : DialogFragment() {
PreferKey.readBarStyleFollowPage -> { PreferKey.readBarStyleFollowPage -> {
postEvent(EventBus.updateReadActionBar, true) postEvent(EventBus.updateReadActionBar, true)
} }
PreferKey.progressBarBehavior -> {
postEvent(EventBus.UP_SEEK_BAR, true)
}
} }
} }

@ -234,6 +234,9 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
mode = HandleFileContract.DIR_SYS mode = HandleFileContract.DIR_SYS
} }
} }
neutralButton("不想设置") {
AppConfig.defaultBookTreeUri = "null"
}
noButton() noButton()
} }
} }

@ -1036,4 +1036,5 @@
<string name="net_no_group">网络未分组</string> <string name="net_no_group">网络未分组</string>
<string name="local_no_group">本地未分组</string> <string name="local_no_group">本地未分组</string>
<string name="parallel_export_book">多线程导出TXT</string> <string name="parallel_export_book">多线程导出TXT</string>
<string name="progress_bar_behavior">进度条行为</string>
</resources> </resources>

@ -1039,4 +1039,5 @@
<string name="net_no_group">网络未分组</string> <string name="net_no_group">网络未分组</string>
<string name="local_no_group">本地未分组</string> <string name="local_no_group">本地未分组</string>
<string name="parallel_export_book">多线程导出TXT</string> <string name="parallel_export_book">多线程导出TXT</string>
<string name="progress_bar_behavior">进度条行为</string>
</resources> </resources>

@ -1039,4 +1039,5 @@
<string name="net_no_group">网络未分组</string> <string name="net_no_group">网络未分组</string>
<string name="local_no_group">本地未分组</string> <string name="local_no_group">本地未分组</string>
<string name="parallel_export_book">多线程导出TXT</string> <string name="parallel_export_book">多线程导出TXT</string>
<string name="progress_bar_behavior">进度条行为</string>
</resources> </resources>

@ -1036,4 +1036,5 @@
<string name="net_no_group">网络未分组</string> <string name="net_no_group">网络未分组</string>
<string name="local_no_group">本地未分组</string> <string name="local_no_group">本地未分组</string>
<string name="parallel_export_book">多线程导出TXT</string> <string name="parallel_export_book">多线程导出TXT</string>
<string name="progress_bar_behavior">进度条行为</string>
</resources> </resources>

@ -1038,4 +1038,5 @@
<string name="net_no_group">网络未分组</string> <string name="net_no_group">网络未分组</string>
<string name="local_no_group">本地未分组</string> <string name="local_no_group">本地未分组</string>
<string name="parallel_export_book">多线程导出TXT</string> <string name="parallel_export_book">多线程导出TXT</string>
<string name="progress_bar_behavior">进度条行为</string>
</resources> </resources>

@ -1038,4 +1038,5 @@
<string name="net_no_group">网络未分组</string> <string name="net_no_group">网络未分组</string>
<string name="local_no_group">本地未分组</string> <string name="local_no_group">本地未分组</string>
<string name="parallel_export_book">多线程导出TXT</string> <string name="parallel_export_book">多线程导出TXT</string>
<string name="progress_bar_behavior">进度条行为</string>
</resources> </resources>

@ -39,6 +39,11 @@
<item>2</item> <item>2</item>
</string-array> </string-array>
<string-array name="progress_bar_behavior_value">
<item>page</item>
<item>chapter</item>
</string-array>
<string-array name="language_value"> <string-array name="language_value">
<item>auto</item> <item>auto</item>
<item>zh</item> <item>zh</item>

@ -67,6 +67,11 @@
<item>横屏双页 竖屏单页</item> <item>横屏双页 竖屏单页</item>
</string-array> </string-array>
<string-array name="progress_bar_behavior_title">
<item>调整本章页数</item>
<item>调整章节位置</item>
</string-array>
<string-array name="icon_names" tools:ignore="Typos"> <string-array name="icon_names" tools:ignore="Typos">
<item>iconMain</item> <item>iconMain</item>
<item>icon1</item> <item>icon1</item>

@ -1039,4 +1039,5 @@
<string name="net_no_group">网络未分组</string> <string name="net_no_group">网络未分组</string>
<string name="local_no_group">本地未分组</string> <string name="local_no_group">本地未分组</string>
<string name="parallel_export_book">多线程导出TXT</string> <string name="parallel_export_book">多线程导出TXT</string>
<string name="progress_bar_behavior">进度条行为</string>
</resources> </resources>

@ -50,6 +50,15 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:isBottomBackground="true" /> app:isBottomBackground="true" />
<io.legado.app.lib.prefs.NameListPreference
android:defaultValue="page"
android:entries="@array/progress_bar_behavior_title"
android:entryValues="@array/progress_bar_behavior_value"
android:key="progressBarBehavior"
android:title="@string/progress_bar_behavior"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference <io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="useZhLayout" android:key="useZhLayout"

Loading…
Cancel
Save