正文按钮增加正则替换(长按配置,短按切换状态) #237
This commit is contained in:
@@ -1665,6 +1665,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
it.setUseReplaceRule(!it.getUseReplaceRule())
|
it.setUseReplaceRule(!it.getUseReplaceRule())
|
||||||
ReadBook.saveRead()
|
ReadBook.saveRead()
|
||||||
menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.getUseReplaceRule()
|
menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.getUseReplaceRule()
|
||||||
|
binding.readMenu.changeReplace(it.getUseReplaceRule())
|
||||||
viewModel.replaceRuleChanged()
|
viewModel.replaceRuleChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,10 @@ import io.legado.app.utils.openUrl
|
|||||||
import io.legado.app.utils.putPrefBoolean
|
import io.legado.app.utils.putPrefBoolean
|
||||||
import io.legado.app.utils.startActivity
|
import io.legado.app.utils.startActivity
|
||||||
import io.legado.app.utils.themeColor
|
import io.legado.app.utils.themeColor
|
||||||
|
import io.legado.app.utils.toastOnUi
|
||||||
import io.legado.app.utils.visible
|
import io.legado.app.utils.visible
|
||||||
import splitties.views.onClick
|
import splitties.views.onClick
|
||||||
|
import splitties.views.onLongClick
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阅读界面菜单
|
* 阅读界面菜单
|
||||||
@@ -107,7 +109,7 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
private val bgColor: Int
|
private val bgColor: Int
|
||||||
get() = when (AppConfig.readBarStyle) {
|
get() = when (AppConfig.readBarStyle) {
|
||||||
0 -> colorSurfaceContainer
|
0 -> colorSurfaceContainer
|
||||||
1 -> kotlin.runCatching {
|
1 -> runCatching {
|
||||||
ReadBookConfig.durConfig.curBgStr().toColorInt()
|
ReadBookConfig.durConfig.curBgStr().toColorInt()
|
||||||
}.getOrDefault(colorSurfaceContainer)
|
}.getOrDefault(colorSurfaceContainer)
|
||||||
else -> ReadBookConfig.durConfig.curMenuBg()
|
else -> ReadBookConfig.durConfig.curMenuBg()
|
||||||
@@ -117,7 +119,7 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
private val acColor: Int
|
private val acColor: Int
|
||||||
get() = when (AppConfig.readBarStyle) {
|
get() = when (AppConfig.readBarStyle) {
|
||||||
0 -> colorSecondary
|
0 -> colorSecondary
|
||||||
1 -> kotlin.runCatching {
|
1 -> runCatching {
|
||||||
ReadBookConfig.durConfig.curTextColor()
|
ReadBookConfig.durConfig.curTextColor()
|
||||||
}.getOrDefault(colorSecondary)
|
}.getOrDefault(colorSecondary)
|
||||||
else -> ReadBookConfig.durConfig.curMenuAc()
|
else -> ReadBookConfig.durConfig.curMenuAc()
|
||||||
@@ -127,11 +129,11 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
private val bgcColor: Int
|
private val bgcColor: Int
|
||||||
get() = when (AppConfig.readBarStyle) {
|
get() = when (AppConfig.readBarStyle) {
|
||||||
0 -> colorSecondaryContainer
|
0 -> colorSecondaryContainer
|
||||||
1 -> kotlin.runCatching {
|
1 -> runCatching {
|
||||||
val baseColor = ReadBookConfig.durConfig.curTextColor()
|
val baseColor = ReadBookConfig.durConfig.curTextColor()
|
||||||
ColorUtils.setAlphaComponent(baseColor, (255 * 0.2f).toInt())
|
ColorUtils.setAlphaComponent(baseColor, (255 * 0.1f).toInt())
|
||||||
}.getOrDefault(colorSecondaryContainer)
|
}.getOrDefault(colorSecondaryContainer)
|
||||||
else -> ColorUtils.setAlphaComponent(acColor, (255 * 0.2f).toInt())
|
else -> ColorUtils.setAlphaComponent(acColor, (255 * 0.1f).toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
private var onMenuOutEnd: (() -> Unit)? = null
|
private var onMenuOutEnd: (() -> Unit)? = null
|
||||||
@@ -317,6 +319,7 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
this.visible()
|
this.visible()
|
||||||
binding.titleBar.visible()
|
binding.titleBar.visible()
|
||||||
binding.bottomMenu.visible()
|
binding.bottomMenu.visible()
|
||||||
|
changeReplace(ReadBook.book?.getUseReplaceRule() ?: false)
|
||||||
if (anim) {
|
if (anim) {
|
||||||
binding.titleBar.startAnimation(menuTopIn)
|
binding.titleBar.startAnimation(menuTopIn)
|
||||||
binding.bottomMenu.startAnimation(menuBottomIn)
|
binding.bottomMenu.startAnimation(menuBottomIn)
|
||||||
@@ -552,8 +555,29 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
strokeWidth = 0
|
strokeWidth = 0
|
||||||
iconGravity = MaterialButton.ICON_GRAVITY_TEXT_START
|
iconGravity = MaterialButton.ICON_GRAVITY_TEXT_START
|
||||||
iconTint = ColorStateList.valueOf(acColor)
|
iconTint = ColorStateList.valueOf(acColor)
|
||||||
|
val bgColorState = ColorStateList(
|
||||||
|
arrayOf(
|
||||||
|
intArrayOf(android.R.attr.state_checked),
|
||||||
|
intArrayOf(-android.R.attr.state_checked)
|
||||||
|
),
|
||||||
|
intArrayOf(
|
||||||
|
bgcColor,
|
||||||
|
bgColor
|
||||||
|
)
|
||||||
|
)
|
||||||
|
backgroundTintList = bgColorState
|
||||||
maxLines = 1
|
maxLines = 1
|
||||||
setOnClickListener { btn.onClick() }
|
if (btn.onCheck != null) {
|
||||||
|
isCheckable = true
|
||||||
|
isChecked = btn.state
|
||||||
|
setOnClickListener {
|
||||||
|
isChecked = !isChecked
|
||||||
|
btn.state = isChecked
|
||||||
|
btn.onCheck.invoke()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setOnClickListener { btn.onClick() }
|
||||||
|
}
|
||||||
btn.onLongClick?.let { longAction ->
|
btn.onLongClick?.let { longAction ->
|
||||||
setOnLongClickListener {
|
setOnLongClickListener {
|
||||||
longAction()
|
longAction()
|
||||||
@@ -634,10 +658,22 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
iconRes = R.drawable.ic_next,
|
iconRes = R.drawable.ic_next,
|
||||||
description = context.getString(R.string.next_chapter),
|
description = context.getString(R.string.next_chapter),
|
||||||
onClick = { ReadBook.moveToNextChapter(true) }
|
onClick = { ReadBook.moveToNextChapter(true) }
|
||||||
|
),
|
||||||
|
ToolButton(
|
||||||
|
id = "replace",
|
||||||
|
iconRes = R.drawable.ic_find_replace,
|
||||||
|
description = context.getString(R.string.replace_purify),
|
||||||
|
onLongClick = { runMenuOut { callBack.openReplaceRule() } },
|
||||||
|
onCheck = { runMenuOut { callBack.changeReplaceRuleState() } },
|
||||||
|
onClick = { }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun changeReplace(boolean: Boolean) {
|
||||||
|
buttonMap["replace"]?.isChecked = boolean
|
||||||
|
}
|
||||||
|
|
||||||
private fun getUserButtons(): List<ToolButton> {
|
private fun getUserButtons(): List<ToolButton> {
|
||||||
val prefs by lazy {
|
val prefs by lazy {
|
||||||
context.getSharedPreferences("tool_button_config", Context.MODE_PRIVATE)
|
context.getSharedPreferences("tool_button_config", Context.MODE_PRIVATE)
|
||||||
@@ -808,6 +844,7 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
fun skipToChapter(index: Int)
|
fun skipToChapter(index: Int)
|
||||||
fun onMenuShow()
|
fun onMenuShow()
|
||||||
fun onMenuHide()
|
fun onMenuHide()
|
||||||
|
fun changeReplaceRuleState()
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ToolButton(
|
data class ToolButton(
|
||||||
@@ -816,6 +853,7 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
val description: String, // contentDescription / tooltipText
|
val description: String, // contentDescription / tooltipText
|
||||||
val onClick: () -> Unit, // 点击事件
|
val onClick: () -> Unit, // 点击事件
|
||||||
val onLongClick: (() -> Unit)? = null, // 可选长按
|
val onLongClick: (() -> Unit)? = null, // 可选长按
|
||||||
|
val onCheck: (() -> Unit)? = null,// 可选
|
||||||
var state: Boolean = false // 动态
|
var state: Boolean = false // 动态
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ class ToolButtonConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_too
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getAllButtonIds(): List<String> {
|
private fun getAllButtonIds(): List<String> {
|
||||||
return listOf("search", "auto_page", "catalog", "read_aloud", "setting", "addBookmark", "theme", "prev_chapter", "next_chapter")
|
return listOf("search", "auto_page", "catalog", "read_aloud", "setting", "addBookmark", "theme", "prev_chapter", "next_chapter", "replace")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getButtonInfo(id: String): Pair<Int, String> {
|
private fun getButtonInfo(id: String): Pair<Int, String> {
|
||||||
@@ -128,6 +128,7 @@ class ToolButtonConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_too
|
|||||||
"theme" -> R.drawable.ic_daytime to getString(R.string.day_night_switch)
|
"theme" -> R.drawable.ic_daytime to getString(R.string.day_night_switch)
|
||||||
"prev_chapter" -> R.drawable.ic_previous to getString(R.string.previous_chapter)
|
"prev_chapter" -> R.drawable.ic_previous to getString(R.string.previous_chapter)
|
||||||
"next_chapter" -> R.drawable.ic_next to getString(R.string.next_chapter)
|
"next_chapter" -> R.drawable.ic_next to getString(R.string.next_chapter)
|
||||||
|
"replace" -> R.drawable.ic_find_replace to getString(R.string.replace_purify)
|
||||||
else -> R.drawable.ic_help to id
|
else -> R.drawable.ic_help to id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
VERSION_MAJOR=3
|
VERSION_MAJOR=3
|
||||||
VERSION_MINOR=26
|
VERSION_MINOR=26
|
||||||
VERSION_PATCH=2
|
VERSION_PATCH=2
|
||||||
VERSION_SUFFIX=-beta.9
|
VERSION_SUFFIX=
|
||||||
Reference in New Issue
Block a user