From f629db3c106726eeb971f605eb197c50a2484f40 Mon Sep 17 00:00:00 2001 From: len Date: Sun, 22 May 2016 23:40:44 +0200 Subject: [PATCH] Exclude manga from unknown sources from the library --- .../tachiyomi/ui/library/LibraryPresenter.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 25b7e7e0c..0a8330067 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -129,10 +129,8 @@ class LibraryPresenter : BasePresenter() { return db.getLibraryMangas().asRxObservable() .flatMap { mangas -> Observable.from(mangas) - .filter { - // Filter library by options - filterLibrary(it) - } + // Filter library by options + .filter { filterManga(it) } .groupBy { it.category } .flatMap { group -> group.toList().map { Pair(group.key, it) } } .toMap({ it.first }, { it.second }) @@ -156,12 +154,15 @@ class LibraryPresenter : BasePresenter() { } /** - * Filter library by preference + * Filters an entry of the library. * - * @param manga from library - * @return filter status + * @param manga a favorite manga from the database. + * @return true if the entry is included, false otherwise. */ - fun filterLibrary(manga: Manga): Boolean { + fun filterManga(manga: Manga): Boolean { + // Filter out manga without source + val source = sourceManager.get(manga.source) ?: return false + val prefFilterDownloaded = preferences.filterDownloaded().getOrDefault() val prefFilterUnread = preferences.filterUnread().getOrDefault() @@ -178,7 +179,7 @@ class LibraryPresenter : BasePresenter() { } if (prefFilterDownloaded) { - val mangaDir = downloadManager.getAbsoluteMangaDirectory(sourceManager.get(manga.source)!!, manga) + val mangaDir = downloadManager.getAbsoluteMangaDirectory(source, manga) if (mangaDir.exists()) { for (file in mangaDir.listFiles()) {