pull/32/head
kunfei 5 years ago
parent 148bdae34e
commit befb8578fd
  1. 11
      app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt
  2. 53
      app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt

@ -2,16 +2,25 @@ package io.legado.app.ui.widget.page
import android.text.Spannable import android.text.Spannable
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import io.legado.app.App
import io.legado.app.R
data class TextPage( data class TextPage(
val index: Int, val index: Int,
val text: CharSequence, val text: CharSequence = App.INSTANCE.getString(R.string.data_loading),
val title: String, val title: String,
var pageSize: Int = 0, var pageSize: Int = 0,
var chapterSize: Int = 0, var chapterSize: Int = 0,
var chapterIndex: Int = 0 var chapterIndex: Int = 0
) { ) {
fun removePageAloudSpan(): TextPage {
if (text is SpannableStringBuilder) {
text.removeSpan(ChapterProvider.readAloudSpan)
}
return this
}
fun upPageAloudSpan(pageStart: Int) { fun upPageAloudSpan(pageStart: Int) {
if (text is SpannableStringBuilder) { if (text is SpannableStringBuilder) {
text.removeSpan(ChapterProvider.readAloudSpan) text.removeSpan(ChapterProvider.readAloudSpan)

@ -1,10 +1,5 @@
package io.legado.app.ui.widget.page package io.legado.app.ui.widget.page
import android.text.SpannableStringBuilder
import io.legado.app.App
import io.legado.app.R
import io.legado.app.ui.widget.page.ChapterProvider.readAloudSpan
class TextPageFactory private constructor(dataSource: DataSource) : class TextPageFactory private constructor(dataSource: DataSource) :
PageFactory<TextPage>(dataSource) { PageFactory<TextPage>(dataSource) {
@ -66,55 +61,27 @@ class TextPageFactory private constructor(dataSource: DataSource) :
override fun currentPage(): TextPage? = dataSource.pageIndex().let { index -> override fun currentPage(): TextPage? = dataSource.pageIndex().let { index ->
return dataSource.getCurrentChapter()?.page(index) return dataSource.getCurrentChapter()?.page(index)
?: TextPage(index, App.INSTANCE.getString(R.string.data_loading), "index:$index") ?: TextPage(index = index, title = "index:$index")
} }
override fun nextPage(): TextPage? = dataSource.pageIndex().let { index -> override fun nextPage(): TextPage? = dataSource.pageIndex().let { index ->
dataSource.getCurrentChapter()?.let { dataSource.getCurrentChapter()?.let {
if (index < it.pageSize() - 1) { if (index < it.pageSize() - 1) {
return dataSource.getCurrentChapter()?.page(index + 1)?.apply { return dataSource.getCurrentChapter()?.page(index + 1)?.removePageAloudSpan()
if (text is SpannableStringBuilder) { ?: TextPage(index = index + 1, title = "index:${index + 1}")
text.removeSpan(readAloudSpan)
}
} ?: TextPage(
index + 1,
App.INSTANCE.getString(R.string.data_loading),
"index:${index + 1}"
)
} }
} }
return dataSource.getNextChapter()?.page(0)?.apply { return dataSource.getNextChapter()?.page(0)?.removePageAloudSpan()
if (text is SpannableStringBuilder) { ?: TextPage(index = index + 1, title = "index:${index + 1}")
text.removeSpan(readAloudSpan)
}
} ?: TextPage(
index + 1,
App.INSTANCE.getString(R.string.data_loading),
"index:${index + 1}"
)
} }
override fun previousPage(): TextPage? = dataSource.pageIndex().let { index -> override fun previousPage(): TextPage? = dataSource.pageIndex().let { index ->
if (index > 0) { if (index > 0) {
return dataSource.getCurrentChapter()?.page(index - 1)?.apply { return dataSource.getCurrentChapter()?.page(index - 1)?.removePageAloudSpan()
if (text is SpannableStringBuilder) { ?: TextPage(index = index - 1, title = "index:${index - 1}")
text.removeSpan(readAloudSpan) }
} return dataSource.getPreviousChapter()?.lastPage()?.removePageAloudSpan()
} ?: TextPage( ?: TextPage(index = index - 1, title = "index:${index - 1}")
index - 1,
App.INSTANCE.getString(R.string.data_loading),
"index:${index - 1}"
)
}
return dataSource.getPreviousChapter()?.lastPage()?.apply {
if (text is SpannableStringBuilder) {
text.removeSpan(readAloudSpan)
}
} ?: TextPage(
index - 1,
App.INSTANCE.getString(R.string.data_loading),
"index:${index - 1}"
)
} }

Loading…
Cancel
Save