From c5a9d0b8627477e05ac30f426b2a636b7accd9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korn=C3=A9l=20Szekeres?= Date: Thu, 14 Nov 2024 23:26:00 +0100 Subject: [PATCH] Fix value reassgin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kornél Szekeres --- .../niedermann/owncloud/notes/main/MainActivity.java | 12 ++++-------- .../notes/shared/model/CategorySortingMethod.java | 8 ++------ 2 files changed, 6 insertions(+), 14 deletions(-) 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 7d97be8f..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,10 +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; - //Rotate for next method - newMethod = CategorySortingMethod.findById(newMethod.getId() + 1); - + //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)); } @@ -622,10 +620,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A * Updates sorting method icon. */ private void updateSortMethodIcon(CategorySortingMethod method) { - if (method == null) - method = CategorySortingMethod.SORT_MODIFIED_DESC; - - switch (method){ + 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)); 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 d0788aaa..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 @@ -45,14 +45,10 @@ public enum CategorySortingMethod { * @return the corresponding enum item with the index (ordinal) */ public static CategorySortingMethod findById(int id) { - if (id < 0) - id += values().length; - - if (id >= values().length) - id = id % values().length; + var newId = id % values().length; for (final var csm : values()) { - if (csm.getId() == id) { + if (csm.getId() == newId) { return csm; } }