From c03495be94483d201f2ca93f6cb183dbd6c76714 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 29 Jan 2016 19:36:08 +0100 Subject: [PATCH] All chapter filters are now saved --- .../tachiyomi/data/database/models/Manga.java | 27 +++++++++++++++ .../ui/manga/chapter/ChaptersFragment.java | 4 +-- .../ui/manga/chapter/ChaptersPresenter.java | 33 +++++++++---------- .../reader/viewer/webtoon/WebtoonHolder.java | 11 +++++-- .../reader/viewer/webtoon/WebtoonReader.java | 1 + 5 files changed, 54 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java index a8acba4994..d64f4b1083 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java @@ -72,6 +72,17 @@ public class Manga implements Serializable { public static final int SORT_ZA = 0x00000001; public static final int SORT_MASK = 0x00000001; + public static final int SHOW_UNREAD = 0x00000002; + public static final int SHOW_READ = 0x00000004; + public static final int READ_MASK = 0x00000006; + + public static final int SHOW_DOWNLOADED = 0x00000008; + public static final int SHOW_NOT_DOWNLOADED = 0x00000010; + public static final int DOWNLOADED_MASK = 0x00000018; + + // Generic filter that does not filter anything + public static final int SHOW_ALL = 0x00000000; + public static final int DISPLAY_NAME = 0x00000000; public static final int DISPLAY_NUMBER = 0x00100000; public static final int DISPLAY_MASK = 0x00100000; @@ -136,6 +147,14 @@ public class Manga implements Serializable { setFlags(mode, DISPLAY_MASK); } + public void setReadFilter(int filter) { + setFlags(filter, READ_MASK); + } + + public void setDownloadedFilter(int filter) { + setFlags(filter, DOWNLOADED_MASK); + } + private void setFlags(int flag, int mask) { chapter_flags = (chapter_flags & ~mask) | (flag & mask); } @@ -149,6 +168,14 @@ public class Manga implements Serializable { return chapter_flags & DISPLAY_MASK; } + public int getReadFilter() { + return chapter_flags & READ_MASK; + } + + public int getDownloadedFilter() { + return chapter_flags & DOWNLOADED_MASK; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java index 682aa34a50..1b7534d70b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java @@ -386,13 +386,13 @@ public class ChaptersFragment extends BaseRxFragment implemen public void setReadFilter() { if (readCb != null) { - readCb.setChecked(getPresenter().getReadFilter()); + readCb.setChecked(getPresenter().onlyUnread()); } } public void setDownloadedFilter() { if (downloadedCb != null) { - downloadedCb.setChecked(getPresenter().getDownloadedFilter()); + downloadedCb.setChecked(getPresenter().onlyDownloaded()); } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java index e981ec0e7b..e5938e0a8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java @@ -39,8 +39,6 @@ public class ChaptersPresenter extends BasePresenter { private Manga manga; private Source source; private List chapters; - private boolean onlyUnread = true; - private boolean onlyDownloaded; @State boolean hasRequested; private PublishSubject> chaptersSubject; @@ -142,10 +140,10 @@ public class ChaptersPresenter extends BasePresenter { private Observable> applyChapterFilters(List chapters) { Observable observable = Observable.from(chapters) .subscribeOn(Schedulers.io()); - if (onlyUnread) { + if (onlyUnread()) { observable = observable.filter(chapter -> !chapter.read); } - if (onlyDownloaded) { + if (onlyDownloaded()) { observable = observable.filter(chapter -> chapter.status == Download.DOWNLOADED); } return observable.toSortedList((chapter, chapter2) -> getSortOrder() ? @@ -182,7 +180,7 @@ public class ChaptersPresenter extends BasePresenter { break; } } - if (onlyDownloaded && download.getStatus() == Download.DOWNLOADED) + if (onlyDownloaded() && download.getStatus() == Download.DOWNLOADED) refreshChapters(); } @@ -238,7 +236,7 @@ public class ChaptersPresenter extends BasePresenter { }, error -> { Timber.e(error.getMessage()); }, () -> { - if (onlyDownloaded) + if (onlyDownloaded()) refreshChapters(); })); } @@ -254,13 +252,14 @@ public class ChaptersPresenter extends BasePresenter { } public void setReadFilter(boolean onlyUnread) { - //TODO do we need save filter for manga? - this.onlyUnread = onlyUnread; + manga.setReadFilter(onlyUnread ? Manga.SHOW_UNREAD : Manga.SHOW_ALL); + db.insertManga(manga).executeAsBlocking(); refreshChapters(); } public void setDownloadedFilter(boolean onlyDownloaded) { - this.onlyDownloaded = onlyDownloaded; + manga.setDownloadedFilter(onlyDownloaded ? Manga.SHOW_DOWNLOADED : Manga.SHOW_ALL); + db.insertManga(manga).executeAsBlocking(); refreshChapters(); } @@ -269,18 +268,18 @@ public class ChaptersPresenter extends BasePresenter { db.insertManga(manga).executeAsBlocking(); } + public boolean onlyDownloaded() { + return manga.getDownloadedFilter() == Manga.SHOW_DOWNLOADED; + } + + public boolean onlyUnread() { + return manga.getReadFilter() == Manga.SHOW_UNREAD; + } + public boolean getSortOrder() { return manga.sortChaptersAZ(); } - public boolean getReadFilter() { - return onlyUnread; - } - - public boolean getDownloadedFilter() { - return onlyDownloaded; - } - public Manga getManga() { return manga; } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java index 0ed8ba700d..fdc90ebba1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java @@ -48,9 +48,14 @@ public class WebtoonHolder extends RecyclerView.ViewHolder { } }); - // Avoid to create a lot of view holders taking all the screen height, - // saving memory and a possible OOM - container.setMinimumHeight(view.getResources().getDisplayMetrics().heightPixels); + // Avoid to create a lot of view holders taking twice the screen height, + // saving memory and a possible OOM. When the first image is loaded in this holder, + // the minimum size will be removed. + // Doing this we get sequential holder instantiation. + container.setMinimumHeight(view.getResources().getDisplayMetrics().heightPixels * 2); + + // Leave some space between progress bars + progressBar.setMinimumHeight(300); container.setOnTouchListener(touchListener); retryButton.setOnTouchListener((v, event) -> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java index c59d93a615..cdc574d046 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java @@ -109,6 +109,7 @@ public class WebtoonReader extends BaseReader { recycler.clearOnScrollListeners(); adapter.setPages(pages); recycler.setAdapter(adapter); + updatePageNumber(); setScrollListener(); observeStatus(0); }