Skip to content

Commit bbadb8e

Browse files
Merge pull request #2487 from Kokika/Add_sort_lexicographical_descendant
Add sort lexicographical descendant for notes application
2 parents 516c686 + 8772fbd commit bbadb8e

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,8 @@ protected void onCreate(Bundle savedInstanceState) {
291291
updateSortMethodIcon(methodOfCategory.second);
292292
activityBinding.sortingMethod.setOnClickListener((v) -> {
293293
if (methodOfCategory.first != null) {
294-
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-
}
294+
//Rotate for next sorting method
295+
var newMethod = CategorySortingMethod.findById(methodOfCategory.second.getId() + 1);
300296
final var modifyLiveData = mainViewModel.modifyCategoryOrder(methodOfCategory.first, newMethod);
301297
modifyLiveData.observe(this, (next) -> modifyLiveData.removeObservers(this));
302298
}
@@ -624,18 +620,30 @@ public boolean onSupportNavigateUp() {
624620
* Updates sorting method icon.
625621
*/
626622
private void updateSortMethodIcon(CategorySortingMethod method) {
627-
if (method == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) {
628-
activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_asc);
629-
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_last_modified));
630-
if (SDK_INT >= O) {
631-
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_last_modified));
632-
}
633-
} else {
634-
activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc);
635-
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));
636-
if (SDK_INT >= O) {
637-
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically));
638-
}
623+
CategorySortingMethod newMethod = (method != null) ? method: CategorySortingMethod.SORT_MODIFIED_DESC;
624+
switch (newMethod){
625+
case SORT_MODIFIED_DESC :
626+
activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc);
627+
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));
628+
if (SDK_INT >= O) {
629+
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically));
630+
}
631+
break;
632+
case SORT_LEXICOGRAPHICAL_ASC:
633+
activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_asc);
634+
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));
635+
if (SDK_INT >= O) {
636+
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_alphabetically));
637+
}
638+
break;
639+
case SORT_LEXICOGRAPHICAL_DESC:
640+
activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_desc);
641+
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_last_modified));
642+
if (SDK_INT >= O) {
643+
activityBinding.sortingMethod.setTooltipText(getString(R.string.sort_last_modified));
644+
}
645+
break;
646+
default: throw new IllegalStateException("Unknown method: " + method.name());
639647
}
640648
}
641649

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

Lines changed: 5 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,11 @@ 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+
if(sortingMethod != SORT_LEXICOGRAPHICAL_ASC){
288+
Collections.reverse(noteList);
289+
}
290+
return fillListByInitials(getApplication(), noteList);
288291
}
289292

290293
@NonNull

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

Lines changed: 5 additions & 2 deletions
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,8 +45,10 @@ public String getTitle() {
4445
* @return the corresponding enum item with the index (ordinal)
4546
*/
4647
public static CategorySortingMethod findById(int id) {
48+
var newId = id % values().length;
49+
4750
for (final var csm : values()) {
48-
if (csm.getId() == id) {
51+
if (csm.getId() == newId) {
4952
return csm;
5053
}
5154
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Nextcloud Notes - Android Client
4+
~
5+
~ SPDX-FileCopyrightText: 2018-2024 Google LLC
6+
~ SPDX-FileCopyrightText: 2018-2024 Andy Scherzinger
7+
~ SPDX-License-Identifier: Apache-2.0
8+
-->
9+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
10+
android:width="26dp"
11+
android:height="26dp"
12+
android:viewportWidth="26"
13+
android:viewportHeight="26">
14+
15+
<path
16+
android:fillColor="#757575"
17+
android:pathData="M 20.401 13.623 L 18.877 13.621 L 18.868 20.218 L 17.228 18.57 L 16.145 19.651 L 19.627 23.145 L 23.12 19.663 L 22.039 18.58 L 20.392 20.219 Z M 15.034 1.85 L 15.034 3.104 L 10.691 9.337 L 10.691 9.412 L 15.1 9.412 L 15.1 11.209 L 7.847 11.209 L 7.847 10.03 L 12.292 3.695 L 12.292 3.638 L 8.268 3.638 L 8.268 1.85 Z M 13.051 12.122 L 15.981 21.48 L 13.678 21.48 L 12.949 18.952 L 10.244 18.952 L 9.571 21.48 L 7.352 21.48 L 10.244 12.122 Z M 12.64 17.437 L 12.05 15.454 L 11.807 14.545 L 11.573 13.646 L 11.545 13.646 L 11.339 14.555 L 11.114 15.472 L 10.553 17.437 Z" />
18+
</vector>

0 commit comments

Comments
 (0)