diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index 0b5db26c8..e007f4950 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -130,7 +130,7 @@ class DomainModule : InjektModule { addFactory { GetExtensionLanguages(get(), get()) } addSingletonFactory { UpdatesRepositoryImpl(get()) } - addFactory { GetUpdates(get(), get()) } + addFactory { GetUpdates(get()) } addSingletonFactory { SourceRepositoryImpl(get(), get()) } addSingletonFactory { SourceDataRepositoryImpl(get()) } diff --git a/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt b/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt index d78d980fc..7f3d21544 100644 --- a/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt +++ b/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt @@ -60,8 +60,7 @@ class LibraryPreferences( fun languageBadge() = preferenceStore.getBoolean("display_language_badge", false) - fun showUpdatesNavBadge() = preferenceStore.getBoolean("library_update_show_tab_badge", false) - fun unreadUpdatesCount() = preferenceStore.getInt("library_unread_updates_count", 0) + fun newUpdatesCount() = preferenceStore.getInt("library_unseen_updates_count", 0) // endregion diff --git a/app/src/main/java/eu/kanade/domain/updates/interactor/GetUpdates.kt b/app/src/main/java/eu/kanade/domain/updates/interactor/GetUpdates.kt index c26ebfb18..b9e04b880 100644 --- a/app/src/main/java/eu/kanade/domain/updates/interactor/GetUpdates.kt +++ b/app/src/main/java/eu/kanade/domain/updates/interactor/GetUpdates.kt @@ -1,24 +1,17 @@ package eu.kanade.domain.updates.interactor -import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.updates.model.UpdatesWithRelations import eu.kanade.domain.updates.repository.UpdatesRepository import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.onEach import java.util.Calendar class GetUpdates( private val repository: UpdatesRepository, - private val preferences: LibraryPreferences, ) { fun subscribe(calendar: Calendar): Flow> = subscribe(calendar.time.time) fun subscribe(after: Long): Flow> { return repository.subscribeAll(after) - .onEach { updates -> - // Set unread chapter count for bottom bar badge - preferences.unreadUpdatesCount().set(updates.count { !it.read }) - } } } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt index e518636ac..9df7d12a0 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt @@ -37,13 +37,6 @@ object SettingsGeneralScreen : SearchableSettings { val prefs = remember { Injekt.get() } val libraryPrefs = remember { Injekt.get() } return mutableListOf().apply { - add( - Preference.PreferenceItem.SwitchPreference( - pref = libraryPrefs.showUpdatesNavBadge(), - title = stringResource(R.string.pref_library_update_show_tab_badge), - ), - ) - add( Preference.PreferenceItem.SwitchPreference( pref = prefs.confirmExit(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 6c37379d7..eb7970436 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -26,6 +26,7 @@ import eu.kanade.domain.track.interactor.InsertTrack import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.core.preference.getAndSet import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService @@ -312,7 +313,6 @@ class LibraryUpdateService( val failedUpdates = CopyOnWriteArrayList>() val hasDownloads = AtomicBoolean(false) val loggedServices by lazy { trackManager.services.filter { it.isLogged } } - val currentUnreadUpdatesCount = libraryPreferences.unreadUpdatesCount().get() val restrictions = libraryPreferences.libraryUpdateMangaRestriction().get() withIOContext { @@ -362,6 +362,8 @@ class LibraryUpdateService( hasDownloads.set(true) } + libraryPreferences.newUpdatesCount().getAndSet { it + newChapters.size } + // Convert to the manga that contains new chapters newUpdates.add(manga to newChapters.toTypedArray()) } @@ -392,8 +394,6 @@ class LibraryUpdateService( if (newUpdates.isNotEmpty()) { notifier.showUpdateNotifications(newUpdates) - val newChapterCount = newUpdates.sumOf { it.second.size } - libraryPreferences.unreadUpdatesCount().set(currentUnreadUpdatesCount + newChapterCount) if (hasDownloads.get()) { DownloadService.start(this) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/home/HomeScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/home/HomeScreen.kt index 757026514..a6ac722e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/home/HomeScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/home/HomeScreen.kt @@ -40,7 +40,6 @@ import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.components.NavigationBar import eu.kanade.presentation.components.NavigationRail import eu.kanade.presentation.components.Scaffold -import eu.kanade.presentation.util.Tab import eu.kanade.presentation.util.Transition import eu.kanade.presentation.util.isTabletUi import eu.kanade.tachiyomi.R @@ -52,7 +51,6 @@ import eu.kanade.tachiyomi.ui.more.MoreTab import eu.kanade.tachiyomi.ui.updates.UpdatesTab import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch import uy.kohesive.injekt.Injekt @@ -219,11 +217,8 @@ object HomeScreen : Screen { when { tab is UpdatesTab -> { val count by produceState(initialValue = 0) { - val pref = Injekt.get() - combine( - pref.showUpdatesNavBadge().changes(), - pref.unreadUpdatesCount().changes(), - ) { show, count -> if (show) count else 0 } + Injekt.get() + .newUpdatesCount().changes() .collectLatest { value = it } } if (count > 0) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt index 47e172d4e..c5de15e0f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt @@ -60,10 +60,10 @@ class UpdatesScreenModel( private val getUpdates: GetUpdates = Injekt.get(), private val getManga: GetManga = Injekt.get(), private val getChapter: GetChapter = Injekt.get(), + private val libraryPreferences: LibraryPreferences = Injekt.get(), val snackbarHostState: SnackbarHostState = SnackbarHostState(), basePreferences: BasePreferences = Injekt.get(), uiPreferences: UiPreferences = Injekt.get(), - libraryPreferences: LibraryPreferences = Injekt.get(), ) : StateScreenModel(UpdatesState()) { private val _events: Channel = Channel(Int.MAX_VALUE) @@ -371,6 +371,10 @@ class UpdatesScreenModel( mutableState.update { it.copy(dialog = dialog) } } + fun resetNewUpdatesCount() { + libraryPreferences.newUpdatesCount().set(0) + } + sealed class Dialog { data class DeleteConfirmation(val toDelete: List) : Dialog() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesTab.kt index ba3af64f1..3f0248891 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesTab.kt @@ -4,6 +4,7 @@ import androidx.compose.animation.graphics.res.animatedVectorResource import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter import androidx.compose.animation.graphics.vector.AnimatedImageVector import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -110,5 +111,12 @@ object UpdatesTab : Tab { (context as? MainActivity)?.ready = true } } + DisposableEffect(Unit) { + screenModel.resetNewUpdatesCount() + + onDispose { + screenModel.resetNewUpdatesCount() + } + } } } diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index aaa6df186..5f926ae22 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -254,7 +254,6 @@ With unread chapter(s) With \"Completed\" status That haven\'t been started - Show unread count on Updates icon Automatically refresh metadata Check for new cover and details when updating library Automatically refresh trackers