|
58 | 58 | import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem; |
59 | 59 | import com.magicmicky.habitrpgwrapper.lib.models.tasks.Days; |
60 | 60 | import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData; |
| 61 | +import com.magicmicky.habitrpgwrapper.lib.models.tasks.RemindersItem; |
61 | 62 | import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; |
62 | 63 | import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag; |
63 | 64 | import com.mikepenz.materialdrawer.AccountHeader; |
@@ -378,6 +379,14 @@ private void setUserData(boolean fromLocalDb) { |
378 | 379 | } |
379 | 380 | loadAndRemoveOldTaskTags(allTaskTags); |
380 | 381 |
|
| 382 | + ArrayList<RemindersItem> allReminders = new ArrayList<>(); |
| 383 | + for (Task t : allTasks) { |
| 384 | + if (t.getReminders() != null) { |
| 385 | + allReminders.addAll(t.getReminders()); |
| 386 | + } |
| 387 | + } |
| 388 | + loadAndRemoveOldReminders(allReminders); |
| 389 | + |
381 | 390 | loadAndRemoveOldTags(user.getTags()); |
382 | 391 |
|
383 | 392 | updateOwnedDataForUser(user); |
@@ -561,6 +570,52 @@ public boolean hasResult(BaseTransaction<List<TaskTag>> baseTransaction, List<Ta |
561 | 570 |
|
562 | 571 | } |
563 | 572 |
|
| 573 | + private void loadAndRemoveOldReminders(final List<RemindersItem> onlineEntries) { |
| 574 | + final ArrayList<String> onlineTaskTagItemIdList = new ArrayList<>(); |
| 575 | + |
| 576 | + for (RemindersItem item : onlineEntries) { |
| 577 | + onlineTaskTagItemIdList.add(item.getId()); |
| 578 | + } |
| 579 | + |
| 580 | + From<RemindersItem> query = new Select().from(RemindersItem.class); |
| 581 | + try { |
| 582 | + if (query.count() != onlineEntries.size()) { |
| 583 | + |
| 584 | + // Load Database Checklist items |
| 585 | + query.async().queryList(new TransactionListener<List<RemindersItem>>() { |
| 586 | + @Override |
| 587 | + public void onResultReceived(List<RemindersItem> items) { |
| 588 | + |
| 589 | + ArrayList<RemindersItem> remindersToDelete = new ArrayList<>(); |
| 590 | + |
| 591 | + for (RemindersItem reminder : items) { |
| 592 | + if (!onlineTaskTagItemIdList.contains(reminder.getId())) { |
| 593 | + remindersToDelete.add(reminder); |
| 594 | + } |
| 595 | + } |
| 596 | + |
| 597 | + for (RemindersItem reminder : remindersToDelete) { |
| 598 | + reminder.async().delete(); |
| 599 | + } |
| 600 | + } |
| 601 | + |
| 602 | + @Override |
| 603 | + public boolean onReady(BaseTransaction<List<RemindersItem>> baseTransaction) { |
| 604 | + return false; |
| 605 | + } |
| 606 | + |
| 607 | + @Override |
| 608 | + public boolean hasResult(BaseTransaction<List<RemindersItem>> baseTransaction, List<RemindersItem> items) { |
| 609 | + return items != null && items.size() > 0; |
| 610 | + } |
| 611 | + }); |
| 612 | + } |
| 613 | + } catch (SQLiteDoneException ignored) { |
| 614 | + //Ignored |
| 615 | + } |
| 616 | + |
| 617 | + } |
| 618 | + |
564 | 619 | private void loadAndRemoveOldTags(final List<Tag> onlineEntries) { |
565 | 620 | final ArrayList<String> onlineTaskTagItemIdList = new ArrayList<>(); |
566 | 621 |
|
|
0 commit comments