pull/34/head
kunfei 5 years ago
parent ef5fddf0ef
commit 8e426101c2
  1. 18
      app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt
  2. 6
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  3. 13
      app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt

@ -26,8 +26,9 @@ import java.util.*
class ContentView : FrameLayout {
private var isScroll: Boolean = false
var callBack: CallBack? = null
private var isScroll: Boolean = false
private var pageSize: Int = 0
private val bgImage: AppCompatImageView = AppCompatImageView(context)
.apply {
scaleType = ImageView.ScaleType.CENTER_CROP
@ -112,11 +113,18 @@ class ContentView : FrameLayout {
tv_top_right.text = context.getString(R.string.battery_show, battery)
}
fun setContent(textPage: TextPage?) {
content_text_view.text = textPage?.text
tv_bottom_left.text = textPage?.title
pageSize = textPage?.pageSize ?: 0
setPageIndex(textPage?.index)
}
@SuppressLint("SetTextI18n")
fun setContent(page: TextPage?) {
content_text_view.text = page?.text
tv_bottom_left.text = page?.title
tv_bottom_right.text = "${page?.index?.plus(1)}/${page?.pageSize}"
fun setPageIndex(pageIndex: Int?) {
pageIndex?.let {
tv_bottom_right.text = "${pageIndex.plus(1)}/${pageSize}"
}
}
fun isTextSelected(): Boolean {

@ -210,7 +210,11 @@ class PageView(context: Context, attrs: AttributeSet) :
}
override fun scrollToLine(line: Int) {
callback?.textChapter()?.let {
val pageIndex = it.getPageIndex(line)
curPage?.setPageIndex(pageIndex)
callback?.setPageIndex(pageIndex)
}
}
interface CallBack {

@ -31,7 +31,7 @@ data class TextChapter(
pages.forEach {
spannableStringBuilder.append(it.text)
}
return TextPage(0, spannableStringBuilder, title, position, chaptersSize)
return TextPage(0, spannableStringBuilder, title, position, pages.size)
}
return null
}
@ -76,5 +76,16 @@ data class TextChapter(
}
return 0
}
fun getPageIndex(line: Int): Int {
var lines = 0
for (pageIndex in pageLines.indices) {
lines += pageLines[pageIndex] + 1
if (line < lines) {
return pageIndex
}
}
return 0
}
}

Loading…
Cancel
Save