Skip to content

Commit

Permalink
Fix value reassgin
Browse files Browse the repository at this point in the history
Signed-off-by: Kornél Szekeres <[email protected]>
  • Loading branch information
Kokika committed Nov 14, 2024
1 parent 3f2161f commit c5a9d0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,8 @@ protected void onCreate(Bundle savedInstanceState) {
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));
}
Expand Down Expand Up @@ -622,10 +620,8 @@ public boolean onSupportNavigateUp() {
* 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ public String getTitle() {
* @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;
}
}
Expand Down

0 comments on commit c5a9d0b

Please sign in to comment.