|
|
@ -9,13 +9,21 @@ class TextPageFactory private constructor(dataSource: DataSource) : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun hasPrev(): Boolean { |
|
|
|
override fun hasPrev(): Boolean = with(dataSource) { |
|
|
|
return dataSource.hasPrevChapter() || dataSource.pageIndex() > 0 |
|
|
|
return if (isScrollDelegate()) { |
|
|
|
|
|
|
|
hasPrevChapter() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
hasPrevChapter() || pageIndex() > 0 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun hasNext(): Boolean { |
|
|
|
override fun hasNext(): Boolean = with(dataSource) { |
|
|
|
return dataSource.hasNextChapter() |
|
|
|
return if (isScrollDelegate()) { |
|
|
|
|| dataSource.getCurrentChapter()?.isLastIndex(dataSource.pageIndex()) != true |
|
|
|
hasNextChapter() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
hasNextChapter() |
|
|
|
|
|
|
|
|| getCurrentChapter()?.isLastIndex(pageIndex()) != true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun pageAt(index: Int): TextPage { |
|
|
|
override fun pageAt(index: Int): TextPage { |
|
|
@ -27,76 +35,76 @@ class TextPageFactory private constructor(dataSource: DataSource) : |
|
|
|
dataSource.setPageIndex(0) |
|
|
|
dataSource.setPageIndex(0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun moveToLast() { |
|
|
|
override fun moveToLast() = with(dataSource) { |
|
|
|
dataSource.getCurrentChapter()?.let { |
|
|
|
getCurrentChapter()?.let { |
|
|
|
if (it.pageSize() == 0) { |
|
|
|
if (it.pageSize() == 0) { |
|
|
|
dataSource.setPageIndex(0) |
|
|
|
setPageIndex(0) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dataSource.setPageIndex(it.pageSize().minus(1)) |
|
|
|
setPageIndex(it.pageSize().minus(1)) |
|
|
|
} |
|
|
|
} |
|
|
|
} ?: dataSource.setPageIndex(0) |
|
|
|
} ?: setPageIndex(0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun moveToNext(): Boolean = dataSource.pageIndex().let { index -> |
|
|
|
override fun moveToNext(): Boolean = with(dataSource) { |
|
|
|
return if (hasNext()) { |
|
|
|
return if (hasNext()) { |
|
|
|
if (dataSource.getCurrentChapter()?.isLastIndex(index) == true |
|
|
|
if (getCurrentChapter()?.isLastIndex(pageIndex()) == true |
|
|
|
|| dataSource.isScrollDelegate() |
|
|
|
|| isScrollDelegate() |
|
|
|
) { |
|
|
|
) { |
|
|
|
dataSource.moveToNextChapter() |
|
|
|
moveToNextChapter() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dataSource.setPageIndex(index.plus(1)) |
|
|
|
setPageIndex(pageIndex().plus(1)) |
|
|
|
} |
|
|
|
} |
|
|
|
true |
|
|
|
true |
|
|
|
} else |
|
|
|
} else |
|
|
|
false |
|
|
|
false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun moveToPrevious(): Boolean = dataSource.pageIndex().let { index -> |
|
|
|
override fun moveToPrevious(): Boolean = with(dataSource) { |
|
|
|
return if (hasPrev()) { |
|
|
|
return if (hasPrev()) { |
|
|
|
if (index <= 0 || dataSource.isScrollDelegate()) { |
|
|
|
if (pageIndex() <= 0 || isScrollDelegate()) { |
|
|
|
dataSource.moveToPrevChapter() |
|
|
|
moveToPrevChapter() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dataSource.setPageIndex(index.minus(1)) |
|
|
|
setPageIndex(pageIndex().minus(1)) |
|
|
|
} |
|
|
|
} |
|
|
|
true |
|
|
|
true |
|
|
|
} else |
|
|
|
} else |
|
|
|
false |
|
|
|
false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun currentPage(): TextPage? = dataSource.pageIndex().let { index -> |
|
|
|
override fun currentPage(): TextPage? = with(dataSource) { |
|
|
|
return if (dataSource.isScrollDelegate()) { |
|
|
|
return if (isScrollDelegate()) { |
|
|
|
dataSource.getCurrentChapter()?.scrollPage() |
|
|
|
getCurrentChapter()?.scrollPage() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dataSource.getCurrentChapter()?.page(index) |
|
|
|
getCurrentChapter()?.page(pageIndex()) |
|
|
|
} ?: TextPage(index = index, title = "index:$index") |
|
|
|
} ?: TextPage(index = pageIndex(), title = "index:${pageIndex()}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun nextPage(): TextPage? = dataSource.pageIndex().let { index -> |
|
|
|
override fun nextPage(): TextPage? = with(dataSource) { |
|
|
|
if (dataSource.isScrollDelegate()) { |
|
|
|
if (isScrollDelegate()) { |
|
|
|
return dataSource.getNextChapter()?.scrollPage() |
|
|
|
return getNextChapter()?.scrollPage() |
|
|
|
?: TextPage(index = index + 1, title = "index:${index + 1}") |
|
|
|
?: TextPage(index = pageIndex() + 1, title = "index:${pageIndex() + 1}") |
|
|
|
} |
|
|
|
} |
|
|
|
dataSource.getCurrentChapter()?.let { |
|
|
|
getCurrentChapter()?.let { |
|
|
|
if (index < it.pageSize() - 1) { |
|
|
|
if (pageIndex() < it.pageSize() - 1) { |
|
|
|
return dataSource.getCurrentChapter()?.page(index + 1)?.removePageAloudSpan() |
|
|
|
return getCurrentChapter()?.page(pageIndex() + 1)?.removePageAloudSpan() |
|
|
|
?: TextPage(index = index + 1, title = "index:${index + 1}") |
|
|
|
?: TextPage(index = pageIndex() + 1, title = "index:${pageIndex() + 1}") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return dataSource.getNextChapter()?.page(0)?.removePageAloudSpan() |
|
|
|
return getNextChapter()?.page(0)?.removePageAloudSpan() |
|
|
|
?: TextPage(index = index + 1, title = "index:${index + 1}") |
|
|
|
?: TextPage(index = pageIndex() + 1, title = "index:${pageIndex() + 1}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun previousPage(): TextPage? = dataSource.pageIndex().let { index -> |
|
|
|
override fun previousPage(): TextPage? = with(dataSource) { |
|
|
|
if (dataSource.isScrollDelegate()) { |
|
|
|
if (isScrollDelegate()) { |
|
|
|
return dataSource.getPreviousChapter()?.scrollPage() |
|
|
|
return getPreviousChapter()?.scrollPage() |
|
|
|
?: TextPage(index = index + 1, title = "index:${index + 1}") |
|
|
|
?: TextPage(index = pageIndex() + 1, title = "index:${pageIndex() + 1}") |
|
|
|
} |
|
|
|
} |
|
|
|
if (index > 0) { |
|
|
|
if (pageIndex() > 0) { |
|
|
|
return dataSource.getCurrentChapter()?.page(index - 1)?.removePageAloudSpan() |
|
|
|
return getCurrentChapter()?.page(pageIndex() - 1)?.removePageAloudSpan() |
|
|
|
?: TextPage(index = index - 1, title = "index:${index - 1}") |
|
|
|
?: TextPage(index = pageIndex() - 1, title = "index:${pageIndex() - 1}") |
|
|
|
} |
|
|
|
} |
|
|
|
return dataSource.getPreviousChapter()?.lastPage()?.removePageAloudSpan() |
|
|
|
return getPreviousChapter()?.lastPage()?.removePageAloudSpan() |
|
|
|
?: TextPage(index = index - 1, title = "index:${index - 1}") |
|
|
|
?: TextPage(index = pageIndex() - 1, title = "index:${pageIndex() - 1}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|