Exclude manga from unknown sources from the library

This commit is contained in:
len 2016-05-22 23:40:44 +02:00
parent af0cf9e52d
commit f629db3c10

View file

@ -129,10 +129,8 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
return db.getLibraryMangas().asRxObservable() return db.getLibraryMangas().asRxObservable()
.flatMap { mangas -> .flatMap { mangas ->
Observable.from(mangas) Observable.from(mangas)
.filter { // Filter library by options
// Filter library by options .filter { filterManga(it) }
filterLibrary(it)
}
.groupBy { it.category } .groupBy { it.category }
.flatMap { group -> group.toList().map { Pair(group.key, it) } } .flatMap { group -> group.toList().map { Pair(group.key, it) } }
.toMap({ it.first }, { it.second }) .toMap({ it.first }, { it.second })
@ -156,12 +154,15 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
} }
/** /**
* Filter library by preference * Filters an entry of the library.
* *
* @param manga from library * @param manga a favorite manga from the database.
* @return filter status * @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 prefFilterDownloaded = preferences.filterDownloaded().getOrDefault()
val prefFilterUnread = preferences.filterUnread().getOrDefault() val prefFilterUnread = preferences.filterUnread().getOrDefault()
@ -178,7 +179,7 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
} }
if (prefFilterDownloaded) { if (prefFilterDownloaded) {
val mangaDir = downloadManager.getAbsoluteMangaDirectory(sourceManager.get(manga.source)!!, manga) val mangaDir = downloadManager.getAbsoluteMangaDirectory(source, manga)
if (mangaDir.exists()) { if (mangaDir.exists()) {
for (file in mangaDir.listFiles()) { for (file in mangaDir.listFiles()) {