mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-12-18 16:42:17 +03:00
Add sort lexicographical descendant order for notes
This commit is contained in:
parent
d7c054436a
commit
d5048f4e92
3 changed files with 17 additions and 8 deletions
|
@ -292,11 +292,9 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
|
||||||
activityBinding.sortingMethod.setOnClickListener((v) -> {
|
activityBinding.sortingMethod.setOnClickListener((v) -> {
|
||||||
if (methodOfCategory.first != null) {
|
if (methodOfCategory.first != null) {
|
||||||
var newMethod = methodOfCategory.second;
|
var newMethod = methodOfCategory.second;
|
||||||
if (newMethod == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) {
|
//Rotate for next method
|
||||||
newMethod = CategorySortingMethod.SORT_MODIFIED_DESC;
|
newMethod = CategorySortingMethod.findById(newMethod.getId() + 1);
|
||||||
} else {
|
|
||||||
newMethod = CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC;
|
|
||||||
}
|
|
||||||
final var modifyLiveData = mainViewModel.modifyCategoryOrder(methodOfCategory.first, newMethod);
|
final var modifyLiveData = mainViewModel.modifyCategoryOrder(methodOfCategory.first, newMethod);
|
||||||
modifyLiveData.observe(this, (next) -> modifyLiveData.removeObservers(this));
|
modifyLiveData.observe(this, (next) -> modifyLiveData.removeObservers(this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.fillListByInitials;
|
||||||
import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByTime;
|
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_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.DEFAULT_CATEGORY;
|
||||||
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES;
|
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES;
|
||||||
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT;
|
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT;
|
||||||
|
@ -282,9 +283,12 @@ public class MainViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
if (sortingMethod == SORT_MODIFIED_DESC) {
|
if (sortingMethod == SORT_MODIFIED_DESC) {
|
||||||
return fillListByTime(getApplication(), noteList);
|
return fillListByTime(getApplication(), noteList);
|
||||||
} else {
|
|
||||||
return fillListByInitials(getApplication(), noteList);
|
|
||||||
}
|
}
|
||||||
|
List<Item> itemList = fillListByInitials(getApplication(), noteList);
|
||||||
|
if(sortingMethod != SORT_LEXICOGRAPHICAL_ASC){
|
||||||
|
Collections.reverse(itemList);
|
||||||
|
}
|
||||||
|
return itemList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
@ -8,7 +8,8 @@ package it.niedermann.owncloud.notes.shared.model;
|
||||||
|
|
||||||
public enum CategorySortingMethod {
|
public enum CategorySortingMethod {
|
||||||
SORT_MODIFIED_DESC(0, "MODIFIED DESC"),
|
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 int id;
|
||||||
private final String title; // sorting method OrderBy for SQL
|
private final String title; // sorting method OrderBy for SQL
|
||||||
|
@ -44,6 +45,12 @@ public enum CategorySortingMethod {
|
||||||
* @return the corresponding enum item with the index (ordinal)
|
* @return the corresponding enum item with the index (ordinal)
|
||||||
*/
|
*/
|
||||||
public static CategorySortingMethod findById(int id) {
|
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()) {
|
for (final var csm : values()) {
|
||||||
if (csm.getId() == id) {
|
if (csm.getId() == id) {
|
||||||
return csm;
|
return csm;
|
||||||
|
|
Loading…
Reference in a new issue