mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 06:49:12 +00:00
Fix key profile sorting and simplify its logic a bit
This commit is contained in:
parent
74536dbda6
commit
277d76e467
2 changed files with 6 additions and 26 deletions
|
@ -41,29 +41,13 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
|||
|
||||
}
|
||||
|
||||
private void remove(int position) {
|
||||
_keyProfiles.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemMove(int firstPosition, int secondPosition) {
|
||||
Collections.swap(_keyProfiles, firstPosition, secondPosition);
|
||||
notifyItemMoved(firstPosition, secondPosition);
|
||||
|
||||
_keyProfiles.get(firstPosition).getEntry().setOrder(secondPosition);
|
||||
adjustOrder(secondPosition);
|
||||
}
|
||||
|
||||
private void adjustOrder(int startPosition) {
|
||||
Comparator<KeyProfile> comparator = new Comparator<KeyProfile>() {
|
||||
@Override
|
||||
public int compare(KeyProfile keyProfile, KeyProfile t1) {
|
||||
return keyProfile.getEntry().getOrder() - t1.getEntry().getOrder();
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = startPosition; i < _keyProfiles.size(); i++) {
|
||||
// update the order of all key profiles
|
||||
for (int i = 0; i < _keyProfiles.size(); i++) {
|
||||
_keyProfiles.get(i).getEntry().setOrder(i + 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,15 +122,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_keyProfileAdapter);
|
||||
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
||||
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
||||
|
||||
rvKeyProfiles.setAdapter(_keyProfileAdapter);
|
||||
Comparator<KeyProfile> comparator = new Comparator<KeyProfile>() {
|
||||
@Override
|
||||
public int compare(KeyProfile keyProfile, KeyProfile t1) {
|
||||
return keyProfile.getEntry().getOrder() - t1.getEntry().getOrder();
|
||||
}
|
||||
};
|
||||
Collections.sort(_keyProfiles, comparator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -445,6 +437,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Collections.sort(_keyProfiles, (p1, p2) -> {
|
||||
return p1.getEntry().getOrder() >= p2.getEntry().getOrder() ? 1 : -1;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateLockIcon() {
|
||||
|
|
Loading…
Add table
Reference in a new issue