优化
This commit is contained in:
@@ -46,7 +46,6 @@ import io.legado.app.utils.setLightStatusBar
|
|||||||
import io.legado.app.utils.setNavigationBarColorAuto
|
import io.legado.app.utils.setNavigationBarColorAuto
|
||||||
import io.legado.app.utils.showDialogFragment
|
import io.legado.app.utils.showDialogFragment
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import io.legado.app.utils.visible
|
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@@ -58,6 +57,8 @@ abstract class BaseReadBookActivity :
|
|||||||
|
|
||||||
override val binding by viewBinding(ActivityBookReadBinding::inflate)
|
override val binding by viewBinding(ActivityBookReadBinding::inflate)
|
||||||
override val viewModel by viewModels<ReadBookViewModel>()
|
override val viewModel by viewModels<ReadBookViewModel>()
|
||||||
|
protected val menuLayoutIsVisible
|
||||||
|
get() = bottomDialog > 0 || binding.readMenu.isVisible || binding.searchMenu.bottomMenuVisible
|
||||||
|
|
||||||
var bottomDialog = 0
|
var bottomDialog = 0
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -229,37 +230,7 @@ abstract class BaseReadBookActivity :
|
|||||||
|
|
||||||
@SuppressLint("RtlHardcoded")
|
@SuppressLint("RtlHardcoded")
|
||||||
private fun upNavigationBar() {
|
private fun upNavigationBar() {
|
||||||
binding.navigationBar.run {
|
binding.navigationBar.gone(!menuLayoutIsVisible)
|
||||||
if (bottomDialog > 0 || binding.readMenu.isVisible || binding.searchMenu.bottomMenuVisible) {
|
|
||||||
// val navigationBarHeight =
|
|
||||||
// if (ReadBookConfig.hideNavigationBar) navigationBarHeight else 0
|
|
||||||
// when (navigationBarGravity) {
|
|
||||||
// Gravity.BOTTOM -> layoutParams =
|
|
||||||
// (layoutParams as FrameLayout.LayoutParams).apply {
|
|
||||||
// height = navigationBarHeight
|
|
||||||
// width = MATCH_PARENT
|
|
||||||
// gravity = Gravity.BOTTOM
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Gravity.LEFT -> layoutParams =
|
|
||||||
// (layoutParams as FrameLayout.LayoutParams).apply {
|
|
||||||
// height = MATCH_PARENT
|
|
||||||
// width = navigationBarHeight
|
|
||||||
// gravity = Gravity.LEFT
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Gravity.RIGHT -> layoutParams =
|
|
||||||
// (layoutParams as FrameLayout.LayoutParams).apply {
|
|
||||||
// height = MATCH_PARENT
|
|
||||||
// width = navigationBarHeight
|
|
||||||
// gravity = Gravity.RIGHT
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
visible()
|
|
||||||
} else {
|
|
||||||
gone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -317,57 +288,59 @@ abstract class BaseReadBookActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun showSimulatedReading() {
|
fun showSimulatedReading() {
|
||||||
|
val book = ReadBook.book ?: return
|
||||||
val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
||||||
ReadBook.book?.let { book ->
|
val alertBinding = DialogSimulatedReadingBinding.inflate(layoutInflater).apply {
|
||||||
alert(titleResource = R.string.simulated_reading) {
|
srEnabled.isChecked = book.getReadSimulating()
|
||||||
val alertBinding = DialogSimulatedReadingBinding.inflate(layoutInflater).apply {
|
editStart.setText(book.getStartChapter().toString())
|
||||||
srEnabled.isChecked = book.getReadSimulating()
|
editNum.setText(book.getDailyChapters().toString())
|
||||||
editStart.setText(book.getStartChapter().toString())
|
startDate.setText(book.getStartDate()?.format(dateFormatter))
|
||||||
editNum.setText(book.getDailyChapters().toString())
|
startDate.isFocusable = false // 设置为false,不允许获得焦点
|
||||||
startDate.setText(book.getStartDate()?.format(dateFormatter))
|
startDate.isCursorVisible = false // 不显示光标
|
||||||
startDate.isFocusable = false // 设置为false,不允许获得焦点
|
startDate.setOnClickListener {
|
||||||
startDate.isCursorVisible = false // 不显示光标
|
// 获取当前日期
|
||||||
startDate.setOnClickListener {
|
val localStartDate = LocalDate.parse(startDate.text)
|
||||||
// 获取当前日期
|
// 创建 DatePickerDialog
|
||||||
val localStartDate = LocalDate.parse(startDate.text)
|
val datePickerDialog = DatePickerDialog(
|
||||||
// 创建 DatePickerDialog
|
root.context,
|
||||||
val datePickerDialog = DatePickerDialog(
|
{ _, yy, mm, dayOfMonth ->
|
||||||
root.context,
|
// 使用Java 8的日期和时间API来格式化日期
|
||||||
{ _, yy, mm, dayOfMonth ->
|
val date = LocalDate.of(yy, mm + 1, dayOfMonth) // Java 8的LocalDate,月份从1开始
|
||||||
// 使用Java 8的日期和时间API来格式化日期
|
val formattedDate = date.format(dateFormatter)
|
||||||
val date = LocalDate.of(yy, mm + 1, dayOfMonth) // Java 8的LocalDate,月份从1开始
|
startDate.setText(formattedDate)
|
||||||
val formattedDate = date.format(dateFormatter)
|
}, localStartDate.year,
|
||||||
startDate.setText(formattedDate)
|
localStartDate.monthValue - 1,
|
||||||
}, localStartDate.year, localStartDate.monthValue - 1, localStartDate.dayOfMonth
|
localStartDate.dayOfMonth
|
||||||
)
|
)
|
||||||
datePickerDialog.show()
|
datePickerDialog.show()
|
||||||
}
|
|
||||||
}
|
|
||||||
customView { alertBinding.root }
|
|
||||||
yesButton {
|
|
||||||
alertBinding.run {
|
|
||||||
val start = editStart.text!!.toString().let {
|
|
||||||
if (it.isEmpty()) 0 else it.toInt()
|
|
||||||
}
|
|
||||||
val num = editNum.text!!.toString().let {
|
|
||||||
if (it.isEmpty()) book.totalChapterNum else it.toInt()
|
|
||||||
}
|
|
||||||
val enabled = srEnabled.isChecked
|
|
||||||
val date = startDate.text!!.toString().let {
|
|
||||||
if (it.isEmpty()) LocalDate.now() else LocalDate.parse(it, dateFormatter)
|
|
||||||
}
|
|
||||||
book.setStartDate(date)
|
|
||||||
book.setDailyChapters(num)
|
|
||||||
book.setStartChapter(start)
|
|
||||||
book.setReadSimulating(enabled)
|
|
||||||
book.save()
|
|
||||||
ReadBook.clearTextChapter()
|
|
||||||
viewModel.initData(intent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
noButton()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
alert(titleResource = R.string.simulated_reading) {
|
||||||
|
customView { alertBinding.root }
|
||||||
|
yesButton {
|
||||||
|
alertBinding.run {
|
||||||
|
val start = editStart.text!!.toString().let {
|
||||||
|
if (it.isEmpty()) 0 else it.toInt()
|
||||||
|
}
|
||||||
|
val num = editNum.text!!.toString().let {
|
||||||
|
if (it.isEmpty()) book.totalChapterNum else it.toInt()
|
||||||
|
}
|
||||||
|
val enabled = srEnabled.isChecked
|
||||||
|
val date = startDate.text!!.toString().let {
|
||||||
|
if (it.isEmpty()) LocalDate.now()
|
||||||
|
else LocalDate.parse(it, dateFormatter)
|
||||||
|
}
|
||||||
|
book.setStartDate(date)
|
||||||
|
book.setDailyChapters(num)
|
||||||
|
book.setStartChapter(start)
|
||||||
|
book.setReadSimulating(enabled)
|
||||||
|
book.save()
|
||||||
|
ReadBook.clearTextChapter()
|
||||||
|
viewModel.initData(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
noButton()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showCharsetConfig() {
|
fun showCharsetConfig() {
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
override val pageFactory get() = binding.readView.pageFactory
|
override val pageFactory get() = binding.readView.pageFactory
|
||||||
override val pageDelegate get() = binding.readView.pageDelegate
|
override val pageDelegate get() = binding.readView.pageDelegate
|
||||||
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
||||||
private val menuLayoutIsVisible get() = bottomDialog > 0 || binding.readMenu.isVisible || binding.searchMenu.bottomMenuVisible
|
|
||||||
private val nextPageDebounce by lazy { Debounce { keyPage(PageDirection.NEXT) } }
|
private val nextPageDebounce by lazy { Debounce { keyPage(PageDirection.NEXT) } }
|
||||||
private val prevPageDebounce by lazy { Debounce { keyPage(PageDirection.PREV) } }
|
private val prevPageDebounce by lazy { Debounce { keyPage(PageDirection.PREV) } }
|
||||||
private var bookChanged = false
|
private var bookChanged = false
|
||||||
|
|||||||
@@ -126,21 +126,7 @@ class ReadMenu @JvmOverloads constructor(
|
|||||||
|
|
||||||
@SuppressLint("RtlHardcoded")
|
@SuppressLint("RtlHardcoded")
|
||||||
override fun onAnimationEnd(animation: Animation) {
|
override fun onAnimationEnd(animation: Animation) {
|
||||||
// val navigationBarHeight =
|
binding.vwMenuBg.setOnClickListener { runMenuOut() }
|
||||||
// if (ReadBookConfig.hideNavigationBar) {
|
|
||||||
// activity?.navigationBarHeight ?: 0
|
|
||||||
// } else {
|
|
||||||
// 0
|
|
||||||
// }
|
|
||||||
binding.run {
|
|
||||||
vwMenuBg.setOnClickListener { runMenuOut() }
|
|
||||||
// root.padding = 0
|
|
||||||
// when (activity?.navigationBarGravity) {
|
|
||||||
// Gravity.BOTTOM -> root.bottomPadding = navigationBarHeight
|
|
||||||
// Gravity.LEFT -> root.leftPadding = navigationBarHeight
|
|
||||||
// Gravity.RIGHT -> root.rightPadding = navigationBarHeight
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
callBack.upSystemUiVisibility()
|
callBack.upSystemUiVisibility()
|
||||||
if (!LocalConfig.readMenuHelpVersionIsLast) {
|
if (!LocalConfig.readMenuHelpVersionIsLast) {
|
||||||
callBack.showHelp()
|
callBack.showHelp()
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ import android.content.Context
|
|||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.animation.Animation
|
import android.view.animation.Animation
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.databinding.ViewSearchMenuBinding
|
import io.legado.app.databinding.ViewSearchMenuBinding
|
||||||
import io.legado.app.help.config.ReadBookConfig
|
|
||||||
import io.legado.app.lib.theme.Selector
|
import io.legado.app.lib.theme.Selector
|
||||||
import io.legado.app.lib.theme.bottomBackground
|
import io.legado.app.lib.theme.bottomBackground
|
||||||
import io.legado.app.lib.theme.getPrimaryTextColor
|
import io.legado.app.lib.theme.getPrimaryTextColor
|
||||||
@@ -20,15 +18,10 @@ import io.legado.app.model.ReadBook
|
|||||||
import io.legado.app.ui.book.searchContent.SearchResult
|
import io.legado.app.ui.book.searchContent.SearchResult
|
||||||
import io.legado.app.utils.ColorUtils
|
import io.legado.app.utils.ColorUtils
|
||||||
import io.legado.app.utils.activity
|
import io.legado.app.utils.activity
|
||||||
|
import io.legado.app.utils.applyNavigationBarPadding
|
||||||
import io.legado.app.utils.invisible
|
import io.legado.app.utils.invisible
|
||||||
import io.legado.app.utils.loadAnimation
|
import io.legado.app.utils.loadAnimation
|
||||||
import io.legado.app.utils.navigationBarGravity
|
|
||||||
import io.legado.app.utils.navigationBarHeight
|
|
||||||
import io.legado.app.utils.visible
|
import io.legado.app.utils.visible
|
||||||
import splitties.views.bottomPadding
|
|
||||||
import splitties.views.leftPadding
|
|
||||||
import splitties.views.padding
|
|
||||||
import splitties.views.rightPadding
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索界面菜单
|
* 搜索界面菜单
|
||||||
@@ -91,6 +84,7 @@ class SearchMenu @JvmOverloads constructor(
|
|||||||
ivSearchContentUp.setColorFilter(textColor, PorterDuff.Mode.SRC_IN)
|
ivSearchContentUp.setColorFilter(textColor, PorterDuff.Mode.SRC_IN)
|
||||||
ivSearchContentDown.setColorFilter(textColor, PorterDuff.Mode.SRC_IN)
|
ivSearchContentDown.setColorFilter(textColor, PorterDuff.Mode.SRC_IN)
|
||||||
tvCurrentSearchInfo.setTextColor(textColor)
|
tvCurrentSearchInfo.setTextColor(textColor)
|
||||||
|
applyNavigationBarPadding()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -196,20 +190,7 @@ class SearchMenu @JvmOverloads constructor(
|
|||||||
|
|
||||||
@SuppressLint("RtlHardcoded")
|
@SuppressLint("RtlHardcoded")
|
||||||
override fun onAnimationEnd(animation: Animation) {
|
override fun onAnimationEnd(animation: Animation) {
|
||||||
val navigationBarHeight = if (ReadBookConfig.hideNavigationBar) {
|
binding.vwMenuBg.setOnClickListener { runMenuOut() }
|
||||||
activity?.navigationBarHeight ?: 0
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
binding.run {
|
|
||||||
vwMenuBg.setOnClickListener { runMenuOut() }
|
|
||||||
root.padding = 0
|
|
||||||
when (activity?.navigationBarGravity) {
|
|
||||||
Gravity.BOTTOM -> root.bottomPadding = navigationBarHeight
|
|
||||||
Gravity.LEFT -> root.leftPadding = navigationBarHeight
|
|
||||||
Gravity.RIGHT -> root.rightPadding = navigationBarHeight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
callBack.upSystemUiVisibility()
|
callBack.upSystemUiVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user