Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Jul 21, 2016
1 parent e4d667e commit 0f70acc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Habitica/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
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;
Expand Down Expand Up @@ -378,6 +379,14 @@ private void setUserData(boolean fromLocalDb) {
}
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);
Expand Down Expand Up @@ -561,6 +570,52 @@ public boolean hasResult(BaseTransaction<List<TaskTag>> baseTransaction, List<Ta

}

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<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,6 @@ public void delete() {
TaskDeleteEvent event = new TaskDeleteEvent();
event.task = this;
EventBus.getDefault().post(event);
super.save();
super.delete();
}
}

0 comments on commit 0f70acc

Please sign in to comment.