pull/2622/head
Horis 2 years ago
parent c71fb13916
commit c0bdf2bb30
  1. 1
      app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt
  2. 6
      app/src/main/java/io/legado/app/help/config/ReadTipConfig.kt
  3. 11
      app/src/main/java/io/legado/app/help/storage/BackupConfig.kt
  4. 12
      app/src/main/java/io/legado/app/model/ReadBook.kt
  5. 20
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  6. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  7. 27
      app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt
  8. 10
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  9. 18
      app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt
  10. 26
      app/src/main/res/layout/dialog_tip_config.xml
  11. 1
      app/src/main/res/values-es-rES/strings.xml
  12. 1
      app/src/main/res/values-ja-rJP/strings.xml
  13. 1
      app/src/main/res/values-pt-rBR/strings.xml
  14. 1
      app/src/main/res/values-zh-rHK/strings.xml
  15. 1
      app/src/main/res/values-zh-rTW/strings.xml
  16. 1
      app/src/main/res/values-zh/strings.xml
  17. 1
      app/src/main/res/values/strings.xml

@ -476,6 +476,7 @@ object ReadBookConfig {
var tipFooterMiddle: Int = ReadTipConfig.none, var tipFooterMiddle: Int = ReadTipConfig.none,
var tipFooterRight: Int = ReadTipConfig.pageAndTotal, var tipFooterRight: Int = ReadTipConfig.pageAndTotal,
var tipColor: Int = 0, var tipColor: Int = 0,
var tipDividerColor: Int = -1,
var headerMode: Int = 0, var headerMode: Int = 0,
var footerMode: Int = 0 var footerMode: Int = 0
) { ) {

@ -78,6 +78,12 @@ object ReadTipConfig {
ReadBookConfig.config.tipColor = value ReadBookConfig.config.tipColor = value
} }
var tipDividerColor: Int
get() = ReadBookConfig.config.tipDividerColor
set(value) {
ReadBookConfig.config.tipDividerColor = value
}
fun getHeaderModes(context: Context): LinkedHashMap<Int, String> { fun getHeaderModes(context: Context): LinkedHashMap<Int, String> {
return linkedMapOf( return linkedMapOf(
Pair(0, context.getString(R.string.hide_when_status_bar_show)), Pair(0, context.getString(R.string.hide_when_status_bar_show)),

@ -62,7 +62,16 @@ object BackupConfig {
PreferKey.shareLayout, PreferKey.shareLayout,
PreferKey.hideStatusBar, PreferKey.hideStatusBar,
PreferKey.hideNavigationBar, PreferKey.hideNavigationBar,
PreferKey.autoReadSpeed PreferKey.autoReadSpeed,
PreferKey.clickActionTL,
PreferKey.clickActionTC,
PreferKey.clickActionTR,
PreferKey.clickActionML,
PreferKey.clickActionMC,
PreferKey.clickActionMR,
PreferKey.clickActionBL,
PreferKey.clickActionBC,
PreferKey.clickActionBR
) )

@ -42,10 +42,13 @@ object ReadBook : CoroutineScope by MainScope() {
private val loadingChapters = arrayListOf<Int>() private val loadingChapters = arrayListOf<Int>()
private val readRecord = ReadRecord() private val readRecord = ReadRecord()
var readStartTime: Long = System.currentTimeMillis() var readStartTime: Long = System.currentTimeMillis()
/* 跳转历史记录 */ /* 跳转历史记录 */
var bookProgressHistory: List<BookProgress>? = null var bookProgressHistory: List<BookProgress>? = null
/* 跳转进度前进度记录 */ /* 跳转进度前进度记录 */
var lastBookPress: BookProgress? = null var lastBookPress: BookProgress? = null
/* web端阅读进度记录 */ /* web端阅读进度记录 */
var webBookProgress: BookProgress? = null var webBookProgress: BookProgress? = null
@ -54,6 +57,7 @@ object ReadBook : CoroutineScope by MainScope() {
if (lastBookPress != null) return //避免进度条连续跳转不能覆盖最初的进度记录 if (lastBookPress != null) return //避免进度条连续跳转不能覆盖最初的进度记录
lastBookPress = book?.let { BookProgress(it) } lastBookPress = book?.let { BookProgress(it) }
} }
//恢复跳转前进度 //恢复跳转前进度
fun restoreLastBookProcess() { fun restoreLastBookProcess() {
lastBookPress?.let { lastBookPress?.let {
@ -482,14 +486,10 @@ object ReadBook : CoroutineScope by MainScope() {
} }
} }
fun exit() {
callBack?.exit()
}
interface CallBack { interface CallBack {
fun upMenuView() fun upMenuView()
fun loadChapterList(book: Book) fun loadChapterList(book: Book, callback: (() -> Unit)? = null)
fun upContent( fun upContent(
relativePosition: Int = 0, relativePosition: Int = 0,
@ -503,8 +503,6 @@ object ReadBook : CoroutineScope by MainScope() {
fun upPageAnim() fun upPageAnim()
fun exit()
fun notifyBookChanged() fun notifyBookChanged()
} }

@ -49,6 +49,7 @@ import io.legado.app.ui.book.read.config.*
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR 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.BgTextConfigDialog.Companion.TEXT_COLOR
import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_COLOR 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 import io.legado.app.ui.book.read.page.ContentTextView
import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.ReadView
import io.legado.app.ui.book.read.page.entities.PageDirection import io.legado.app.ui.book.read.page.entities.PageDirection
@ -737,9 +738,9 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
override fun loadChapterList(book: Book) { override fun loadChapterList(book: Book, callback: (() -> Unit)?) {
ReadBook.upMsg(getString(R.string.toc_updateing)) ReadBook.upMsg(getString(R.string.toc_updateing))
viewModel.loadChapterList(book) viewModel.loadChapterList(book, callback)
} }
/** /**
@ -776,16 +777,6 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
override fun exit() {
ReadBook.book?.let {
if (!ReadBook.inBookshelf) {
viewModel.removeFromBookshelf { super.finish() }
} else {
super.finish()
}
} ?: super.finish()
}
override fun notifyBookChanged() { override fun notifyBookChanged() {
bookChanged = true bookChanged = true
} }
@ -1154,6 +1145,11 @@ class ReadBookActivity : BaseReadBookActivity(),
postEvent(EventBus.TIP_COLOR, "") postEvent(EventBus.TIP_COLOR, "")
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
TIP_DIVIDER_COLOR -> {
ReadTipConfig.tipDividerColor = color
postEvent(EventBus.TIP_COLOR, "")
postEvent(EventBus.UP_CONFIG, true)
}
} }
} }

@ -135,7 +135,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
/** /**
* 加载目录 * 加载目录
*/ */
fun loadChapterList(book: Book) { fun loadChapterList(book: Book, callback: (() -> Unit)? = null) {
if (book.isLocal) { if (book.isLocal) {
execute { execute {
LocalBook.getChapterList(book).let { LocalBook.getChapterList(book).let {
@ -157,10 +157,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}") ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
} }
} }
}.onFinally {
callback?.invoke()
} }
} else { } else {
ReadBook.bookSource?.let { ReadBook.bookSource?.let {
viewModelScope.launch(IO) {
val oldBook = book.copy() val oldBook = book.copy()
WebBook.getChapterList(viewModelScope, it, book, true) WebBook.getChapterList(viewModelScope, it, book, true)
.onSuccess(IO) { cList -> .onSuccess(IO) { cList ->
@ -177,7 +178,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
}.onError { }.onError {
ReadBook.upMsg(context.getString(R.string.error_load_toc)) ReadBook.upMsg(context.getString(R.string.error_load_toc))
} }.onFinally {
callback?.invoke()
} }
} }
} }

@ -19,6 +19,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
companion object { companion object {
const val TIP_COLOR = 7897 const val TIP_COLOR = 7897
const val TIP_DIVIDER_COLOR = 7898
} }
private val binding by viewBinding(DialogTipConfigBinding::bind) private val binding by viewBinding(DialogTipConfigBinding::bind)
@ -33,6 +34,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
initEvent() initEvent()
observeEvent<String>(EventBus.TIP_COLOR) { observeEvent<String>(EventBus.TIP_COLOR) {
upTvTipColor() upTvTipColor()
upTvTipDividerColor()
} }
} }
@ -64,6 +66,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
} }
} }
upTvTipColor() upTvTipColor()
upTvTipDividerColor()
} }
private fun upTvTipColor() { private fun upTvTipColor() {
@ -75,6 +78,14 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
} }
} }
private fun upTvTipDividerColor() {
binding.tvTipDividerColor.text = when (ReadTipConfig.tipDividerColor) {
-1 -> "默认"
0 -> "跟随文字颜色"
else -> "#${ReadTipConfig.tipDividerColor.hexString}"
}
}
private fun initEvent() = binding.run { private fun initEvent() = binding.run {
rgTitleMode.setOnCheckedChangeListener { _, checkedId -> rgTitleMode.setOnCheckedChangeListener { _, checkedId ->
ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId) ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId)
@ -178,6 +189,22 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
} }
} }
} }
llTipDividerColor.setOnClickListener {
context?.selector(items = arrayListOf("默认", "跟随文字颜色", "自定义")) { _, i ->
when (i) {
0, 1 -> {
ReadTipConfig.tipDividerColor = i - 1
upTvTipDividerColor()
postEvent(EventBus.UP_CONFIG, true)
}
2 -> ColorPickerDialog.newBuilder()
.setShowAlphaSlider(false)
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setDialogId(TIP_DIVIDER_COLOR)
.show(requireActivity())
}
}
}
} }
private fun clearRepeat(repeat: Int) = ReadTipConfig.apply { private fun clearRepeat(repeat: Int) = ReadTipConfig.apply {

@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.view.isGone import androidx.core.view.isGone
@ -70,12 +71,21 @@ class PageView(context: Context) : FrameLayout(context) {
val tipColor = with(ReadTipConfig) { val tipColor = with(ReadTipConfig) {
if (tipColor == 0) it.textColor else tipColor if (tipColor == 0) it.textColor else tipColor
} }
val tipDividerColor = with(ReadTipConfig) {
when (tipDividerColor) {
-1 -> Color.parseColor("#66666666")
0 -> tipColor
else -> tipDividerColor
}
}
tvHeaderLeft.setColor(tipColor) tvHeaderLeft.setColor(tipColor)
tvHeaderMiddle.setColor(tipColor) tvHeaderMiddle.setColor(tipColor)
tvHeaderRight.setColor(tipColor) tvHeaderRight.setColor(tipColor)
tvFooterLeft.setColor(tipColor) tvFooterLeft.setColor(tipColor)
tvFooterMiddle.setColor(tipColor) tvFooterMiddle.setColor(tipColor)
tvFooterRight.setColor(tipColor) tvFooterRight.setColor(tipColor)
vwTopDivider.backgroundColor = tipDividerColor
vwBottomDivider.backgroundColor = tipDividerColor
upStatusBar() upStatusBar()
llHeader.setPadding( llHeader.setPadding(
it.headerPaddingLeft.dpToPx(), it.headerPaddingLeft.dpToPx(),

@ -8,7 +8,6 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter import androidx.fragment.app.FragmentPagerAdapter
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
@ -19,8 +18,10 @@ import io.legado.app.help.book.isLocalTxt
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.model.ReadBook
import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.toc.rule.TxtTocRuleDialog import io.legado.app.ui.book.toc.rule.TxtTocRuleDialog
import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.showDialogFragment import io.legado.app.utils.showDialogFragment
@ -30,7 +31,8 @@ import io.legado.app.utils.visible
/** /**
* 目录 * 目录
*/ */
class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() { class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
TxtTocRuleDialog.CallBack {
override val binding by viewBinding(ActivityChapterListBinding::inflate) override val binding by viewBinding(ActivityChapterListBinding::inflate)
override val viewModel by viewModels<TocViewModel>() override val viewModel by viewModels<TocViewModel>()
@ -38,6 +40,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
private lateinit var tabLayout: TabLayout private lateinit var tabLayout: TabLayout
private var menu: Menu? = null private var menu: Menu? = null
private var searchView: SearchView? = null private var searchView: SearchView? = null
private val waitDialog by lazy { WaitDialog(this) }
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
tabLayout = binding.titleBar.findViewById(R.id.tab_layout) tabLayout = binding.titleBar.findViewById(R.id.tab_layout)
@ -122,6 +125,17 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
override fun onTocRegexDialogResult(tocRegex: String) {
ReadBook.book?.let { book ->
book.tocUrl = tocRegex
waitDialog.show()
ReadBook.callBack?.loadChapterList(book) {
viewModel.initBook(book.bookUrl)
waitDialog.dismiss()
}
}
}
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private inner class TabFragmentPageAdapter : private inner class TabFragmentPageAdapter :
FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {

@ -322,6 +322,32 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/ll_tip_divider_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
tools:ignore="RtlHardcoded,RtlSymmetry">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dp"
android:text="@string/tip_divider_color"
android:textColor="@color/primaryText" />
<TextView
android:id="@+id/tv_tip_divider_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:textColor="@color/primaryText"
tools:text="@string/tip_divider_color" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>

@ -1059,4 +1059,5 @@
<string name="replace_state_change">替换(启用/禁用)</string> <string name="replace_state_change">替换(启用/禁用)</string>
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string>
</resources> </resources>

@ -1062,4 +1062,5 @@
<string name="replace_state_change">替换(启用/禁用)</string> <string name="replace_state_change">替换(启用/禁用)</string>
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string>
</resources> </resources>

@ -1062,4 +1062,5 @@
<string name="replace_state_change">替换(启用/禁用)</string> <string name="replace_state_change">替换(启用/禁用)</string>
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string>
</resources> </resources>

@ -1059,4 +1059,5 @@
<string name="replace_state_change">替换(启用/禁用)</string> <string name="replace_state_change">替换(启用/禁用)</string>
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string>
</resources> </resources>

@ -1061,4 +1061,5 @@
<string name="replace_state_change">取代(啟用/禁用)</string> <string name="replace_state_change">取代(啟用/禁用)</string>
<string name="show_last_update_time">顯示上次更新時間</string> <string name="show_last_update_time">顯示上次更新時間</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string>
</resources> </resources>

@ -1061,4 +1061,5 @@
<string name="replace_state_change">替换(启用/禁用)</string> <string name="replace_state_change">替换(启用/禁用)</string>
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string>
</resources> </resources>

@ -1062,4 +1062,5 @@
<string name="replace_state_change">替换(启用/禁用)</string> <string name="replace_state_change">替换(启用/禁用)</string>
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string>
</resources> </resources>

Loading…
Cancel
Save