From befb8578fd81f0ead4c630726060485232fa444f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 27 Aug 2019 14:15:57 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/widget/page/TextPage.kt | 11 +++- .../app/ui/widget/page/TextPageFactory.kt | 51 ++++--------------- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt index 9871a7c7b..44f47d098 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt @@ -2,16 +2,25 @@ package io.legado.app.ui.widget.page import android.text.Spannable import android.text.SpannableStringBuilder +import io.legado.app.App +import io.legado.app.R data class TextPage( val index: Int, - val text: CharSequence, + val text: CharSequence = App.INSTANCE.getString(R.string.data_loading), val title: String, var pageSize: Int = 0, var chapterSize: Int = 0, var chapterIndex: Int = 0 ) { + fun removePageAloudSpan(): TextPage { + if (text is SpannableStringBuilder) { + text.removeSpan(ChapterProvider.readAloudSpan) + } + return this + } + fun upPageAloudSpan(pageStart: Int) { if (text is SpannableStringBuilder) { text.removeSpan(ChapterProvider.readAloudSpan) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt index d5d3414e1..96d646c3d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt @@ -1,10 +1,5 @@ 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) : PageFactory(dataSource) { @@ -66,55 +61,27 @@ class TextPageFactory private constructor(dataSource: DataSource) : override fun currentPage(): TextPage? = dataSource.pageIndex().let { 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 -> dataSource.getCurrentChapter()?.let { if (index < it.pageSize() - 1) { - return dataSource.getCurrentChapter()?.page(index + 1)?.apply { - if (text is SpannableStringBuilder) { - text.removeSpan(readAloudSpan) - } - } ?: TextPage( - index + 1, - App.INSTANCE.getString(R.string.data_loading), - "index:${index + 1}" - ) + return dataSource.getCurrentChapter()?.page(index + 1)?.removePageAloudSpan() + ?: TextPage(index = index + 1, title = "index:${index + 1}") } } - return dataSource.getNextChapter()?.page(0)?.apply { - if (text is SpannableStringBuilder) { - text.removeSpan(readAloudSpan) - } - } ?: TextPage( - index + 1, - App.INSTANCE.getString(R.string.data_loading), - "index:${index + 1}" - ) + return dataSource.getNextChapter()?.page(0)?.removePageAloudSpan() + ?: TextPage(index = index + 1, title = "index:${index + 1}") } override fun previousPage(): TextPage? = dataSource.pageIndex().let { index -> if (index > 0) { - return dataSource.getCurrentChapter()?.page(index - 1)?.apply { - if (text is SpannableStringBuilder) { - text.removeSpan(readAloudSpan) - } - } ?: TextPage( - index - 1, - App.INSTANCE.getString(R.string.data_loading), - "index:${index - 1}" - ) + return dataSource.getCurrentChapter()?.page(index - 1)?.removePageAloudSpan() + ?: TextPage(index = index - 1, title = "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}" - ) + return dataSource.getPreviousChapter()?.lastPage()?.removePageAloudSpan() + ?: TextPage(index = index - 1, title = "index:${index - 1}") }