Fixed resetting order

pull/156/head
M66B 6 years ago
parent c3eab6eee0
commit e586370fb8

@ -153,7 +153,34 @@ public class FragmentOrder extends FragmentBase {
public void onPause() {
super.onPause();
if (dirty) {
if (dirty)
update(false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_sort, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_reset_order:
onMenuResetOrder();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuResetOrder() {
adapter.onReset();
dirty = false;
update(true);
}
private void update(boolean reset) {
List<EntityOrder> items = adapter.getItems();
List<Long> order = new ArrayList<>();
@ -162,23 +189,25 @@ public class FragmentOrder extends FragmentBase {
Bundle args = new Bundle();
args.putString("class", clazz);
args.putLongArray("order", Helper.toLongArray(order));
args.putBoolean("reset", reset);
args.putLongArray("ids", Helper.toLongArray(order));
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
final String clazz = args.getString("class");
final long[] order = args.getLongArray("order");
final boolean reset = args.getBoolean("reset");
final long[] ids = args.getLongArray("ids");
final DB db = DB.getInstance(context);
db.runInTransaction(new Runnable() {
@Override
public void run() {
for (int i = 0; i < order.length; i++)
for (int i = 0; i < ids.length; i++)
if (EntityAccount.class.getName().equals(clazz))
db.account().setAccountOrder(order[i], i);
db.account().setAccountOrder(ids[i], reset ? null : i);
else if (TupleFolderSort.class.getName().equals(clazz))
db.folder().setFolderOrder(order[i], i);
db.folder().setFolderOrder(ids[i], reset ? null : i);
else
throw new IllegalArgumentException("Unknown class=" + clazz);
}
@ -193,28 +222,7 @@ public class FragmentOrder extends FragmentBase {
}
}.execute(getContext(), getViewLifecycleOwner(), args, "order:set");
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_sort, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_reset_order:
onMenuResetOrder();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuResetOrder() {
adapter.onReset();
}
private ItemTouchHelper.Callback touchHelper = new ItemTouchHelper.Callback() {

Loading…
Cancel
Save