Skip to content

Commit

Permalink
Merge pull request #2487 from Kokika/Add_sort_lexicographical_descendant
Browse files Browse the repository at this point in the history
Add sort lexicographical descendant for notes application
  • Loading branch information
alperozturk96 authored Nov 29, 2024
2 parents 516c686 + 8772fbd commit bbadb8e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,8 @@ protected void onCreate(Bundle savedInstanceState) {
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));
}
Expand Down Expand Up @@ -624,18 +620,30 @@ 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));
}
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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -282,9 +283,11 @@ private List<Item> fromNotes(List<Note> noteList, @NonNull NavigationCategory se
}
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,8 +45,10 @@ public String getTitle() {
* @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;
}
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/alphabetical_desc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Notes - Android Client
~
~ SPDX-FileCopyrightText: 2018-2024 Google LLC
~ SPDX-FileCopyrightText: 2018-2024 Andy Scherzinger
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="26dp"
android:viewportWidth="26"
android:viewportHeight="26">

<path
android:fillColor="#757575"
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" />
</vector>

0 comments on commit bbadb8e

Please sign in to comment.