diff --git a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/ChooseSyncInitHelper.java b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/ChooseSyncInitHelper.java index c6e1e03..e64633b 100644 --- a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/ChooseSyncInitHelper.java +++ b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/ChooseSyncInitHelper.java @@ -27,6 +27,7 @@ public class ChooseSyncInitHelper { private ChooseSyncModel mChooseSyncModel = null; private boolean mHasDataToSync = false; private boolean mHasChosenDataToSync = false; + private int nbElementsToSync = 0; public ChooseSyncInitHelper(Context context, ComputeSyncResultModel syncResult) { super(); @@ -44,6 +45,8 @@ public ChooseSyncModel filterSyncResult() { fillMaterials(); fillMonsters(); + MyLog.info("nbElementsToSync : " + nbElementsToSync); + MyLog.exit(); return mChooseSyncModel; } @@ -56,6 +59,7 @@ private void fillUserInfo() { syncedUserInfoToUpdate.setModel(mSyncResult.getSyncedUserInfo()); mChooseSyncModel.setSyncedUserInfoToUpdate(syncedUserInfoToUpdate); + nbElementsToSync++; MyLog.exit(); } @@ -74,6 +78,7 @@ private void fillMaterials() { container.setChosen(mPrefHelper.isChooseSyncPreselectMaterialsUpdated()); container.setModel(material); syncedMaterialsToUpdate.add(container); + nbElementsToSync++; flagDataToSync(container); } } @@ -85,9 +90,9 @@ private void fillMaterials() { private void fillMonsters() { MyLog.entry(); - final List> syncedMonstersToUpdate = new ArrayList>(); - final List> syncedMonstersToCreate = new ArrayList>(); - final List> syncedMonstersToDelete = new ArrayList>(); + mChooseSyncModel.setSyncedMonsters(SyncMode.UPDATED, new ArrayList>()); + mChooseSyncModel.setSyncedMonsters(SyncMode.CREATED, new ArrayList>()); + mChooseSyncModel.setSyncedMonsters(SyncMode.DELETED, new ArrayList>()); final Set ignoredIds = mPrefHelper.getMonsterIgnoreList(); @@ -101,9 +106,7 @@ private void fillMonsters() { MyLog.debug("ignoring deleted monster : " + monster); } else { MyLog.debug("adding deleted monster : " + monster); - container.setChosen(mPrefHelper.isChooseSyncPreselectMonsters(SyncMode.DELETED)); - syncedMonstersToDelete.add(container); - flagDataToSync(container); + addMonsterToSync(SyncMode.DELETED, container); } } else if (monster.getPadherderInfo() == null) { boolean ignored = mPrefHelper.isChooseSyncUseIgnoreListForMonsters(SyncMode.CREATED) && ignoredIds.contains(monster.getDisplayedMonsterInfo().getIdJP()); @@ -111,9 +114,7 @@ private void fillMonsters() { MyLog.debug("ignoring created monster : " + monster); } else { MyLog.debug("adding created monster : " + monster); - container.setChosen(mPrefHelper.isChooseSyncPreselectMonsters(SyncMode.CREATED)); - syncedMonstersToCreate.add(container); - flagDataToSync(container); + addMonsterToSync(SyncMode.CREATED, container); } } else { boolean ignored = mPrefHelper.isChooseSyncUseIgnoreListForMonsters(SyncMode.UPDATED) && ignoredIds.contains(monster.getDisplayedMonsterInfo().getIdJP()); @@ -121,20 +122,23 @@ private void fillMonsters() { MyLog.debug("ignoring updated monster : " + monster); } else { MyLog.debug("adding updated monster : " + monster); - container.setChosen(mPrefHelper.isChooseSyncPreselectMonsters(SyncMode.UPDATED)); - syncedMonstersToUpdate.add(container); - flagDataToSync(container); + addMonsterToSync(SyncMode.UPDATED, container); } } } - mChooseSyncModel.setSyncedMonsters(SyncMode.UPDATED, syncedMonstersToUpdate); - mChooseSyncModel.setSyncedMonsters(SyncMode.CREATED, syncedMonstersToCreate); - mChooseSyncModel.setSyncedMonsters(SyncMode.DELETED, syncedMonstersToDelete); + MyLog.exit(); } + private void addMonsterToSync(SyncMode mode, ChooseModelContainer container) { + container.setChosen(mPrefHelper.isChooseSyncPreselectMonsters(mode)); + mChooseSyncModel.getSyncedMonsters(mode).add(container); + flagDataToSync(container); + } + private void flagDataToSync(ChooseModelContainer container) { + nbElementsToSync++; mHasDataToSync = true; if (container.isChosen()) { mHasChosenDataToSync = true; diff --git a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/MonsterComparatorHelper.java b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/MonsterComparatorHelper.java index 1c2039e..ebbe001 100644 --- a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/MonsterComparatorHelper.java +++ b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/MonsterComparatorHelper.java @@ -11,6 +11,7 @@ public class MonsterComparatorHelper { public static boolean areMonstersEqual(MonsterModel a, MonsterModel b) { return a.getIdJp() == b.getIdJp() && + a.getCardId() == b.getCardId() && a.getExp() == b.getExp() && a.getSkillLevel() == b.getSkillLevel() && a.getPlusHp() == b.getPlusHp() && diff --git a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/PushSyncHelper.java b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/PushSyncHelper.java index 8c12eb1..b59fbf4 100644 --- a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/PushSyncHelper.java +++ b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/PushSyncHelper.java @@ -85,6 +85,10 @@ private void pushMonsterToUpdate(SyncedMonsterModel model) throws JSONException, final JSONObject json = new JSONObject(); json.put("monster", model.getCapturedInfo().getIdJp()); + if (model.getCapturedInfo().getCardId() != null && !model.getCapturedInfo().getCardId().equals(model.getPadherderInfo().getCardId())) { + json.put("pad_id", model.getCapturedInfo().getCardId()); + } + if (model.getCapturedInfo().getIdJp() != model.getPadherderInfo().getIdJp()) { // Monster evolution, reset the target to the max json.put("target_level", model.getCapturedMonsterInfo().getMaxLevel()); @@ -140,6 +144,9 @@ private void pushMonsterToCreate(SyncedMonsterModel model) throws JSONException, */ final JSONObject json = new JSONObject(); json.put("monster", model.getDisplayedMonsterInfo().getIdJP()); + if (model.getCapturedInfo().getCardId() != null) { + json.put("pad_id", model.getCapturedInfo().getCardId()); + } json.put("current_xp", model.getCapturedInfo().getExp()); json.put("current_skill", model.getCapturedInfo().getSkillLevel()); json.put("current_awakening", model.getCapturedInfo().getAwakenings()); diff --git a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/SyncHelper.java b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/SyncHelper.java index 615d437..69df4f2 100644 --- a/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/SyncHelper.java +++ b/PADListenerApp/src/main/java/fr/neraud/padlistener/helper/SyncHelper.java @@ -2,6 +2,7 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.support.annotation.NonNull; import java.util.ArrayList; import java.util.Collections; @@ -375,6 +376,39 @@ private List syncMonstersForOneId(Integer monsterId, List capturedIter = capturedMonstersWork.iterator(); + // Matching monsters on CARD_ID + capturedLoop: + while (capturedIter.hasNext()) { + final MonsterModel captured = capturedIter.next(); + if (captured.getCardId() != null) { + final Iterator parherderIter = padherderMonstersWork.iterator(); + while (parherderIter.hasNext()) { + final UserInfoMonsterModel padherder = parherderIter.next(); + if (captured.getCardId().equals(padherder.getCardId())) { + if (MonsterComparatorHelper.areMonstersEqual(captured, padherder)) { + MyLog.debug("matching ids and equal, removing : " + captured); + capturedIter.remove(); + parherderIter.remove(); + continue capturedLoop; + } else { + try { + final SyncedMonsterModel model = fillUpdatedSyncedMonsterModel(padherder, captured); + syncedMonsters.add(model); + MyLog.debug("matching ids and different, updating : " + model); + } catch (UnknownMonsterException e) { + // Should not happen as monsters are checked before during the reorg phase + MyLog.warn("missing monster info for id = " + e.getMonsterId()); + hasEncounteredUnknownMonster = true; + } + capturedIter.remove(); + parherderIter.remove(); + continue capturedLoop; + } + } + } + } + } + // Filter "equals" monsters capturedLoop: while (capturedIter.hasNext()) { @@ -383,7 +417,7 @@ private List syncMonstersForOneId(Integer monsterId, List syncMonstersForOneId(Integer monsterId, List creating - final MonsterModel captured = capturedMonstersWork.get(i); - - model.setCapturedMonsterInfo(monsterInfoHelper.getMonsterInfo(captured.getIdJp())); - - // default create priority - captured.setPriority(helper.getDefaultMonsterCreatePriority()); - model.setCapturedInfo(capturedMonstersWork.get(i)); - - model.setPadherderInfo(null); + model = fillCreatedSyncedMonsterModel(capturedMonstersWork.get(i)); MyLog.debug("added : " + model); } else { // not enough captured -> deleting - final UserInfoMonsterModel padherder = padherderMonstersWork.get(i); - - model.setPadherderMonsterInfo(monsterInfoHelper.getMonsterInfo(padherder.getIdJp())); - - model.setPadherderId(padherder.getPadherderId()); - model.setCapturedInfo(null); - model.setPadherderInfo(padherderMonstersWork.get(i)); + model = fillDeletedSyncedMonsterModel(padherderMonstersWork.get(i)); MyLog.debug("deleted : " + model); } @@ -449,4 +456,45 @@ private List syncMonstersForOneId(Integer monsterId, ListFixed #81 : Fixed friends broken by the new Best Friend flag (thanks QuasiTD !) Fixed #90 : repaired Manual capture for M (thanks olifozzy !) Fixed #91 : Tapping on "PAD data captured" notification dismisses it + Fixed #94 : Added support for CardID