mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-30 02:05:00 -05:00
Merge pull request #53 from icewind1991/sort-order
save per-manga sort order
This commit is contained in:
commit
50306f6ea3
2 changed files with 20 additions and 5 deletions
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue