Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide entries whose scanlators are excluded from updates tab #1623

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
### Added
- Add option to always decode long strip images with SSIV

### Changed
- Hide entries whose scanlators are excluded from updates tab ([@shabnix](https://github.com/shabnix)) ([#1623](https://github.com/mihonapp/mihon/pull/1623))

### Fixed
- Fix MAL `main_picture` nullability breaking search if a result doesn't have a cover set ([@MajorTanya](https://github.com/MajorTanya)) ([#1618](https://github.com/mihonapp/mihon/pull/1618))

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/eu/kanade/domain/DomainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import mihon.domain.extensionrepo.interactor.UpdateExtensionRepo
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
import mihon.domain.extensionrepo.service.ExtensionRepoService
import mihon.domain.upcoming.interactor.GetUpcomingManga
import mihon.domain.updates.interactor.FilterExcludedScanlators
import tachiyomi.data.category.CategoryRepositoryImpl
import tachiyomi.data.chapter.ChapterRepositoryImpl
import tachiyomi.data.history.HistoryRepositoryImpl
Expand Down Expand Up @@ -169,6 +170,7 @@ class DomainModule : InjektModule {

addSingletonFactory<UpdatesRepository> { UpdatesRepositoryImpl(get()) }
addFactory { GetUpdates(get()) }
addFactory { FilterExcludedScanlators(get()) }

addSingletonFactory<SourceRepository> { SourceRepositoryImpl(get(), get()) }
addSingletonFactory<StubSourceRepository> { StubSourceRepositoryImpl(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ class GetExcludedScanlators(
}
.map { it.toSet() }
}

fun notify(): Flow<Unit> {
return handler.subscribeToList {
excluded_scanlatorsQueries.observeChanges()
}
.map { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import eu.kanade.core.preference.asState
import eu.kanade.core.util.addOrRemove
import eu.kanade.core.util.insertSeparators
import eu.kanade.domain.chapter.interactor.SetReadStatus
import eu.kanade.domain.manga.interactor.GetExcludedScanlators
import eu.kanade.presentation.manga.components.ChapterDownloadAction
import eu.kanade.presentation.updates.UpdatesUiModel
import eu.kanade.tachiyomi.data.download.DownloadCache
Expand All @@ -32,6 +33,7 @@ import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import logcat.LogPriority
import mihon.domain.updates.interactor.FilterExcludedScanlators
import tachiyomi.core.common.util.lang.launchIO
import tachiyomi.core.common.util.lang.launchNonCancellable
import tachiyomi.core.common.util.system.logcat
Expand All @@ -57,6 +59,8 @@ class UpdatesScreenModel(
private val getManga: GetManga = Injekt.get(),
private val getChapter: GetChapter = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val filterExcludedScanlators: FilterExcludedScanlators = Injekt.get(),
private val getExcludedScanlators: GetExcludedScanlators = Injekt.get(),
val snackbarHostState: SnackbarHostState = SnackbarHostState(),
) : StateScreenModel<UpdatesScreenModel.State>(State()) {

Expand All @@ -78,16 +82,19 @@ class UpdatesScreenModel(
getUpdates.subscribe(limit).distinctUntilChanged(),
downloadCache.changes,
downloadManager.queueState,
) { updates, _, _ -> updates }
getExcludedScanlators.notify(),
) { updates, _, _, _ -> updates }
.catch {
logcat(LogPriority.ERROR, it)
_events.send(Event.InternalError)
}
.collectLatest { updates ->
val filteredUpdates = filterExcludedScanlators.await(updates)

mutableState.update {
it.copy(
isLoading = false,
items = updates.toUpdateItems(),
items = filteredUpdates.toUpdateItems(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package mihon.domain.updates.interactor

import eu.kanade.domain.manga.interactor.GetExcludedScanlators
import tachiyomi.domain.updates.model.UpdatesWithRelations

/**
* Filters a list of manga updates to exclude those with scanlators marked as excluded.
*
* @property getExcludedScanlators Fetches the excluded scanlators for a manga ID.
*/
class FilterExcludedScanlators(
private val getExcludedScanlators: GetExcludedScanlators,
) {

/**
* Filters updates to exclude those with scanlators in the excluded list for their manga.
*
* @param updates The list of manga updates to filter.
* @return A filtered list of updates.
*/
suspend fun await(updates: List<UpdatesWithRelations>): List<UpdatesWithRelations> {
val excludedScanlatorsCache = mutableMapOf<Long, Set<String>>()

return updates.filter {
val excludedScanlators = excludedScanlatorsCache.getOrPut(it.mangaId) {
getExcludedScanlators.await(it.mangaId)
}

it.scanlator !in excludedScanlators
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ getExcludedScanlatorsByMangaId:
SELECT scanlator
FROM excluded_scanlators
WHERE manga_id = :mangaId;

observeChanges:
SELECT 1
FROM excluded_scanlators
LIMIT 1;
Loading