mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-23 07:19:13 +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
|
@Override
|
||||||
public void onItemMove(int firstPosition, int secondPosition) {
|
public void onItemMove(int firstPosition, int secondPosition) {
|
||||||
Collections.swap(_keyProfiles, firstPosition, secondPosition);
|
Collections.swap(_keyProfiles, firstPosition, secondPosition);
|
||||||
notifyItemMoved(firstPosition, secondPosition);
|
notifyItemMoved(firstPosition, secondPosition);
|
||||||
|
|
||||||
_keyProfiles.get(firstPosition).getEntry().setOrder(secondPosition);
|
// update the order of all key profiles
|
||||||
adjustOrder(secondPosition);
|
for (int i = 0; i < _keyProfiles.size(); i++) {
|
||||||
}
|
|
||||||
|
|
||||||
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++) {
|
|
||||||
_keyProfiles.get(i).getEntry().setOrder(i + 1);
|
_keyProfiles.get(i).getEntry().setOrder(i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,15 +122,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_keyProfileAdapter);
|
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_keyProfileAdapter);
|
||||||
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
||||||
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
||||||
|
|
||||||
rvKeyProfiles.setAdapter(_keyProfileAdapter);
|
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
|
@Override
|
||||||
|
@ -445,6 +437,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collections.sort(_keyProfiles, (p1, p2) -> {
|
||||||
|
return p1.getEntry().getOrder() >= p2.getEntry().getOrder() ? 1 : -1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLockIcon() {
|
private void updateLockIcon() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue