|
|
@ -17,7 +17,7 @@ class PageView(context: Context, attrs: AttributeSet) : |
|
|
|
ContentView.CallBack, |
|
|
|
ContentView.CallBack, |
|
|
|
DataSource { |
|
|
|
DataSource { |
|
|
|
|
|
|
|
|
|
|
|
var callback: CallBack? = null |
|
|
|
var callBack: CallBack? = null |
|
|
|
var pageFactory: TextPageFactory? = null |
|
|
|
var pageFactory: TextPageFactory? = null |
|
|
|
private var pageDelegate: PageDelegate? = null |
|
|
|
private var pageDelegate: PageDelegate? = null |
|
|
|
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ class PageView(context: Context, attrs: AttributeSet) : |
|
|
|
var curlView: CurlView? = null |
|
|
|
var curlView: CurlView? = null |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
callback = activity as? CallBack |
|
|
|
callBack = activity as? CallBack |
|
|
|
prevPage = ContentView(context) |
|
|
|
prevPage = ContentView(context) |
|
|
|
addView(prevPage) |
|
|
|
addView(prevPage) |
|
|
|
nextPage = ContentView(context) |
|
|
|
nextPage = ContentView(context) |
|
|
@ -111,7 +111,7 @@ class PageView(context: Context, attrs: AttributeSet) : |
|
|
|
curPage?.setContent(it.currentPage()) |
|
|
|
curPage?.setContent(it.currentPage()) |
|
|
|
nextPage?.setContent(it.nextPage()) |
|
|
|
nextPage?.setContent(it.nextPage()) |
|
|
|
prevPage?.setContent(it.previousPage()) |
|
|
|
prevPage?.setContent(it.previousPage()) |
|
|
|
callback?.let { callback -> |
|
|
|
callBack?.let { callback -> |
|
|
|
if (isScrollDelegate) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
curPage?.scrollTo(callback.textChapter()?.getStartLine(callback.durChapterPos())) |
|
|
|
curPage?.scrollTo(callback.textChapter()?.getStartLine(callback.durChapterPos())) |
|
|
|
} |
|
|
|
} |
|
|
@ -128,7 +128,7 @@ class PageView(context: Context, attrs: AttributeSet) : |
|
|
|
fun moveToPrevPage(noAnim: Boolean = true) { |
|
|
|
fun moveToPrevPage(noAnim: Boolean = true) { |
|
|
|
if (noAnim) { |
|
|
|
if (noAnim) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
callback?.textChapter()?.let { |
|
|
|
callBack?.textChapter()?.let { |
|
|
|
curPage?.scrollTo(it.getStartLine(pageIndex - 1)) |
|
|
|
curPage?.scrollTo(it.getStartLine(pageIndex - 1)) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -140,7 +140,7 @@ class PageView(context: Context, attrs: AttributeSet) : |
|
|
|
fun moveToNextPage(noAnim: Boolean = true) { |
|
|
|
fun moveToNextPage(noAnim: Boolean = true) { |
|
|
|
if (noAnim) { |
|
|
|
if (noAnim) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
callback?.textChapter()?.let { |
|
|
|
callBack?.textChapter()?.let { |
|
|
|
curPage?.scrollTo(it.getStartLine(pageIndex + 1)) |
|
|
|
curPage?.scrollTo(it.getStartLine(pageIndex + 1)) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -180,68 +180,68 @@ class PageView(context: Context, attrs: AttributeSet) : |
|
|
|
get() = pageDelegate is ScrollPageDelegate |
|
|
|
get() = pageDelegate is ScrollPageDelegate |
|
|
|
|
|
|
|
|
|
|
|
override val pageIndex: Int |
|
|
|
override val pageIndex: Int |
|
|
|
get() = callback?.durChapterPos() ?: 0 |
|
|
|
get() = callBack?.durChapterPos() ?: 0 |
|
|
|
|
|
|
|
|
|
|
|
override fun setPageIndex(pageIndex: Int) { |
|
|
|
override fun setPageIndex(pageIndex: Int) { |
|
|
|
callback?.setPageIndex(pageIndex) |
|
|
|
callBack?.setPageIndex(pageIndex) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getChapterPosition(): Int { |
|
|
|
override fun getChapterPosition(): Int { |
|
|
|
return callback?.durChapterIndex() ?: 0 |
|
|
|
return callBack?.durChapterIndex() ?: 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getChapter(position: Int): TextChapter? { |
|
|
|
override fun getChapter(position: Int): TextChapter? { |
|
|
|
return callback?.textChapter(position) |
|
|
|
return callBack?.textChapter(position) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getCurrentChapter(): TextChapter? { |
|
|
|
override fun getCurrentChapter(): TextChapter? { |
|
|
|
return callback?.textChapter(0) |
|
|
|
return callBack?.textChapter(0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getNextChapter(): TextChapter? { |
|
|
|
override fun getNextChapter(): TextChapter? { |
|
|
|
return callback?.textChapter(1) |
|
|
|
return callBack?.textChapter(1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getPreviousChapter(): TextChapter? { |
|
|
|
override fun getPreviousChapter(): TextChapter? { |
|
|
|
return callback?.textChapter(-1) |
|
|
|
return callBack?.textChapter(-1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun hasNextChapter(): Boolean { |
|
|
|
override fun hasNextChapter(): Boolean { |
|
|
|
callback?.let { |
|
|
|
callBack?.let { |
|
|
|
return it.durChapterIndex() < it.chapterSize() - 1 |
|
|
|
return it.durChapterIndex() < it.chapterSize() - 1 |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun hasPrevChapter(): Boolean { |
|
|
|
override fun hasPrevChapter(): Boolean { |
|
|
|
callback?.let { |
|
|
|
callBack?.let { |
|
|
|
return it.durChapterIndex() > 0 |
|
|
|
return it.durChapterIndex() > 0 |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun moveToNextChapter() { |
|
|
|
override fun moveToNextChapter() { |
|
|
|
callback?.moveToNextChapter(false) |
|
|
|
callBack?.moveToNextChapter(false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun moveToPrevChapter() { |
|
|
|
override fun moveToPrevChapter() { |
|
|
|
callback?.moveToPrevChapter(false) |
|
|
|
callBack?.moveToPrevChapter(false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun scrollToLine(line: Int) { |
|
|
|
override fun scrollToLine(line: Int) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
callback?.textChapter()?.let { |
|
|
|
callBack?.textChapter()?.let { |
|
|
|
val pageIndex = it.getPageIndex(line) |
|
|
|
val pageIndex = it.getPageIndex(line) |
|
|
|
curPage?.setPageIndex(pageIndex) |
|
|
|
curPage?.setPageIndex(pageIndex) |
|
|
|
callback?.setPageIndex(pageIndex) |
|
|
|
callBack?.setPageIndex(pageIndex) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun scrollToLast() { |
|
|
|
override fun scrollToLast() { |
|
|
|
if (isScrollDelegate) { |
|
|
|
if (isScrollDelegate) { |
|
|
|
callback?.textChapter()?.let { |
|
|
|
callBack?.textChapter()?.let { |
|
|
|
callback?.setPageIndex(it.lastIndex()) |
|
|
|
callBack?.setPageIndex(it.lastIndex()) |
|
|
|
curPage?.setPageIndex(it.lastIndex()) |
|
|
|
curPage?.setPageIndex(it.lastIndex()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|