-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to skip downloading duplicate read chapters (#1125)
* Add query to get chapter count by manga and chapter number * Add functions to get chapter count by manga and chapter number * Only count read chapters * Add interactor * Savepoint * Extract new chapter logic to separate function * Update javadocs * Add preference to toggle new functionality * Add todo * Add debug logcat * Use string resource instead of hardcoding title * Add temporary logcat for debugging * Fix detekt issues * Update javadocs * Update download unread chapters preference * Remove debug logcat calls * Update javadocs * Resolve issue where read chapters were still being downloaded during manual manga fetch * Apply code review changes * Apply code review changes * Revert "Apply code review changes" This reverts commit 1a2dce78acc66a7c529ce5b572bdaf94804b1a30. * Revert "Apply code review changes" This reverts commit ac2a77829313967ad39ce3cb0c0231083b9d640d. * Group download chapter logic inside the interactor GetChaptersToDownload * Update javadocs * Apply code review * Apply code review * Apply code review * Update CHANGELOG.md to include the new feature * Run spotless * Update domain/src/main/java/mihon/domain/chapter/interactor/FilterChaptersForDownload.kt --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
- Loading branch information
Showing
9 changed files
with
101 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
domain/src/main/java/mihon/domain/chapter/interactor/FilterChaptersForDownload.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package mihon.domain.chapter.interactor | ||
|
||
import tachiyomi.domain.category.interactor.GetCategories | ||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId | ||
import tachiyomi.domain.chapter.model.Chapter | ||
import tachiyomi.domain.download.service.DownloadPreferences | ||
import tachiyomi.domain.manga.model.Manga | ||
|
||
/** | ||
* Interactor responsible for determining which chapters of a manga should be downloaded. | ||
* | ||
* @property getChaptersByMangaId Interactor for retrieving chapters by manga ID. | ||
* @property downloadPreferences User preferences related to chapter downloads. | ||
* @property getCategories Interactor for retrieving categories associated with a manga. | ||
*/ | ||
class FilterChaptersForDownload( | ||
private val getChaptersByMangaId: GetChaptersByMangaId, | ||
private val downloadPreferences: DownloadPreferences, | ||
private val getCategories: GetCategories, | ||
) { | ||
|
||
/** | ||
* Determines which chapters of a manga should be downloaded based on user preferences. | ||
* | ||
* @param manga The manga for which chapters may be downloaded. | ||
* @param newChapters The list of new chapters available for the manga. | ||
* @return A list of chapters that should be downloaded | ||
*/ | ||
suspend fun await(manga: Manga, newChapters: List<Chapter>): List<Chapter> { | ||
if ( | ||
newChapters.isEmpty() || | ||
!downloadPreferences.downloadNewChapters().get() || | ||
!manga.shouldDownloadNewChapters() | ||
) { | ||
return emptyList() | ||
} | ||
|
||
if (!downloadPreferences.downloadNewUnreadChaptersOnly().get()) return newChapters | ||
|
||
val readChapterNumbers = getChaptersByMangaId.await(manga.id) | ||
.asSequence() | ||
.filter { it.read && it.isRecognizedNumber } | ||
.map { it.chapterNumber } | ||
.toSet() | ||
|
||
return newChapters.filterNot { it.chapterNumber in readChapterNumbers } | ||
} | ||
|
||
/** | ||
* Determines whether new chapters should be downloaded for the manga based on user preferences and the | ||
* categories to which the manga belongs. | ||
* | ||
* @return `true` if chapters of the manga should be downloaded | ||
*/ | ||
private suspend fun Manga.shouldDownloadNewChapters(): Boolean { | ||
if (!favorite) return false | ||
|
||
val categories = getCategories.await(id).map { it.id }.ifEmpty { listOf(DEFAULT_CATEGORY_ID) } | ||
val includedCategories = downloadPreferences.downloadNewChapterCategories().get().map { it.toLong() } | ||
val excludedCategories = downloadPreferences.downloadNewChapterCategoriesExclude().get().map { it.toLong() } | ||
|
||
return when { | ||
// Default Download from all categories | ||
includedCategories.isEmpty() && excludedCategories.isEmpty() -> true | ||
// In excluded category | ||
categories.any { it in excludedCategories } -> false | ||
// Included category not selected | ||
includedCategories.isEmpty() -> true | ||
// In included category | ||
else -> categories.any { it in includedCategories } | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DEFAULT_CATEGORY_ID = 0L | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters