Added read filter to chapter select. (#431)
* Added read filter to chapter select. * Can now select how far back the chapter should be deleted after read.
This commit is contained in:
committed by
GitHub
parent
8ffff44454
commit
d8d93ee344
@@ -228,12 +228,14 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||
* strategy set for the manga.
|
||||
*
|
||||
* @param chapter the current active chapter.
|
||||
* @param previousChapterAmount the desired number of chapters preceding the current active chapter (Default: 1).
|
||||
* @param nextChapterAmount the desired number of chapters succeeding the current active chapter (Default: 1).
|
||||
*/
|
||||
private fun getAdjacentChaptersStrategy(chapter: ReaderChapter) = when (manga.sorting) {
|
||||
private fun getAdjacentChaptersStrategy(chapter: ReaderChapter, previousChapterAmount: Int = 1, nextChapterAmount: Int = 1) = when (manga.sorting) {
|
||||
Manga.SORTING_SOURCE -> {
|
||||
val currChapterIndex = chapterList.indexOfFirst { chapter.id == it.id }
|
||||
val nextChapter = chapterList.getOrNull(currChapterIndex + 1)
|
||||
val prevChapter = chapterList.getOrNull(currChapterIndex - 1)
|
||||
val nextChapter = chapterList.getOrNull(currChapterIndex + nextChapterAmount)
|
||||
val prevChapter = chapterList.getOrNull(currChapterIndex - previousChapterAmount)
|
||||
Pair(prevChapter, nextChapter)
|
||||
}
|
||||
Manga.SORTING_NUMBER -> {
|
||||
@@ -241,18 +243,18 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||
val chapterNumber = chapter.chapter_number
|
||||
|
||||
var prevChapter: ReaderChapter? = null
|
||||
for (i in (currChapterIndex - 1) downTo 0) {
|
||||
for (i in (currChapterIndex - previousChapterAmount) downTo 0) {
|
||||
val c = chapterList[i]
|
||||
if (c.chapter_number < chapterNumber && c.chapter_number >= chapterNumber - 1) {
|
||||
if (c.chapter_number < chapterNumber && c.chapter_number >= chapterNumber - previousChapterAmount) {
|
||||
prevChapter = c
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var nextChapter: ReaderChapter? = null
|
||||
for (i in (currChapterIndex + 1) until chapterList.size) {
|
||||
for (i in (currChapterIndex + nextChapterAmount) until chapterList.size) {
|
||||
val c = chapterList[i]
|
||||
if (c.chapter_number > chapterNumber && c.chapter_number <= chapterNumber + 1) {
|
||||
if (c.chapter_number > chapterNumber && c.chapter_number <= chapterNumber + nextChapterAmount) {
|
||||
nextChapter = c
|
||||
break
|
||||
}
|
||||
@@ -344,7 +346,6 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||
fun onChapterLeft() {
|
||||
// Reference these locally because they are needed later from another thread.
|
||||
val chapter = chapter
|
||||
val prevChapter = prevChapter
|
||||
|
||||
val pages = chapter.pages ?: return
|
||||
|
||||
@@ -355,21 +356,21 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||
chapter.read = true
|
||||
}
|
||||
|
||||
// Cache current page list progress for online chapters to allow a faster reopen
|
||||
if (!chapter.isDownloaded) {
|
||||
source.let { if (it is OnlineSource) it.savePageList(chapter, pages) }
|
||||
}
|
||||
|
||||
// Cache current page list progress for online chapters to allow a faster reopen
|
||||
if (chapter.read) {
|
||||
// Check if remove after read is selected by user
|
||||
if (prefs.removeAfterRead()) {
|
||||
if (prefs.removeAfterReadPrevious() ) {
|
||||
if (prevChapter != null) {
|
||||
deleteChapter(prevChapter, manga)
|
||||
}
|
||||
} else {
|
||||
deleteChapter(chapter, manga)
|
||||
}
|
||||
val removeAfterReadSlots = prefs.removeAfterReadSlots()
|
||||
when (removeAfterReadSlots) {
|
||||
// Setting disabled
|
||||
-1 -> { /**Empty function**/ }
|
||||
// Remove current read chapter
|
||||
0 -> deleteChapter(chapter, manga)
|
||||
// Remove previous chapter specified by user in settings.
|
||||
else -> getAdjacentChaptersStrategy(chapter, removeAfterReadSlots)
|
||||
.first?.let { deleteChapter(it, manga) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user