|
|
@ -1,5 +1,8 @@ |
|
|
|
package io.legado.app.ui.widget.page |
|
|
|
package io.legado.app.ui.widget.page |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.legado.app.App |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
|
|
|
|
class TextPageFactory private constructor(dataSource: DataSource) : |
|
|
|
class TextPageFactory private constructor(dataSource: DataSource) : |
|
|
|
PageFactory<TextPage>(dataSource) { |
|
|
|
PageFactory<TextPage>(dataSource) { |
|
|
|
|
|
|
|
|
|
|
@ -63,28 +66,43 @@ 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, "index:$index", "index:$index") |
|
|
|
?: TextPage(index, App.INSTANCE.getString(R.string.data_loading), "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) |
|
|
|
return dataSource.getCurrentChapter()?.page(index + 1) |
|
|
|
?: TextPage(index + 1, "index:${index + 1}", "index:${index + 1}") |
|
|
|
?: TextPage( |
|
|
|
|
|
|
|
index + 1, |
|
|
|
|
|
|
|
App.INSTANCE.getString(R.string.data_loading), |
|
|
|
|
|
|
|
"index:${index + 1}" |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return dataSource.getNextChapter()?.page(0) |
|
|
|
return dataSource.getNextChapter()?.page(0) |
|
|
|
?: TextPage(index + 1, "index:${index + 1}", "index:${index + 1}") |
|
|
|
?: 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) |
|
|
|
return dataSource.getCurrentChapter()?.page(index - 1) |
|
|
|
?: TextPage(index - 1, "index:${index - 1}", "index:${index - 1}") |
|
|
|
?: TextPage( |
|
|
|
|
|
|
|
index - 1, |
|
|
|
|
|
|
|
App.INSTANCE.getString(R.string.data_loading), |
|
|
|
|
|
|
|
"index:${index - 1}" |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return dataSource.getPreviousChapter()?.lastPage() |
|
|
|
return dataSource.getPreviousChapter()?.lastPage() |
|
|
|
?: TextPage(index - 1, "index:${index - 1}", "index:${index - 1}") |
|
|
|
?: TextPage( |
|
|
|
|
|
|
|
index - 1, |
|
|
|
|
|
|
|
App.INSTANCE.getString(R.string.data_loading), |
|
|
|
|
|
|
|
"index:${index - 1}" |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|