From 6b8ccbe01b0bc6532b3525aa4dbd793e5d05fd8d Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 2 Dec 2015 14:56:47 +0100 Subject: [PATCH] Add filter by downloaded chapter. When searching manga by URL, also check the source --- app/build.gradle | 2 +- .../data/database/DatabaseHelper.java | 6 ++--- .../ui/catalogue/CataloguePresenter.java | 2 +- .../ui/manga/chapter/ChaptersFragment.java | 13 ++++++++++- .../ui/manga/chapter/ChaptersPresenter.java | 22 ++++++++++++++++++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 88e27b97a..78a3df583 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -85,7 +85,7 @@ dependencies { compile "frankiesardo:icepick:$ICEPICK_VERSION" provided "frankiesardo:icepick-processor:$ICEPICK_VERSION" compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4' - compile 'eu.davidea:flexible-adapter:4.0.1@aar' + compile 'eu.davidea:flexible-adapter:4.1.0@aar' compile "com.google.dagger:dagger:$DAGGER_VERSION" apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION" diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java index b75af7fb9..814c1e3bc 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java @@ -108,13 +108,13 @@ public class DatabaseHelper { .prepare(); } - public PreparedGetListOfObjects getManga(String url) { + public PreparedGetListOfObjects getManga(String url, int sourceId) { return db.get() .listOfObjects(Manga.class) .withQuery(Query.builder() .table(MangaTable.TABLE) - .where(MangaTable.COLUMN_URL + "=?") - .whereArgs(url) + .where(MangaTable.COLUMN_URL + "=? AND " + MangaTable.COLUMN_SOURCE + "=?") + .whereArgs(url, sourceId) .build()) .prepare(); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java index 1aa238aef..25742e865 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java @@ -137,7 +137,7 @@ public class CataloguePresenter extends BasePresenter { } private Manga networkToLocalManga(Manga networkManga) { - List dbResult = db.getManga(networkManga.url).executeAsBlocking(); + List dbResult = db.getManga(networkManga.url, selectedSource.getSourceId()).executeAsBlocking(); Manga localManga = !dbResult.isEmpty() ? dbResult.get(0) : null; if (localManga == null) { PutResult result = db.insertManga(networkManga).executeAsBlocking(); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersFragment.java index 9cc887fd4..7d912a961 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersFragment.java @@ -79,11 +79,15 @@ public class ChaptersFragment extends BaseRxFragment implemen // Set initial values setReadFilter(); + setDownloadedFilter(); setSortIcon(); // Init listeners swipeRefresh.setOnRefreshListener(this::onFetchChapters); - readCb.setOnCheckedChangeListener((arg, isChecked) -> getPresenter().setReadFilter(isChecked)); + readCb.setOnCheckedChangeListener((arg, isChecked) -> + getPresenter().setReadFilter(isChecked)); + downloadedCb.setOnCheckedChangeListener((v, isChecked) -> + getPresenter().setDownloadedFilter(isChecked)); sortBtn.setOnClickListener(v -> { getPresenter().revertSortOrder(); setSortIcon(); @@ -294,4 +298,11 @@ public class ChaptersFragment extends BaseRxFragment implemen readCb.setChecked(getPresenter().getReadFilter()); } } + + public void setDownloadedFilter() { + if (downloadedCb != null) { + downloadedCb.setChecked(getPresenter().getDownloadedFilter()); + } + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java index cb079f134..36febe954 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java @@ -37,6 +37,7 @@ public class ChaptersPresenter extends BasePresenter { private boolean isCatalogueManga; private boolean sortOrderAToZ = true; private boolean onlyUnread = true; + private boolean onlyDownloaded; private static final int DB_CHAPTERS = 1; private static final int FETCH_CHAPTERS = 2; @@ -98,6 +99,7 @@ public class ChaptersPresenter extends BasePresenter { private Observable> getDbChaptersObs() { return db.getChapters(manga.id, sortOrderAToZ, onlyUnread).createObservable() .doOnNext(this::checkChaptersStatus) + .flatMap(this::applyDownloadedFilter) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } @@ -152,7 +154,6 @@ public class ChaptersPresenter extends BasePresenter { })); } - private void checkChaptersStatus(List chapters) { for (Chapter chapter : chapters) { checkIsChapterDownloaded(chapter); @@ -174,6 +175,15 @@ public class ChaptersPresenter extends BasePresenter { } } + private Observable> applyDownloadedFilter(List chapters) { + if (onlyDownloaded) + return Observable.from(chapters) + .filter(chapter -> chapter.status == Download.DOWNLOADED) + .toList(); + + return Observable.just(chapters); + } + public void revertSortOrder() { //TODO manga.chapter_order sortOrderAToZ = !sortOrderAToZ; @@ -186,6 +196,11 @@ public class ChaptersPresenter extends BasePresenter { start(DB_CHAPTERS); } + public void setDownloadedFilter(boolean onlyDownloaded) { + this.onlyDownloaded = onlyDownloaded; + start(DB_CHAPTERS); + } + public void setIsCatalogueManga(boolean value) { isCatalogueManga = value; } @@ -198,7 +213,12 @@ public class ChaptersPresenter extends BasePresenter { return onlyUnread; } + public boolean getDownloadedFilter() { + return onlyDownloaded; + } + public Manga getManga() { return manga; } + }