From d5048f4e92c73be8ffc6ddeaaa420317db64edff Mon Sep 17 00:00:00 2001 From: Kokika Date: Thu, 14 Nov 2024 19:45:11 +0100 Subject: [PATCH 1/5] 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 2e1e809d8..093bb9615 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 @@ protected void onCreate(Bundle savedInstanceState) { 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 c1fc1cc0c..6e30e4612 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.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 @@ private List fromNotes(List noteList, @NonNull NavigationCategory se } 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 f887f08fa..d0788aaa2 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 @@ 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 String getTitle() { * @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; From 687d874689ac4db1bc5328a5b1c86173cb7e441f Mon Sep 17 00:00:00 2001 From: Kokika Date: Thu, 14 Nov 2024 22:54:49 +0100 Subject: [PATCH 2/5] Add icon for lexicographical descendant sorting --- .../owncloud/notes/main/MainActivity.java | 35 ++++++++++++------- .../main/res/drawable/alphabetical_desc.xml | 18 ++++++++++ 2 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/alphabetical_desc.xml 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 093bb9615..bd5525de3 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 @@ -622,18 +622,29 @@ public boolean onSupportNavigateUp() { * Updates sorting method icon. */ private void updateSortMethodIcon(CategorySortingMethod method) { - if (method == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) { - activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_asc); - activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_last_modified)); - if (SDK_INT >= O) { - activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_last_modified)); - } - } else { - activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc); - activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically)); - if (SDK_INT >= O) { - activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically)); - } + switch (method){ + case SORT_MODIFIED_DESC : + activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc); + activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically)); + if (SDK_INT >= O) { + activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically)); + } + break; + case SORT_LEXICOGRAPHICAL_ASC: + activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_asc); + activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically)); + if (SDK_INT >= O) { + activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically)); + } + break; + case SORT_LEXICOGRAPHICAL_DESC: + activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_desc); + activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_last_modified)); + if (SDK_INT >= O) { + activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_last_modified)); + } + break; + default: throw new IllegalStateException("Unknown method: " + method.name()); } } diff --git a/app/src/main/res/drawable/alphabetical_desc.xml b/app/src/main/res/drawable/alphabetical_desc.xml new file mode 100644 index 000000000..c97617a74 --- /dev/null +++ b/app/src/main/res/drawable/alphabetical_desc.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file From 3f2161fe966013369bf6fd43d67d57650062a3b1 Mon Sep 17 00:00:00 2001 From: Kokika Date: Thu, 14 Nov 2024 23:10:13 +0100 Subject: [PATCH 3/5] Update Sort Method Icon null reference fix --- .../java/it/niedermann/owncloud/notes/main/MainActivity.java | 3 +++ 1 file changed, 3 insertions(+) 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 bd5525de3..7d97be8f9 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 @@ -622,6 +622,9 @@ public boolean onSupportNavigateUp() { * Updates sorting method icon. */ private void updateSortMethodIcon(CategorySortingMethod method) { + if (method == null) + method = CategorySortingMethod.SORT_MODIFIED_DESC; + switch (method){ case SORT_MODIFIED_DESC : activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc); From c5a9d0b8627477e05ac30f426b2a636b7accd9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korn=C3=A9l=20Szekeres?= Date: Thu, 14 Nov 2024 23:26:00 +0100 Subject: [PATCH 4/5] Fix value reassgin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kornél Szekeres --- .../niedermann/owncloud/notes/main/MainActivity.java | 12 ++++-------- .../notes/shared/model/CategorySortingMethod.java | 8 ++------ 2 files changed, 6 insertions(+), 14 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 7d97be8f9..f06641543 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 @@ -291,10 +291,8 @@ protected void onCreate(Bundle savedInstanceState) { updateSortMethodIcon(methodOfCategory.second); activityBinding.sortingMethod.setOnClickListener((v) -> { if (methodOfCategory.first != null) { - var newMethod = methodOfCategory.second; - //Rotate for next method - newMethod = CategorySortingMethod.findById(newMethod.getId() + 1); - + //Rotate for next sorting method + var newMethod = CategorySortingMethod.findById(methodOfCategory.second.getId() + 1); final var modifyLiveData = mainViewModel.modifyCategoryOrder(methodOfCategory.first, newMethod); modifyLiveData.observe(this, (next) -> modifyLiveData.removeObservers(this)); } @@ -622,10 +620,8 @@ public boolean onSupportNavigateUp() { * Updates sorting method icon. */ private void updateSortMethodIcon(CategorySortingMethod method) { - if (method == null) - method = CategorySortingMethod.SORT_MODIFIED_DESC; - - switch (method){ + CategorySortingMethod newMethod = (method != null) ? method: CategorySortingMethod.SORT_MODIFIED_DESC; + switch (newMethod){ case SORT_MODIFIED_DESC : activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc); activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically)); 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 d0788aaa2..9285e7208 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 @@ -45,14 +45,10 @@ public String getTitle() { * @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; + var newId = id % values().length; for (final var csm : values()) { - if (csm.getId() == id) { + if (csm.getId() == newId) { return csm; } } From 6cccf496d51a2d16fed5a3cca4fd0b6cb1abe37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korn=C3=A9l=20Szekeres?= Date: Sat, 16 Nov 2024 10:53:01 +0100 Subject: [PATCH 5/5] Fix section item position at lexical asc ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kornél Szekeres --- .../it/niedermann/owncloud/notes/main/MainViewModel.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 6e30e4612..96776b2c1 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 @@ -284,11 +284,10 @@ private List fromNotes(List noteList, @NonNull NavigationCategory se if (sortingMethod == SORT_MODIFIED_DESC) { return fillListByTime(getApplication(), noteList); } - List itemList = fillListByInitials(getApplication(), noteList); if(sortingMethod != SORT_LEXICOGRAPHICAL_ASC){ - Collections.reverse(itemList); + Collections.reverse(noteList); } - return itemList; + return fillListByInitials(getApplication(), noteList); } @NonNull