Commit 50bd3941 authored by Kevin Whitaker's avatar Kevin Whitaker

Stop using for loops to delete items in the loop. Can confuse Realm and make...

Stop using for loops to delete items in the loop. Can confuse Realm and make it think there are items where there are not. Luckily, there's a simple delete all method. Update gradle plugin.
parent b41200de
......@@ -4,11 +4,13 @@ import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.model.*;
import com.eyecreate.miceandmystics.miceandmystics.model.Character;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CampaignType;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignViewHolder;
import io.realm.RealmResults;
public class CampaignAdapter extends RecyclerView.Adapter<CampaignViewHolder> {
......@@ -50,13 +52,12 @@ public class CampaignAdapter extends RecyclerView.Adapter<CampaignViewHolder> {
.where(com.eyecreate.miceandmystics.miceandmystics.model.Campaign.class)
.equalTo("campaignName",campaignName)
.findFirst();
for(com.eyecreate.miceandmystics.miceandmystics.model.Character character:campaign.getCurrentCharacters()) {
CampaignDetailsAdapter.removeCharacterFromDB(character);
for(Character character:campaign.getCurrentCharacters()) {
CampaignDetailsAdapter.removeItemsAndAbilities(character);
}
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
for(Achievement achievement:campaign.getPartyStoryAchievements()) {
achievement.deleteFromRealm();
}
campaign.getCurrentCharacters().deleteAllFromRealm();
campaign.getPartyStoryAchievements().deleteAllFromRealm();
campaign.deleteFromRealm();
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
......
......@@ -5,12 +5,14 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Toast;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.model.*;
import com.eyecreate.miceandmystics.miceandmystics.model.Achievement;
import com.eyecreate.miceandmystics.miceandmystics.model.Campaign;
import com.eyecreate.miceandmystics.miceandmystics.model.Character;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.*;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CharacterNames;
import com.eyecreate.miceandmystics.miceandmystics.model.Player;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignDetailsViewHolder;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignHeaderViewHolder;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.PartyAchievementViewHolder;
......@@ -92,14 +94,10 @@ public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
}
private static void removeItemsAndAbilities(Character character) {
public static void removeItemsAndAbilities(Character character) {
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
for(Ability ability:character.getAbilities()) {
ability.deleteFromRealm();
}
for(BackpackItem item:character.getStoredItems()) {
item.deleteFromRealm();
}
character.getAbilities().deleteAllFromRealm();
character.getStoredItems().deleteAllFromRealm();
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
}
......
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.2.2'
classpath "io.realm:realm-gradle-plugin:1.1.1"
// NOTE: Do not place your application dependencies here; they belong
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment