tip 添加时间及电量

pull/517/head
gedoor 4 years ago
parent 82ca16cb38
commit 0fa79f9b77
  1. 1
      app/src/main/java/io/legado/app/help/ReadTipConfig.kt
  2. 96
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  3. 1
      app/src/main/res/values-zh-rHK/arrays.xml
  4. 1
      app/src/main/res/values-zh-rTW/arrays.xml
  5. 1
      app/src/main/res/values-zh/arrays.xml
  6. 1
      app/src/main/res/values/arrays.xml

@ -21,6 +21,7 @@ object ReadTipConfig {
const val totalProgress = 5 const val totalProgress = 5
const val pageAndTotal = 6 const val pageAndTotal = 6
const val bookName = 7 const val bookName = 7
const val timeBattery = 8
val tipHeaderLeftStr: String get() = tips.getOrElse(tipHeaderLeft) { tips[none] } val tipHeaderLeftStr: String get() = tips.getOrElse(tipHeaderLeft) { tips[none] }
val tipHeaderMiddleStr: String get() = tips.getOrElse(tipHeaderMiddle) { tips[none] } val tipHeaderMiddleStr: String get() = tips.getOrElse(tipHeaderMiddle) { tips[none] }

@ -33,6 +33,7 @@ class ContentView(context: Context) : FrameLayout(context) {
private var tvTotalProgress: BatteryView? = null private var tvTotalProgress: BatteryView? = null
private var tvPageAndTotal: BatteryView? = null private var tvPageAndTotal: BatteryView? = null
private var tvBookName: BatteryView? = null private var tvBookName: BatteryView? = null
private var tvTimeBattery: BatteryView? = null
val headerHeight: Int val headerHeight: Int
get() { get() {
@ -123,97 +124,60 @@ class ContentView(context: Context) : FrameLayout(context) {
else -> false else -> false
} }
} }
tvTitle = when (ReadTipConfig.chapterTitle) { tvTitle = getTipView(ReadTipConfig.chapterTitle)
ReadTipConfig.tipHeaderLeft -> tv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> tv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
}
tvTitle?.apply { tvTitle?.apply {
isBattery = false isBattery = false
textSize = 12f textSize = 12f
} }
tvTime = when (ReadTipConfig.time) { tvTime = getTipView(ReadTipConfig.time)
ReadTipConfig.tipHeaderLeft -> bv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> bv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
}
tvTime?.apply { tvTime?.apply {
isBattery = false isBattery = false
textSize = 12f textSize = 12f
} }
tvBattery = when (ReadTipConfig.battery) { tvBattery = getTipView(ReadTipConfig.battery)
ReadTipConfig.tipHeaderLeft -> bv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> bv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
}
tvBattery?.apply { tvBattery?.apply {
isBattery = true isBattery = true
textSize = 10f textSize = 10f
} }
tvPage = when (ReadTipConfig.page) { tvPage = getTipView(ReadTipConfig.page)
ReadTipConfig.tipHeaderLeft -> bv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> bv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
}
tvPage?.apply { tvPage?.apply {
isBattery = false isBattery = false
textSize = 12f textSize = 12f
} }
tvTotalProgress = when (ReadTipConfig.totalProgress) { tvTotalProgress = getTipView(ReadTipConfig.totalProgress)
ReadTipConfig.tipHeaderLeft -> bv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> bv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
}
tvTotalProgress?.apply { tvTotalProgress?.apply {
isBattery = false isBattery = false
textSize = 12f textSize = 12f
} }
tvPageAndTotal = when (ReadTipConfig.pageAndTotal) { tvPageAndTotal = getTipView(ReadTipConfig.pageAndTotal)
ReadTipConfig.tipHeaderLeft -> bv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> bv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
}
tvPageAndTotal?.apply { tvPageAndTotal?.apply {
isBattery = false isBattery = false
textSize = 12f textSize = 12f
} }
tvBookName = when (ReadTipConfig.bookName) { tvBookName = getTipView(ReadTipConfig.bookName)
ReadTipConfig.tipHeaderLeft -> bv_header_left tvBookName?.apply {
isBattery = false
textSize = 12f
}
tvTimeBattery = getTipView(ReadTipConfig.timeBattery)
tvTimeBattery?.apply {
isBattery = false
textSize = 12f
}
}
private fun getTipView(tip: Int): BatteryView? {
return when (tip) {
ReadTipConfig.tipHeaderLeft ->
if (tip == ReadTipConfig.chapterTitle) tv_header_left else bv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> bv_footer_left ReadTipConfig.tipFooterLeft ->
if (tip == ReadTipConfig.chapterTitle) tv_footer_left else bv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null else -> null
} }
tvBookName?.apply {
isBattery = false
textSize = 12f
}
} }
fun setBg(bg: Drawable?) { fun setBg(bg: Drawable?) {
@ -222,11 +186,21 @@ class ContentView(context: Context) : FrameLayout(context) {
fun upTime() { fun upTime() {
tvTime?.text = timeFormat.format(Date(System.currentTimeMillis())) tvTime?.text = timeFormat.format(Date(System.currentTimeMillis()))
upTimeBattery()
} }
fun upBattery(battery: Int) { fun upBattery(battery: Int) {
this.battery = battery this.battery = battery
tvBattery?.setBattery(battery) tvBattery?.setBattery(battery)
upTimeBattery()
}
@SuppressLint("SetTextI18n")
private fun upTimeBattery() {
tvTimeBattery?.let {
val time = timeFormat.format(Date(System.currentTimeMillis()))
it.text = "$time $battery%"
}
} }
fun setContent(pageData: PageData, resetPageOffset: Boolean = true) { fun setContent(pageData: PageData, resetPageOffset: Boolean = true) {

@ -44,6 +44,7 @@
<item>进度</item> <item>进度</item>
<item>页数及进度</item> <item>页数及进度</item>
<item>書名</item> <item>書名</item>
<item>时间及电量</item>
</string-array> </string-array>
<string-array name="text_font_weight"> <string-array name="text_font_weight">

@ -85,6 +85,7 @@
<item>進度</item> <item>進度</item>
<item>頁數及進度</item> <item>頁數及進度</item>
<item>書名</item> <item>書名</item>
<item>時間及電量</item>
</string-array> </string-array>
<string-array name="text_font_weight"> <string-array name="text_font_weight">

@ -85,6 +85,7 @@
<item>进度</item> <item>进度</item>
<item>页数及进度</item> <item>页数及进度</item>
<item>书名</item> <item>书名</item>
<item>时间及电量</item>
</string-array> </string-array>
<string-array name="text_font_weight"> <string-array name="text_font_weight">

@ -85,6 +85,7 @@
<item>Progress</item> <item>Progress</item>
<item>Pages and progress</item> <item>Pages and progress</item>
<item>Book name</item> <item>Book name</item>
<item>Time and Battery</item>
</string-array> </string-array>
<string-array name="text_font_weight"> <string-array name="text_font_weight">

Loading…
Cancel
Save