mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-04 08:08:55 +01:00 
			
		
		
		
	All chapter filters are now saved
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -386,13 +386,13 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> 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());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -39,8 +39,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
 | 
			
		||||
    private Manga manga;
 | 
			
		||||
    private Source source;
 | 
			
		||||
    private List<Chapter> chapters;
 | 
			
		||||
    private boolean onlyUnread = true;
 | 
			
		||||
    private boolean onlyDownloaded;
 | 
			
		||||
    @State boolean hasRequested;
 | 
			
		||||
 | 
			
		||||
    private PublishSubject<List<Chapter>> chaptersSubject;
 | 
			
		||||
@@ -142,10 +140,10 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
 | 
			
		||||
    private Observable<List<Chapter>> applyChapterFilters(List<Chapter> chapters) {
 | 
			
		||||
        Observable<Chapter> 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<ChaptersFragment> {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (onlyDownloaded && download.getStatus() == Download.DOWNLOADED)
 | 
			
		||||
        if (onlyDownloaded() && download.getStatus() == Download.DOWNLOADED)
 | 
			
		||||
            refreshChapters();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -238,7 +236,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
 | 
			
		||||
                }, error -> {
 | 
			
		||||
                    Timber.e(error.getMessage());
 | 
			
		||||
                }, () -> {
 | 
			
		||||
                    if (onlyDownloaded)
 | 
			
		||||
                    if (onlyDownloaded())
 | 
			
		||||
                        refreshChapters();
 | 
			
		||||
                }));
 | 
			
		||||
    }
 | 
			
		||||
@@ -254,13 +252,14 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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<ChaptersFragment> {
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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) -> {
 | 
			
		||||
 
 | 
			
		||||
@@ -109,6 +109,7 @@ public class WebtoonReader extends BaseReader {
 | 
			
		||||
            recycler.clearOnScrollListeners();
 | 
			
		||||
            adapter.setPages(pages);
 | 
			
		||||
            recycler.setAdapter(adapter);
 | 
			
		||||
            updatePageNumber();
 | 
			
		||||
            setScrollListener();
 | 
			
		||||
            observeStatus(0);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user