mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-12-18 08:32:24 +03:00
Merge pull request #2487 from Kokika/Add_sort_lexicographical_descendant
Add sort lexicographical descendant for notes application
This commit is contained in:
commit
bbadb8ea31
4 changed files with 54 additions and 22 deletions
|
@ -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 {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
18
app/src/main/res/drawable/alphabetical_desc.xml
Normal file
18
app/src/main/res/drawable/alphabetical_desc.xml
Normal file
|
@ -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>
|
Loading…
Reference in a new issue