Merge pull request #53 from icewind1991/sort-order

save per-manga sort order
This commit is contained in:
inorichi 2016-01-24 00:10:02 +01:00
commit 50306f6ea3
2 changed files with 20 additions and 5 deletions

View file

@ -68,6 +68,10 @@ public class Manga implements Serializable {
public static final int COMPLETED = 2; public static final int COMPLETED = 2;
public static final int LICENSED = 3; 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 Manga() {}
public static Manga create(String pathUrl) { 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 @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View file

@ -39,7 +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 sortOrderAToZ = true;
private boolean onlyUnread = true; private boolean onlyUnread = true;
private boolean onlyDownloaded; private boolean onlyDownloaded;
@State boolean hasRequested; @State boolean hasRequested;
@ -142,7 +141,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
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) -> sortOrderAToZ ? return observable.toSortedList((chapter, chapter2) -> getSortOrder() ?
Float.compare(chapter2.chapter_number, chapter.chapter_number) : Float.compare(chapter2.chapter_number, chapter.chapter_number) :
Float.compare(chapter.chapter_number, chapter2.chapter_number)); Float.compare(chapter.chapter_number, chapter2.chapter_number));
} }
@ -242,8 +241,8 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
} }
public void revertSortOrder() { public void revertSortOrder() {
//TODO manga.chapter_order manga.setChapterOrder(getSortOrder() ? Manga.SORT_ZA : Manga.SORT_AZ);
sortOrderAToZ = !sortOrderAToZ; db.insertManga(manga).executeAsBlocking();
refreshChapters(); refreshChapters();
} }
@ -259,7 +258,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
} }
public boolean getSortOrder() { public boolean getSortOrder() {
return sortOrderAToZ; return manga.sortChaptersAZ();
} }
public boolean getReadFilter() { public boolean getReadFilter() {