Increase new updates count when updates found

This commit is contained in:
Jobobby04 2024-12-08 13:35:58 -05:00
parent 76af3b59f0
commit c720f0ac5c

View File

@ -33,9 +33,11 @@ import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toList
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import tachiyomi.core.common.preference.getAndSet
import tachiyomi.domain.UnsortedPreferences import tachiyomi.domain.UnsortedPreferences
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.library.service.LibraryPreferences.Companion.DEVICE_CHARGING import tachiyomi.domain.library.service.LibraryPreferences.Companion.DEVICE_CHARGING
import tachiyomi.domain.library.service.LibraryPreferences.Companion.DEVICE_ONLY_ON_WIFI import tachiyomi.domain.library.service.LibraryPreferences.Companion.DEVICE_ONLY_ON_WIFI
import tachiyomi.domain.manga.interactor.GetExhFavoriteMangaWithMetadata import tachiyomi.domain.manga.interactor.GetExhFavoriteMangaWithMetadata
@ -52,6 +54,7 @@ import kotlin.time.Duration.Companion.days
class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerParameters) : class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerParameters) :
CoroutineWorker(context, workerParams) { CoroutineWorker(context, workerParams) {
private val preferences: UnsortedPreferences by injectLazy() private val preferences: UnsortedPreferences by injectLazy()
private val libraryPreferences: LibraryPreferences by injectLazy()
private val sourceManager: SourceManager by injectLazy() private val sourceManager: SourceManager by injectLazy()
private val updateHelper: EHentaiUpdateHelper by injectLazy() private val updateHelper: EHentaiUpdateHelper by injectLazy()
private val logger: Logger by lazy { xLog() } private val logger: Logger by lazy { xLog() }
@ -200,8 +203,10 @@ class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerPara
updateHelper.findAcceptedRootAndDiscardOthers(manga.source, chapters) updateHelper.findAcceptedRootAndDiscardOthers(manga.source, chapters)
if (new.isNotEmpty() && manga.id == acceptedRoot.manga.id) { if (new.isNotEmpty() && manga.id == acceptedRoot.manga.id) {
libraryPreferences.newUpdatesCount().getAndSet { it + new.size }
updatedManga += acceptedRoot.manga to new.toTypedArray() updatedManga += acceptedRoot.manga to new.toTypedArray()
} else if (exhNew.isNotEmpty() && updatedManga.none { it.first.id == acceptedRoot.manga.id }) { } else if (exhNew.isNotEmpty() && updatedManga.none { it.first.id == acceptedRoot.manga.id }) {
libraryPreferences.newUpdatesCount().getAndSet { it + exhNew.size }
updatedManga += acceptedRoot.manga to exhNew.toTypedArray() updatedManga += acceptedRoot.manga to exhNew.toTypedArray()
} }
@ -268,6 +273,7 @@ class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerPara
context.workManager.enqueue( context.workManager.enqueue(
OneTimeWorkRequestBuilder<EHentaiUpdateWorker>() OneTimeWorkRequestBuilder<EHentaiUpdateWorker>()
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) .setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.addTag(TAG)
.build(), .build(),
) )
} }