mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 11:35:08 +01:00
Change Updates icon badge to show new updates count (#8659)
* Change Updates icon badge to show new updates count * Fix reference * review changes * Lint
This commit is contained in:
parent
7be9b49143
commit
373463e995
@ -130,7 +130,7 @@ class DomainModule : InjektModule {
|
||||
addFactory { GetExtensionLanguages(get(), get()) }
|
||||
|
||||
addSingletonFactory<UpdatesRepository> { UpdatesRepositoryImpl(get()) }
|
||||
addFactory { GetUpdates(get(), get()) }
|
||||
addFactory { GetUpdates(get()) }
|
||||
|
||||
addSingletonFactory<SourceRepository> { SourceRepositoryImpl(get(), get()) }
|
||||
addSingletonFactory<SourceDataRepository> { SourceDataRepositoryImpl(get()) }
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<List<UpdatesWithRelations>> = subscribe(calendar.time.time)
|
||||
|
||||
fun subscribe(after: Long): Flow<List<UpdatesWithRelations>> {
|
||||
return repository.subscribeAll(after)
|
||||
.onEach { updates ->
|
||||
// Set unread chapter count for bottom bar badge
|
||||
preferences.unreadUpdatesCount().set(updates.count { !it.read })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,13 +37,6 @@ object SettingsGeneralScreen : SearchableSettings {
|
||||
val prefs = remember { Injekt.get<BasePreferences>() }
|
||||
val libraryPrefs = remember { Injekt.get<LibraryPreferences>() }
|
||||
return mutableListOf<Preference>().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(),
|
||||
|
@ -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<Pair<Manga, String?>>()
|
||||
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)
|
||||
}
|
||||
|
@ -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<LibraryPreferences>()
|
||||
combine(
|
||||
pref.showUpdatesNavBadge().changes(),
|
||||
pref.unreadUpdatesCount().changes(),
|
||||
) { show, count -> if (show) count else 0 }
|
||||
Injekt.get<LibraryPreferences>()
|
||||
.newUpdatesCount().changes()
|
||||
.collectLatest { value = it }
|
||||
}
|
||||
if (count > 0) {
|
||||
|
@ -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>(UpdatesState()) {
|
||||
|
||||
private val _events: Channel<Event> = 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<UpdatesItem>) : Dialog()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,6 @@
|
||||
<string name="pref_update_only_completely_read">With unread chapter(s)</string>
|
||||
<string name="pref_update_only_non_completed">With \"Completed\" status</string>
|
||||
<string name="pref_update_only_started">That haven\'t been started</string>
|
||||
<string name="pref_library_update_show_tab_badge">Show unread count on Updates icon</string>
|
||||
<string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string>
|
||||
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>
|
||||
<string name="pref_library_update_refresh_trackers">Automatically refresh trackers</string>
|
||||
|
Loading…
Reference in New Issue
Block a user