mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
chapter deletion logic fixed (#3320)
This commit is contained in:
parent
c041410f61
commit
f642f23366
1 changed files with 18 additions and 13 deletions
|
@ -361,7 +361,7 @@ class ReaderPresenter(
|
|||
if (selectedChapter.pages?.lastIndex == page.index) {
|
||||
selectedChapter.chapter.read = true
|
||||
updateTrackChapterRead(selectedChapter)
|
||||
enqueueDeleteReadChapters(selectedChapter)
|
||||
deleteChapterIfNeeded(selectedChapter)
|
||||
}
|
||||
|
||||
if (selectedChapter != currentChapters.currChapter) {
|
||||
|
@ -371,6 +371,22 @@ class ReaderPresenter(
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if deleting option is enabled and nth to last chapter actually exists.
|
||||
* If both conditions are satisfied enqueues chapter for delete
|
||||
* @param currentChapter current chapter, which is going to be marked as read.
|
||||
*/
|
||||
private fun deleteChapterIfNeeded(currentChapter: ReaderChapter) {
|
||||
// Determine which chapter should be deleted and enqueue
|
||||
val currentChapterPosition = chapterList.indexOf(currentChapter)
|
||||
val removeAfterReadSlots = preferences.removeAfterReadSlots()
|
||||
val chapterToDelete = chapterList.getOrNull(currentChapterPosition - removeAfterReadSlots)
|
||||
// Check if deleting option is enabled and chapter exists
|
||||
if (removeAfterReadSlots != -1 && chapterToDelete != null) {
|
||||
enqueueDeleteReadChapters(chapterToDelete)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a chapter changed from [fromChapter] to [toChapter]. It updates [fromChapter]
|
||||
* on the database.
|
||||
|
@ -653,19 +669,8 @@ class ReaderPresenter(
|
|||
if (!chapter.chapter.read || chapter.pageLoader !is DownloadPageLoader) return
|
||||
val manga = manga ?: return
|
||||
|
||||
// Return if the setting is disabled
|
||||
val removeAfterReadSlots = preferences.removeAfterReadSlots()
|
||||
if (removeAfterReadSlots == -1) return
|
||||
|
||||
launchIO {
|
||||
// Position of the read chapter
|
||||
val position = chapterList.indexOf(chapter)
|
||||
|
||||
// Retrieve chapter to delete according to preference
|
||||
val chapterToDelete = chapterList.getOrNull(position - removeAfterReadSlots)
|
||||
if (chapterToDelete != null) {
|
||||
downloadManager.enqueueDeleteChapters(listOf(chapterToDelete.chapter), manga)
|
||||
}
|
||||
downloadManager.enqueueDeleteChapters(listOf(chapter.chapter), manga)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue