MCPcopy Create free account
hub / github.com/M66B/FairEmail / update

Method update

app/src/main/java/eu/faircode/email/FragmentOrder.java:181–225  ·  view source on GitHub ↗
(boolean reset)

Source from the content-addressed store, hash-verified

179 }
180
181 private void update(boolean reset) {
182 List<EntityOrder> items = adapter.getItems();
183
184 List<Long> order = new ArrayList<>();
185 for (int i = 0; i < items.size(); i++)
186 order.add(items.get(i).getSortId());
187
188 Bundle args = new Bundle();
189 args.putString("class", clazz);
190 args.putBoolean("reset", reset);
191 args.putLongArray("ids", Helper.toLongArray(order));
192
193 new SimpleTask<Void>() {
194 @Override
195 protected Void onExecute(Context context, Bundle args) {
196 final String clazz = args.getString("class");
197 final boolean reset = args.getBoolean("reset");
198 final long[] ids = args.getLongArray("ids");
199
200 DB db = DB.getInstance(context);
201 try {
202 db.beginTransaction();
203
204 for (int i = 0; i < ids.length; i++)
205 if (EntityAccount.class.getName().equals(clazz))
206 db.account().setAccountOrder(ids[i], reset ? null : i);
207 else if (TupleFolderSort.class.getName().equals(clazz))
208 db.folder().setFolderOrder(ids[i], reset ? null : i);
209 else
210 throw new IllegalArgumentException("Unknown class=" + clazz);
211
212 db.setTransactionSuccessful();
213 } finally {
214 db.endTransaction();
215 }
216
217 return null;
218 }
219
220 @Override
221 protected void onException(Bundle args, Throwable ex) {
222 Log.unexpectedError(getParentFragmentManager(), ex);
223 }
224 }.execute(this, args, "order:set");
225 }
226
227 private ItemTouchHelper.Callback touchHelper = new ItemTouchHelper.Callback() {
228 @Override

Callers 2

onPauseMethod · 0.95
onMenuResetOrderMethod · 0.95

Calls 7

toLongArrayMethod · 0.95
sizeMethod · 0.65
getItemsMethod · 0.45
addMethod · 0.45
getSortIdMethod · 0.45
getMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected