浏览代码

Merge pull request #53 from icewind1991/sort-order

save per-manga sort order
inorichi 9 年之前
父节点
当前提交
50306f6ea3

+ 16 - 0
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;

+ 4 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java

@@ -39,7 +39,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
     private Manga manga;
     private Source source;
     private List<Chapter> chapters;
-    private boolean sortOrderAToZ = true;
     private boolean onlyUnread = true;
     private boolean onlyDownloaded;
     @State boolean hasRequested;
@@ -142,7 +141,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
         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<ChaptersFragment> {
     }
 
     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<ChaptersFragment> {
     }
 
     public boolean getSortOrder() {
-        return sortOrderAToZ;
+        return manga.sortChaptersAZ();
     }
 
     public boolean getReadFilter() {