Merge branch 'master' into sync-part-final

This commit is contained in:
KaiserBh 2023-08-03 16:06:17 +10:00 committed by GitHub
commit c4dc2c89cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
import eu.kanade.tachiyomi.extension.api.ExtensionUpdateNotifier
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.extension.model.InstallStep
import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.extension.model.LoadResult
@ -195,7 +196,7 @@ class ExtensionManager(
} }
/** /**
* Returns an observable of the installation process for the given extension. It will complete * Returns a flow of the installation process for the given extension. It will complete
* once the extension is installed or throws an error. The process will be canceled if * once the extension is installed or throws an error. The process will be canceled if
* unsubscribed before its completion. * unsubscribed before its completion.
* *
@ -206,7 +207,7 @@ class ExtensionManager(
} }
/** /**
* Returns an observable of the installation process for the given extension. It will complete * Returns a flow of the installation process for the given extension. It will complete
* once the extension is updated or throws an error. The process will be canceled if * once the extension is updated or throws an error. The process will be canceled if
* unsubscribed before its completion. * unsubscribed before its completion.
* *
@ -356,6 +357,10 @@ class ExtensionManager(
} }
private fun updatePendingUpdatesCount() { private fun updatePendingUpdatesCount() {
preferences.extensionUpdatesCount().set(_installedExtensionsFlow.value.count { it.hasUpdate }) val pendingUpdateCount = _installedExtensionsFlow.value.count { it.hasUpdate }
preferences.extensionUpdatesCount().set(pendingUpdateCount)
if (pendingUpdateCount == 0) {
ExtensionUpdateNotifier(context).dismiss()
}
} }
} }

View File

@ -5,6 +5,7 @@ import androidx.core.app.NotificationCompat
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.notify import eu.kanade.tachiyomi.util.system.notify
class ExtensionUpdateNotifier(private val context: Context) { class ExtensionUpdateNotifier(private val context: Context) {
@ -29,4 +30,8 @@ class ExtensionUpdateNotifier(private val context: Context) {
setAutoCancel(true) setAutoCancel(true)
} }
} }
fun dismiss() {
context.cancelNotification(Notifications.ID_UPDATES_TO_EXTS)
}
} }

View File

@ -157,14 +157,14 @@ class ExtensionsScreenModel(
extensionManager.cancelInstallUpdateExtension(extension) extensionManager.cancelInstallUpdateExtension(extension)
} }
private fun removeDownloadState(extension: Extension) {
_currentDownloads.update { it - extension.pkgName }
}
private fun addDownloadState(extension: Extension, installStep: InstallStep) { private fun addDownloadState(extension: Extension, installStep: InstallStep) {
_currentDownloads.update { it + Pair(extension.pkgName, installStep) } _currentDownloads.update { it + Pair(extension.pkgName, installStep) }
} }
private fun removeDownloadState(extension: Extension) {
_currentDownloads.update { it - extension.pkgName }
}
private suspend fun Flow<InstallStep>.collectToInstallUpdate(extension: Extension) = private suspend fun Flow<InstallStep>.collectToInstallUpdate(extension: Extension) =
this this
.onEach { installStep -> addDownloadState(extension, installStep) } .onEach { installStep -> addDownloadState(extension, installStep) }

View File

@ -40,7 +40,7 @@ class SetFetchInterval(
fun getWindow(dateTime: ZonedDateTime): Pair<Long, Long> { fun getWindow(dateTime: ZonedDateTime): Pair<Long, Long> {
val today = dateTime.toLocalDate().atStartOfDay(dateTime.zone) val today = dateTime.toLocalDate().atStartOfDay(dateTime.zone)
val lowerBound = today.minusDays(FETCH_INTERVAL_GRACE_PERIOD.toLong()) val lowerBound = today.minusDays(FETCH_INTERVAL_GRACE_PERIOD.toLong())
val upperBound = lowerBound.plusDays(FETCH_INTERVAL_GRACE_PERIOD.toLong()) val upperBound = today.plusDays(FETCH_INTERVAL_GRACE_PERIOD.toLong())
return Pair(lowerBound.toEpochSecond() * 1000, upperBound.toEpochSecond() * 1000 - 1) return Pair(lowerBound.toEpochSecond() * 1000, upperBound.toEpochSecond() * 1000 - 1)
} }