From d5048f4e92c73be8ffc6ddeaaa420317db64edff Mon Sep 17 00:00:00 2001 From: Kokika Date: Thu, 14 Nov 2024 19:45:11 +0100 Subject: [PATCH] Add sort lexicographical descendant order for notes --- .../it/niedermann/owncloud/notes/main/MainActivity.java | 8 +++----- .../it/niedermann/owncloud/notes/main/MainViewModel.java | 8 ++++++-- .../notes/shared/model/CategorySortingMethod.java | 9 ++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index 2e1e809d..093bb961 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -292,11 +292,9 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A activityBinding.sortingMethod.setOnClickListener((v) -> { if (methodOfCategory.first != null) { var newMethod = methodOfCategory.second; - if (newMethod == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) { - newMethod = CategorySortingMethod.SORT_MODIFIED_DESC; - } else { - newMethod = CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC; - } + //Rotate for next method + newMethod = CategorySortingMethod.findById(newMethod.getId() + 1); + final var modifyLiveData = mainViewModel.modifyCategoryOrder(methodOfCategory.first, newMethod); modifyLiveData.observe(this, (next) -> modifyLiveData.removeObservers(this)); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java index c1fc1cc0..6e30e461 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java @@ -16,6 +16,7 @@ import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByCate import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByInitials; import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByTime; import static it.niedermann.owncloud.notes.shared.model.CategorySortingMethod.SORT_MODIFIED_DESC; +import static it.niedermann.owncloud.notes.shared.model.CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC; import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY; import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES; import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT; @@ -282,9 +283,12 @@ public class MainViewModel extends AndroidViewModel { } if (sortingMethod == SORT_MODIFIED_DESC) { return fillListByTime(getApplication(), noteList); - } else { - return fillListByInitials(getApplication(), noteList); } + List itemList = fillListByInitials(getApplication(), noteList); + if(sortingMethod != SORT_LEXICOGRAPHICAL_ASC){ + Collections.reverse(itemList); + } + return itemList; } @NonNull diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java index f887f08f..d0788aaa 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java @@ -8,7 +8,8 @@ package it.niedermann.owncloud.notes.shared.model; public enum CategorySortingMethod { SORT_MODIFIED_DESC(0, "MODIFIED DESC"), - SORT_LEXICOGRAPHICAL_ASC(1, "TITLE COLLATE NOCASE ASC"); + SORT_LEXICOGRAPHICAL_ASC(1, "TITLE COLLATE NOCASE ASC"), + SORT_LEXICOGRAPHICAL_DESC(2, "TITLE COLLATE NOCASE DESC"); private final int id; private final String title; // sorting method OrderBy for SQL @@ -44,6 +45,12 @@ public enum CategorySortingMethod { * @return the corresponding enum item with the index (ordinal) */ public static CategorySortingMethod findById(int id) { + if (id < 0) + id += values().length; + + if (id >= values().length) + id = id % values().length; + for (final var csm : values()) { if (csm.getId() == id) { return csm;