Commit 2322ddc2 authored by Kevin Whitaker's avatar Kevin Whitaker

Abilities and Achievements should now rely on enum name for identification,...

Abilities and Achievements should now rely on enum name for identification, but display current string resource in ui.
parent d137e91c
......@@ -133,7 +133,7 @@ public class CampaignDetailsActivity extends RecyclerViewActivity {
RealmList<Achievement> currentPartyAchievements = MiceAndMysticsApplication.getRealmInstance().where(Campaign.class).equalTo("campaignName",campaign.getCampaignName()).findFirst().getPartyStoryAchievements();
boolean hasAlready = false;
for (Achievement achievement:currentPartyAchievements) {
if(achievementSpinner.getSelectedItem().toString().equals(achievement.getAchievementName())){
if(((com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement)achievementSpinner.getSelectedItem()).name().equals(achievement.getAchievementName())){
hasAlready = true;
}
}
......
......@@ -76,7 +76,7 @@ public class CharacterDetailsActivity extends RecyclerViewActivity {
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
RealmResults<Character> duplicates = MiceAndMysticsApplication.getRealmInstance().where(Character.class).equalTo("abilities.abilityName",abilitySpinner.getSelectedItem().toString()).equalTo("uuid",currentCharacter.getUuid()).findAll();
RealmResults<Character> duplicates = MiceAndMysticsApplication.getRealmInstance().where(Character.class).equalTo("abilities.abilityName", ((Abilities) abilitySpinner.getSelectedItem()).name()).equalTo("uuid", currentCharacter.getUuid()).findAll();
if(duplicates.size()==0) {
((CharacterDetailsAdapter) getAdapter()).addAbility((Abilities) abilitySpinner.getSelectedItem());
} else {
......
......@@ -107,7 +107,7 @@ public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
Achievement realmAchievement = MiceAndMysticsApplication.getRealmInstance().createObject(Achievement.class);
realmAchievement.setUuid(UUID.randomUUID().toString());
realmAchievement.setAchievementName(achievement.displayName());
realmAchievement.setAchievementName(achievement.name());
currentCampaign.getPartyStoryAchievements().add(realmAchievement);
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
......
package com.eyecreate.miceandmystics.miceandmystics.model.Enums;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
public enum Achievement {
Miz_Maggie("Miz Maggie", R.mipmap.mizmaggie),
Vanestras_Brush("Vanestra's Brush",R.mipmap.vanbrush),
King("King",R.mipmap.king),
Cats_Horn_Claw("Cat's Horn Claw",R.mipmap.catclaw), //not sure if it matters this is the claw and not the horn side.
Catnip("Catnip",R.mipmap.catnip);
Miz_Maggie(R.string.ach_name_maggie, R.mipmap.mizmaggie),
Vanestras_Brush(R.string.ach_name_van_brush,R.mipmap.vanbrush),
King(R.string.ach_name_king,R.mipmap.king),
Cats_Horn_Claw(R.string.ach_name_horn_claw,R.mipmap.catclaw), //not sure if it matters this is the claw and not the horn side.
Catnip(R.string.ach_name_catnip,R.mipmap.catnip);
private String displayName;
private int displayName;
private int displayResource;
Achievement(String displayName,int resource) {
Achievement(int displayName,int resource) {
this.displayName = displayName;
this.displayResource = resource;
}
public String displayName() { return displayName; }
public String displayName() { return MiceAndMysticsApplication.getInstance().getString(displayName); }
public int getDisplayResource() { return displayResource; }
@Override public String toString() { return displayName; }
public static Achievement valueOfDisplayName(String valuedDisplayName) {return Achievement.valueOf(valuedDisplayName.replace(" ","_").replace("'",""));}
@Override public String toString() { return displayName(); }
}
......@@ -25,12 +25,7 @@ public class CharacterAbilityViewHolder extends RecyclerView.ViewHolder implemen
}
public void bindHolder(Ability ability) {
try {
abilityName.setText(Abilities.valueOf(ability.getAbilityName()).toString());
} catch(IllegalArgumentException e) {
//This is a workaround if ability doesn't exist. This is likely due to using old stored data.
abilityName.setText(ability.getAbilityName());
}
abilityName.setText(Abilities.valueOf(ability.getAbilityName()).toString());
uuid = ability.getUuid();
}
......
......@@ -28,8 +28,8 @@ public class PartyAchievementViewHolder extends RecyclerView.ViewHolder implemen
public void bindHolder(Achievement achievement) {
this.boundAchievement = achievement;
achievementName.setText(achievement.getAchievementName());
achievementIcon.setImageResource(com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement.valueOfDisplayName(achievement.getAchievementName()).getDisplayResource());
achievementName.setText(com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement.valueOf(achievement.getAchievementName()).displayName());
achievementIcon.setImageResource(com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement.valueOf(achievement.getAchievementName()).getDisplayResource());
}
@Override
......
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