This commit is contained in:
Phillip Thelen 2016-07-21 14:19:51 +02:00
parent e4d667eacd
commit 0f70acc650
3 changed files with 57 additions and 2 deletions

View file

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.habitrpg.android.habitica"
android:versionCode="102"
android:versionCode="104"
android:versionName="0.0.32"
android:screenOrientation="portrait"
android:installLocation="auto" >

View file

@ -58,6 +58,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.responses.MaintenanceResponse;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Days;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.RemindersItem;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
import com.mikepenz.materialdrawer.AccountHeader;
@ -378,6 +379,14 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
}
loadAndRemoveOldTaskTags(allTaskTags);
ArrayList<RemindersItem> allReminders = new ArrayList<>();
for (Task t : allTasks) {
if (t.getReminders() != null) {
allReminders.addAll(t.getReminders());
}
}
loadAndRemoveOldReminders(allReminders);
loadAndRemoveOldTags(user.getTags());
updateOwnedDataForUser(user);
@ -561,6 +570,52 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
}
private void loadAndRemoveOldReminders(final List<RemindersItem> onlineEntries) {
final ArrayList<String> onlineTaskTagItemIdList = new ArrayList<>();
for (RemindersItem item : onlineEntries) {
onlineTaskTagItemIdList.add(item.getId());
}
From<RemindersItem> query = new Select().from(RemindersItem.class);
try {
if (query.count() != onlineEntries.size()) {
// Load Database Checklist items
query.async().queryList(new TransactionListener<List<RemindersItem>>() {
@Override
public void onResultReceived(List<RemindersItem> items) {
ArrayList<RemindersItem> remindersToDelete = new ArrayList<>();
for (RemindersItem reminder : items) {
if (!onlineTaskTagItemIdList.contains(reminder.getId())) {
remindersToDelete.add(reminder);
}
}
for (RemindersItem reminder : remindersToDelete) {
reminder.async().delete();
}
}
@Override
public boolean onReady(BaseTransaction<List<RemindersItem>> baseTransaction) {
return false;
}
@Override
public boolean hasResult(BaseTransaction<List<RemindersItem>> baseTransaction, List<RemindersItem> items) {
return items != null && items.size() > 0;
}
});
}
} catch (SQLiteDoneException ignored) {
//Ignored
}
}
private void loadAndRemoveOldTags(final List<Tag> onlineEntries) {
final ArrayList<String> onlineTaskTagItemIdList = new ArrayList<>();

View file

@ -629,6 +629,6 @@ public class Task extends BaseModel {
TaskDeleteEvent event = new TaskDeleteEvent();
event.task = this;
EventBus.getDefault().post(event);
super.save();
super.delete();
}
}