mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-15 10:41:58 +00:00
moves owned gear to onUserReceived
This commit is contained in:
parent
7e966ff8cb
commit
4bfb94b8cf
2 changed files with 28 additions and 7 deletions
|
|
@ -62,6 +62,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.TutorialStep;
|
||||
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.Task;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
|
|
@ -70,8 +71,11 @@ import com.mikepenz.materialdrawer.DrawerBuilder;
|
|||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
import com.raizlabs.android.dbflow.runtime.TransactionManager;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelInfo;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.process.SaveModelTransaction;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Delete;
|
||||
import com.raizlabs.android.dbflow.sql.language.From;
|
||||
|
|
@ -314,6 +318,8 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
|
|||
}
|
||||
|
||||
loadAndRemoveOldChecklists(allChecklistItems);
|
||||
|
||||
updateOwnedEquipment(user.getItems().getGear().owned);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
|
@ -424,6 +430,28 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
|
|||
|
||||
}
|
||||
|
||||
private void updateOwnedEquipment(List<ItemData> owned) {
|
||||
HashMap<String, ItemData> ownedMap = new HashMap<>();
|
||||
for (ItemData item : owned) {
|
||||
ownedMap.put(item.key, item);
|
||||
}
|
||||
|
||||
List<ItemData> items = new Select().from(ItemData.class).queryList();
|
||||
List<ItemData> updates = new ArrayList<>();
|
||||
for (ItemData item : items) {
|
||||
if (ownedMap.containsKey(item.key) && !Boolean.TRUE.equals(item.owned)) {
|
||||
item.owned = true;
|
||||
updates.add(item);
|
||||
} else if (!ownedMap.containsKey(item.key) && Boolean.TRUE.equals(item.owned)) {
|
||||
item.owned = null;
|
||||
updates.add(item);
|
||||
}
|
||||
}
|
||||
if (!updates.isEmpty()) {
|
||||
TransactionManager.getInstance().addTransaction(new SaveModelTransaction<>(ProcessModelInfo.withModels(updates)));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUserAvatars() {
|
||||
avatarInHeader.updateData(user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ public class ItemDataListDeserializer implements JsonDeserializer<List<ItemData>
|
|||
item.str = parsedItem.str;
|
||||
item.per = parsedItem.per;
|
||||
item._int = parsedItem._int;
|
||||
} else {
|
||||
item.owned = itemObject.getAsBoolean();
|
||||
}
|
||||
vals.add(item);
|
||||
object.remove(item.key);
|
||||
|
|
@ -56,11 +54,6 @@ public class ItemDataListDeserializer implements JsonDeserializer<List<ItemData>
|
|||
} else {
|
||||
item = new ItemData();
|
||||
item.key = entry.getKey();
|
||||
if (entry.getValue().isJsonNull()) {
|
||||
item.owned = null;
|
||||
} else {
|
||||
item.owned = entry.getValue().getAsBoolean();
|
||||
}
|
||||
}
|
||||
vals.add(item);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue