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..f0664154 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,12 +291,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A updateSortMethodIcon(methodOfCategory.second); 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 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)); } @@ -624,18 +620,30 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A * 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)); - } + 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)); + 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/java/it/niedermann/owncloud/notes/main/MainViewModel.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainViewModel.java index c1fc1cc0..96776b2c 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,11 @@ public class MainViewModel extends AndroidViewModel { } if (sortingMethod == SORT_MODIFIED_DESC) { return fillListByTime(getApplication(), noteList); - } else { - return fillListByInitials(getApplication(), noteList); } + if(sortingMethod != SORT_LEXICOGRAPHICAL_ASC){ + Collections.reverse(noteList); + } + return fillListByInitials(getApplication(), noteList); } @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..9285e720 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,8 +45,10 @@ public enum CategorySortingMethod { * @return the corresponding enum item with the index (ordinal) */ public static CategorySortingMethod findById(int id) { + var newId = id % values().length; + for (final var csm : values()) { - if (csm.getId() == id) { + if (csm.getId() == newId) { return csm; } } 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 00000000..c97617a7 --- /dev/null +++ b/app/src/main/res/drawable/alphabetical_desc.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file