|
|
@@ -46,7 +46,6 @@ import io.legado.app.utils.setLightStatusBar
|
|
|
import io.legado.app.utils.setNavigationBarColorAuto
|
|
|
import io.legado.app.utils.showDialogFragment
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|
|
-import io.legado.app.utils.visible
|
|
|
import java.time.LocalDate
|
|
|
import java.time.format.DateTimeFormatter
|
|
|
|
|
|
@@ -58,6 +57,8 @@ abstract class BaseReadBookActivity :
|
|
|
|
|
|
override val binding by viewBinding(ActivityBookReadBinding::inflate)
|
|
|
override val viewModel by viewModels<ReadBookViewModel>()
|
|
|
+ protected val menuLayoutIsVisible
|
|
|
+ get() = bottomDialog > 0 || binding.readMenu.isVisible || binding.searchMenu.bottomMenuVisible
|
|
|
|
|
|
var bottomDialog = 0
|
|
|
set(value) {
|
|
|
@@ -229,37 +230,7 @@ abstract class BaseReadBookActivity :
|
|
|
|
|
|
@SuppressLint("RtlHardcoded")
|
|
|
private fun upNavigationBar() {
|
|
|
- binding.navigationBar.run {
|
|
|
- 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()
|
|
|
- }
|
|
|
- }
|
|
|
+ binding.navigationBar.gone(!menuLayoutIsVisible)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -317,56 +288,58 @@ abstract class BaseReadBookActivity :
|
|
|
}
|
|
|
|
|
|
fun showSimulatedReading() {
|
|
|
+ val book = ReadBook.book ?: return
|
|
|
val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
- ReadBook.book?.let { book ->
|
|
|
- alert(titleResource = R.string.simulated_reading) {
|
|
|
- val alertBinding = DialogSimulatedReadingBinding.inflate(layoutInflater).apply {
|
|
|
- srEnabled.isChecked = book.getReadSimulating()
|
|
|
- editStart.setText(book.getStartChapter().toString())
|
|
|
- editNum.setText(book.getDailyChapters().toString())
|
|
|
- startDate.setText(book.getStartDate()?.format(dateFormatter))
|
|
|
- startDate.isFocusable = false // 设置为false,不允许获得焦点
|
|
|
- startDate.isCursorVisible = false // 不显示光标
|
|
|
- startDate.setOnClickListener {
|
|
|
- // 获取当前日期
|
|
|
- val localStartDate = LocalDate.parse(startDate.text)
|
|
|
- // 创建 DatePickerDialog
|
|
|
- val datePickerDialog = DatePickerDialog(
|
|
|
- root.context,
|
|
|
- { _, yy, mm, dayOfMonth ->
|
|
|
- // 使用Java 8的日期和时间API来格式化日期
|
|
|
- val date = LocalDate.of(yy, mm + 1, dayOfMonth) // Java 8的LocalDate,月份从1开始
|
|
|
- val formattedDate = date.format(dateFormatter)
|
|
|
- startDate.setText(formattedDate)
|
|
|
- }, localStartDate.year, localStartDate.monthValue - 1, localStartDate.dayOfMonth
|
|
|
- )
|
|
|
- datePickerDialog.show()
|
|
|
+ val alertBinding = DialogSimulatedReadingBinding.inflate(layoutInflater).apply {
|
|
|
+ srEnabled.isChecked = book.getReadSimulating()
|
|
|
+ editStart.setText(book.getStartChapter().toString())
|
|
|
+ editNum.setText(book.getDailyChapters().toString())
|
|
|
+ startDate.setText(book.getStartDate()?.format(dateFormatter))
|
|
|
+ startDate.isFocusable = false // 设置为false,不允许获得焦点
|
|
|
+ startDate.isCursorVisible = false // 不显示光标
|
|
|
+ startDate.setOnClickListener {
|
|
|
+ // 获取当前日期
|
|
|
+ val localStartDate = LocalDate.parse(startDate.text)
|
|
|
+ // 创建 DatePickerDialog
|
|
|
+ val datePickerDialog = DatePickerDialog(
|
|
|
+ root.context,
|
|
|
+ { _, yy, mm, dayOfMonth ->
|
|
|
+ // 使用Java 8的日期和时间API来格式化日期
|
|
|
+ val date = LocalDate.of(yy, mm + 1, dayOfMonth) // Java 8的LocalDate,月份从1开始
|
|
|
+ val formattedDate = date.format(dateFormatter)
|
|
|
+ startDate.setText(formattedDate)
|
|
|
+ }, localStartDate.year,
|
|
|
+ localStartDate.monthValue - 1,
|
|
|
+ localStartDate.dayOfMonth
|
|
|
+ )
|
|
|
+ datePickerDialog.show()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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()
|
|
|
}
|
|
|
- }
|
|
|
- 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)
|
|
|
+ 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()
|
|
|
}
|
|
|
+ noButton()
|
|
|
}
|
|
|
}
|
|
|
|