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 tipFooterRight: Int = ReadTipConfig.pageAndTotal,
var tipColor: Int = 0,
var tipDividerColor: Int = -1,
var headerMode: Int = 0,
var footerMode: Int = 0
) {

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

@ -62,7 +62,16 @@ object BackupConfig {
PreferKey.shareLayout,
PreferKey.hideStatusBar,
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 readRecord = ReadRecord()
var readStartTime: Long = System.currentTimeMillis()
/* 跳转历史记录 */
var bookProgressHistory: List<BookProgress>? = null
/* 跳转进度前进度记录 */
var lastBookPress: BookProgress? = null
/* web端阅读进度记录 */
var webBookProgress: BookProgress? = null
@ -54,6 +57,7 @@ object ReadBook : CoroutineScope by MainScope() {
if (lastBookPress != null) return //避免进度条连续跳转不能覆盖最初的进度记录
lastBookPress = book?.let { BookProgress(it) }
}
//恢复跳转前进度
fun restoreLastBookProcess() {
lastBookPress?.let {
@ -482,14 +486,10 @@ object ReadBook : CoroutineScope by MainScope() {
}
}
fun exit() {
callBack?.exit()
}
interface CallBack {
fun upMenuView()
fun loadChapterList(book: Book)
fun loadChapterList(book: Book, callback: (() -> Unit)? = null)
fun upContent(
relativePosition: Int = 0,
@ -503,8 +503,6 @@ object ReadBook : CoroutineScope by MainScope() {
fun upPageAnim()
fun exit()
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.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_DIVIDER_COLOR
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.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))
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() {
bookChanged = true
}
@ -1154,6 +1145,11 @@ class ReadBookActivity : BaseReadBookActivity(),
postEvent(EventBus.TIP_COLOR, "")
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) {
execute {
LocalBook.getChapterList(book).let {
@ -157,10 +157,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
}
}
}.onFinally {
callback?.invoke()
}
} else {
ReadBook.bookSource?.let {
viewModelScope.launch(IO) {
val oldBook = book.copy()
WebBook.getChapterList(viewModelScope, it, book, true)
.onSuccess(IO) { cList ->
@ -177,7 +178,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.loadContent(resetPageOffset = true)
}.onError {
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 {
const val TIP_COLOR = 7897
const val TIP_DIVIDER_COLOR = 7898
}
private val binding by viewBinding(DialogTipConfigBinding::bind)
@ -33,6 +34,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
initEvent()
observeEvent<String>(EventBus.TIP_COLOR) {
upTvTipColor()
upTvTipDividerColor()
}
}
@ -64,6 +66,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
}
}
upTvTipColor()
upTvTipDividerColor()
}
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 {
rgTitleMode.setOnCheckedChangeListener { _, 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 {

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

@ -8,7 +8,6 @@ import android.view.Menu
import android.view.MenuItem
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
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.lib.theme.accentColor
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.book.toc.rule.TxtTocRuleDialog
import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.applyTint
import io.legado.app.utils.gone
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 viewModel by viewModels<TocViewModel>()
@ -38,6 +40,7 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
private lateinit var tabLayout: TabLayout
private var menu: Menu? = null
private var searchView: SearchView? = null
private val waitDialog by lazy { WaitDialog(this) }
override fun onActivityCreated(savedInstanceState: Bundle?) {
tabLayout = binding.titleBar.findViewById(R.id.tab_layout)
@ -122,6 +125,17 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
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")
private inner class TabFragmentPageAdapter :
FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {

@ -322,6 +322,32 @@
</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>
</androidx.core.widget.NestedScrollView>

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

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

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

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

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

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

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

Loading…
Cancel
Save