Skip to content

Commit d5048f4

Browse files
committed
Add sort lexicographical descendant order for notes
1 parent d7c0544 commit d5048f4

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,9 @@ protected void onCreate(Bundle savedInstanceState) {
292292
activityBinding.sortingMethod.setOnClickListener((v) -> {
293293
if (methodOfCategory.first != null) {
294294
var newMethod = methodOfCategory.second;
295-
if (newMethod == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) {
296-
newMethod = CategorySortingMethod.SORT_MODIFIED_DESC;
297-
} else {
298-
newMethod = CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC;
299-
}
295+
//Rotate for next method
296+
newMethod = CategorySortingMethod.findById(newMethod.getId() + 1);
297+
300298
final var modifyLiveData = mainViewModel.modifyCategoryOrder(methodOfCategory.first, newMethod);
301299
modifyLiveData.observe(this, (next) -> modifyLiveData.removeObservers(this));
302300
}

app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByInitials;
1717
import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByTime;
1818
import static it.niedermann.owncloud.notes.shared.model.CategorySortingMethod.SORT_MODIFIED_DESC;
19+
import static it.niedermann.owncloud.notes.shared.model.CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC;
1920
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY;
2021
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES;
2122
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT;
@@ -282,9 +283,12 @@ private List<Item> fromNotes(List<Note> noteList, @NonNull NavigationCategory se
282283
}
283284
if (sortingMethod == SORT_MODIFIED_DESC) {
284285
return fillListByTime(getApplication(), noteList);
285-
} else {
286-
return fillListByInitials(getApplication(), noteList);
287286
}
287+
List<Item> itemList = fillListByInitials(getApplication(), noteList);
288+
if(sortingMethod != SORT_LEXICOGRAPHICAL_ASC){
289+
Collections.reverse(itemList);
290+
}
291+
return itemList;
288292
}
289293

290294
@NonNull

app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
public enum CategorySortingMethod {
1010
SORT_MODIFIED_DESC(0, "MODIFIED DESC"),
11-
SORT_LEXICOGRAPHICAL_ASC(1, "TITLE COLLATE NOCASE ASC");
11+
SORT_LEXICOGRAPHICAL_ASC(1, "TITLE COLLATE NOCASE ASC"),
12+
SORT_LEXICOGRAPHICAL_DESC(2, "TITLE COLLATE NOCASE DESC");
1213

1314
private final int id;
1415
private final String title; // sorting method OrderBy for SQL
@@ -44,6 +45,12 @@ public String getTitle() {
4445
* @return the corresponding enum item with the index (ordinal)
4546
*/
4647
public static CategorySortingMethod findById(int id) {
48+
if (id < 0)
49+
id += values().length;
50+
51+
if (id >= values().length)
52+
id = id % values().length;
53+
4754
for (final var csm : values()) {
4855
if (csm.getId() == id) {
4956
return csm;

0 commit comments

Comments
 (0)