Skip to content

Commit c5a9d0b

Browse files
committed
Fix value reassgin
Signed-off-by: Kornél Szekeres <[email protected]>
1 parent 3f2161f commit c5a9d0b

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +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-
//Rotate for next method
296-
newMethod = CategorySortingMethod.findById(newMethod.getId() + 1);
297-
294+
//Rotate for next sorting method
295+
var newMethod = CategorySortingMethod.findById(methodOfCategory.second.getId() + 1);
298296
final var modifyLiveData = mainViewModel.modifyCategoryOrder(methodOfCategory.first, newMethod);
299297
modifyLiveData.observe(this, (next) -> modifyLiveData.removeObservers(this));
300298
}
@@ -622,10 +620,8 @@ public boolean onSupportNavigateUp() {
622620
* Updates sorting method icon.
623621
*/
624622
private void updateSortMethodIcon(CategorySortingMethod method) {
625-
if (method == null)
626-
method = CategorySortingMethod.SORT_MODIFIED_DESC;
627-
628-
switch (method){
623+
CategorySortingMethod newMethod = (method != null) ? method: CategorySortingMethod.SORT_MODIFIED_DESC;
624+
switch (newMethod){
629625
case SORT_MODIFIED_DESC :
630626
activityBinding.sortingMethod.setImageResource(R.drawable.modification_desc);
631627
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_alphabetically));

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ public String getTitle() {
4545
* @return the corresponding enum item with the index (ordinal)
4646
*/
4747
public static CategorySortingMethod findById(int id) {
48-
if (id < 0)
49-
id += values().length;
50-
51-
if (id >= values().length)
52-
id = id % values().length;
48+
var newId = id % values().length;
5349

5450
for (final var csm : values()) {
55-
if (csm.getId() == id) {
51+
if (csm.getId() == newId) {
5652
return csm;
5753
}
5854
}

0 commit comments

Comments
 (0)