From 9b90ad0a3bafce24b5bfc42652508ea11510aeb6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 23 Jan 2016 22:41:54 +0100 Subject: [PATCH] save per-manga sort order --- .../tachiyomi/data/database/models/Manga.java | 16 ++++++++++++++++ .../ui/manga/chapter/ChaptersPresenter.java | 9 ++++----- 2 files changed, 20 insertions(+), 5 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 5548f69ff..1128f0b1e 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 @@ -68,6 +68,10 @@ public class Manga implements Serializable { public static final int COMPLETED = 2; public static final int LICENSED = 3; + public static final int SORT_AZ = 0; + public static final int SORT_ZA = 1; + public static final int SORT_MASK = 1; + public Manga() {} public static Manga create(String pathUrl) { @@ -120,6 +124,18 @@ public class Manga implements Serializable { } } + public void setFlags(int flag, int mask) { + chapter_flags = (chapter_flags & ~mask) | (flag & mask); + } + + public boolean sortChaptersAZ () { + return (this.chapter_flags & SORT_MASK) == SORT_AZ; + } + + public void setChapterOrder(int order) { + setFlags(order, SORT_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/ChaptersPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java index 58814af07..38051672e 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,7 +39,6 @@ public class ChaptersPresenter extends BasePresenter { private Manga manga; private Source source; private List chapters; - private boolean sortOrderAToZ = true; private boolean onlyUnread = true; private boolean onlyDownloaded; @State boolean hasRequested; @@ -142,7 +141,7 @@ public class ChaptersPresenter extends BasePresenter { if (onlyDownloaded) { observable = observable.filter(chapter -> chapter.status == Download.DOWNLOADED); } - return observable.toSortedList((chapter, chapter2) -> sortOrderAToZ ? + return observable.toSortedList((chapter, chapter2) -> getSortOrder() ? Float.compare(chapter2.chapter_number, chapter.chapter_number) : Float.compare(chapter.chapter_number, chapter2.chapter_number)); } @@ -242,8 +241,8 @@ public class ChaptersPresenter extends BasePresenter { } public void revertSortOrder() { - //TODO manga.chapter_order - sortOrderAToZ = !sortOrderAToZ; + manga.setChapterOrder(getSortOrder() ? Manga.SORT_ZA : Manga.SORT_AZ); + db.insertManga(manga).executeAsBlocking(); refreshChapters(); } @@ -259,7 +258,7 @@ public class ChaptersPresenter extends BasePresenter { } public boolean getSortOrder() { - return sortOrderAToZ; + return manga.sortChaptersAZ(); } public boolean getReadFilter() {