All chapter filters are now saved

This commit is contained in:
inorichi 2016-01-29 19:36:08 +01:00
parent f19889c222
commit c03495be94
5 changed files with 54 additions and 22 deletions

View File

@ -72,6 +72,17 @@ public class Manga implements Serializable {
public static final int SORT_ZA = 0x00000001; public static final int SORT_ZA = 0x00000001;
public static final int SORT_MASK = 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_NAME = 0x00000000;
public static final int DISPLAY_NUMBER = 0x00100000; public static final int DISPLAY_NUMBER = 0x00100000;
public static final int DISPLAY_MASK = 0x00100000; public static final int DISPLAY_MASK = 0x00100000;
@ -136,6 +147,14 @@ public class Manga implements Serializable {
setFlags(mode, DISPLAY_MASK); 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) { private void setFlags(int flag, int mask) {
chapter_flags = (chapter_flags & ~mask) | (flag & mask); chapter_flags = (chapter_flags & ~mask) | (flag & mask);
} }
@ -149,6 +168,14 @@ public class Manga implements Serializable {
return chapter_flags & DISPLAY_MASK; return chapter_flags & DISPLAY_MASK;
} }
public int getReadFilter() {
return chapter_flags & READ_MASK;
}
public int getDownloadedFilter() {
return chapter_flags & DOWNLOADED_MASK;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -386,13 +386,13 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
public void setReadFilter() { public void setReadFilter() {
if (readCb != null) { if (readCb != null) {
readCb.setChecked(getPresenter().getReadFilter()); readCb.setChecked(getPresenter().onlyUnread());
} }
} }
public void setDownloadedFilter() { public void setDownloadedFilter() {
if (downloadedCb != null) { if (downloadedCb != null) {
downloadedCb.setChecked(getPresenter().getDownloadedFilter()); downloadedCb.setChecked(getPresenter().onlyDownloaded());
} }
} }

View File

@ -39,8 +39,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
private Manga manga; private Manga manga;
private Source source; private Source source;
private List<Chapter> chapters; private List<Chapter> chapters;
private boolean onlyUnread = true;
private boolean onlyDownloaded;
@State boolean hasRequested; @State boolean hasRequested;
private PublishSubject<List<Chapter>> chaptersSubject; private PublishSubject<List<Chapter>> chaptersSubject;
@ -142,10 +140,10 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
private Observable<List<Chapter>> applyChapterFilters(List<Chapter> chapters) { private Observable<List<Chapter>> applyChapterFilters(List<Chapter> chapters) {
Observable<Chapter> observable = Observable.from(chapters) Observable<Chapter> observable = Observable.from(chapters)
.subscribeOn(Schedulers.io()); .subscribeOn(Schedulers.io());
if (onlyUnread) { if (onlyUnread()) {
observable = observable.filter(chapter -> !chapter.read); observable = observable.filter(chapter -> !chapter.read);
} }
if (onlyDownloaded) { if (onlyDownloaded()) {
observable = observable.filter(chapter -> chapter.status == Download.DOWNLOADED); observable = observable.filter(chapter -> chapter.status == Download.DOWNLOADED);
} }
return observable.toSortedList((chapter, chapter2) -> getSortOrder() ? return observable.toSortedList((chapter, chapter2) -> getSortOrder() ?
@ -182,7 +180,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
break; break;
} }
} }
if (onlyDownloaded && download.getStatus() == Download.DOWNLOADED) if (onlyDownloaded() && download.getStatus() == Download.DOWNLOADED)
refreshChapters(); refreshChapters();
} }
@ -238,7 +236,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
}, error -> { }, error -> {
Timber.e(error.getMessage()); Timber.e(error.getMessage());
}, () -> { }, () -> {
if (onlyDownloaded) if (onlyDownloaded())
refreshChapters(); refreshChapters();
})); }));
} }
@ -254,13 +252,14 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
} }
public void setReadFilter(boolean onlyUnread) { public void setReadFilter(boolean onlyUnread) {
//TODO do we need save filter for manga? manga.setReadFilter(onlyUnread ? Manga.SHOW_UNREAD : Manga.SHOW_ALL);
this.onlyUnread = onlyUnread; db.insertManga(manga).executeAsBlocking();
refreshChapters(); refreshChapters();
} }
public void setDownloadedFilter(boolean onlyDownloaded) { public void setDownloadedFilter(boolean onlyDownloaded) {
this.onlyDownloaded = onlyDownloaded; manga.setDownloadedFilter(onlyDownloaded ? Manga.SHOW_DOWNLOADED : Manga.SHOW_ALL);
db.insertManga(manga).executeAsBlocking();
refreshChapters(); refreshChapters();
} }
@ -269,18 +268,18 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
db.insertManga(manga).executeAsBlocking(); 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() { public boolean getSortOrder() {
return manga.sortChaptersAZ(); return manga.sortChaptersAZ();
} }
public boolean getReadFilter() {
return onlyUnread;
}
public boolean getDownloadedFilter() {
return onlyDownloaded;
}
public Manga getManga() { public Manga getManga() {
return manga; return manga;
} }

View File

@ -48,9 +48,14 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
} }
}); });
// Avoid to create a lot of view holders taking all the screen height, // Avoid to create a lot of view holders taking twice the screen height,
// saving memory and a possible OOM // saving memory and a possible OOM. When the first image is loaded in this holder,
container.setMinimumHeight(view.getResources().getDisplayMetrics().heightPixels); // 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); container.setOnTouchListener(touchListener);
retryButton.setOnTouchListener((v, event) -> { retryButton.setOnTouchListener((v, event) -> {

View File

@ -109,6 +109,7 @@ public class WebtoonReader extends BaseReader {
recycler.clearOnScrollListeners(); recycler.clearOnScrollListeners();
adapter.setPages(pages); adapter.setPages(pages);
recycler.setAdapter(adapter); recycler.setAdapter(adapter);
updatePageNumber();
setScrollListener(); setScrollListener();
observeStatus(0); observeStatus(0);
} }