diff --git a/app/build.gradle b/app/build.gradle index 88e27b97a0..78a3df583c 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 b75af7fb9a..814c1e3bcd 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 1aa238aef8..25742e8655 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 9cc887fd41..7d912a9611 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 cb079f1348..36febe9547 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; } + }