Moves DiffCallback methods into Monster class.
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -270,6 +271,69 @@ public class Monster {
|
||||
regionalActions = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static boolean areItemsTheSame(@NonNull Monster oldItem, @NonNull Monster newItem) {
|
||||
return Objects.equals(oldItem.id, newItem.id);
|
||||
}
|
||||
|
||||
public static boolean areContentsTheSame(@NonNull Monster oldItem, @NonNull Monster newItem) {
|
||||
return Objects.equals(oldItem.abilities, newItem.abilities) &&
|
||||
Objects.equals(oldItem.actions, newItem.actions) &&
|
||||
Objects.equals(oldItem.alignment, newItem.alignment) &&
|
||||
Objects.equals(oldItem.armorType, newItem.armorType) &&
|
||||
Objects.equals(oldItem.burrowSpeed, newItem.burrowSpeed) &&
|
||||
Objects.equals(oldItem.canHover, newItem.canHover) &&
|
||||
Objects.equals(oldItem.challengeRating, newItem.challengeRating) &&
|
||||
Objects.equals(oldItem.charismaSavingThrowAdvantage, newItem.charismaSavingThrowAdvantage) &&
|
||||
Objects.equals(oldItem.charismaSavingThrowProficiency, newItem.charismaSavingThrowProficiency) &&
|
||||
Objects.equals(oldItem.charismaScore, newItem.charismaScore) &&
|
||||
Objects.equals(oldItem.climbSpeed, newItem.climbSpeed) &&
|
||||
Objects.equals(oldItem.conditionImmunities, newItem.conditionImmunities) &&
|
||||
Objects.equals(oldItem.constitutionSavingThrowAdvantage, newItem.constitutionSavingThrowAdvantage) &&
|
||||
Objects.equals(oldItem.constitutionSavingThrowProficiency, newItem.constitutionSavingThrowProficiency) &&
|
||||
Objects.equals(oldItem.constitutionScore, newItem.constitutionScore) &&
|
||||
Objects.equals(oldItem.customChallengeRatingDescription, newItem.customChallengeRatingDescription) &&
|
||||
Objects.equals(oldItem.customHPDescription, newItem.customHPDescription) &&
|
||||
Objects.equals(oldItem.customProficiencyBonus, newItem.customProficiencyBonus) &&
|
||||
Objects.equals(oldItem.customSpeedDescription, newItem.customSpeedDescription) &&
|
||||
Objects.equals(oldItem.damageImmunities, newItem.damageImmunities) &&
|
||||
Objects.equals(oldItem.damageResistances, newItem.damageResistances) &&
|
||||
Objects.equals(oldItem.damageVulnerabilities, newItem.damageVulnerabilities) &&
|
||||
Objects.equals(oldItem.dexteritySavingThrowAdvantage, newItem.dexteritySavingThrowAdvantage) &&
|
||||
Objects.equals(oldItem.dexteritySavingThrowProficiency, newItem.dexteritySavingThrowProficiency) &&
|
||||
Objects.equals(oldItem.dexterityScore, newItem.dexterityScore) &&
|
||||
Objects.equals(oldItem.flySpeed, newItem.flySpeed) &&
|
||||
Objects.equals(oldItem.hasCustomHP, newItem.hasCustomHP) &&
|
||||
Objects.equals(oldItem.hasCustomSpeed, newItem.hasCustomSpeed) &&
|
||||
Objects.equals(oldItem.hitDice, newItem.hitDice) &&
|
||||
Objects.equals(oldItem.intelligenceSavingThrowAdvantage, newItem.intelligenceSavingThrowAdvantage) &&
|
||||
Objects.equals(oldItem.intelligenceSavingThrowProficiency, newItem.intelligenceSavingThrowProficiency) &&
|
||||
Objects.equals(oldItem.intelligenceScore, newItem.intelligenceScore) &&
|
||||
Objects.equals(oldItem.lairActions, newItem.lairActions) &&
|
||||
Objects.equals(oldItem.languages, newItem.languages) &&
|
||||
Objects.equals(oldItem.legendaryActions, newItem.legendaryActions) &&
|
||||
Objects.equals(oldItem.name, newItem.name) &&
|
||||
Objects.equals(oldItem.naturalArmorBonus, newItem.naturalArmorBonus) &&
|
||||
Objects.equals(oldItem.otherArmorDescription, newItem.otherArmorDescription) &&
|
||||
Objects.equals(oldItem.reactions, newItem.reactions) &&
|
||||
Objects.equals(oldItem.regionalActions, newItem.regionalActions) &&
|
||||
Objects.equals(oldItem.senses, newItem.senses) &&
|
||||
Objects.equals(oldItem.shieldBonus, newItem.shieldBonus) &&
|
||||
Objects.equals(oldItem.size, newItem.size) &&
|
||||
Objects.equals(oldItem.skills, newItem.skills) &&
|
||||
Objects.equals(oldItem.strengthSavingThrowAdvantage, newItem.strengthSavingThrowAdvantage) &&
|
||||
Objects.equals(oldItem.strengthSavingThrowProficiency, newItem.strengthSavingThrowProficiency) &&
|
||||
Objects.equals(oldItem.strengthScore, newItem.strengthScore) &&
|
||||
Objects.equals(oldItem.subtype, newItem.subtype) &&
|
||||
Objects.equals(oldItem.swimSpeed, newItem.swimSpeed) &&
|
||||
Objects.equals(oldItem.telepathyRange, newItem.telepathyRange) &&
|
||||
Objects.equals(oldItem.type, newItem.type) &&
|
||||
Objects.equals(oldItem.understandsButDescription, newItem.understandsButDescription) &&
|
||||
Objects.equals(oldItem.wisdomSavingThrowAdvantage, newItem.wisdomSavingThrowAdvantage) &&
|
||||
Objects.equals(oldItem.wisdomSavingThrowProficiency, newItem.wisdomSavingThrowProficiency) &&
|
||||
Objects.equals(oldItem.wisdomScore, newItem.wisdomScore) &&
|
||||
Objects.equals(oldItem.walkSpeed, newItem.walkSpeed);
|
||||
}
|
||||
|
||||
public String getMeta() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean isFirstOutput = true;
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
import com.majinnaibu.monstercards.data.enums.AbilityScore;
|
||||
import com.majinnaibu.monstercards.data.enums.AdvantageType;
|
||||
import com.majinnaibu.monstercards.data.enums.ChallengeRating;
|
||||
@@ -21,18 +22,18 @@ import com.majinnaibu.monstercards.models.Monster;
|
||||
import com.majinnaibu.monstercards.models.Trait;
|
||||
import com.majinnaibu.monstercards.utils.Logger;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, DashboardRecyclerViewAdapter.ViewHolder> {
|
||||
private static final DiffUtil.ItemCallback<Monster> DIFF_CALLBACK = new DiffUtil.ItemCallback<Monster>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull @NotNull Monster oldItem, @NonNull @NotNull Monster newItem) {
|
||||
return oldItem.id.equals(newItem.id);
|
||||
public boolean areItemsTheSame(@NonNull Monster oldItem, @NonNull Monster newItem) {
|
||||
return Monster.areItemsTheSame(oldItem, newItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull @NotNull Monster oldItem, @NonNull @NotNull Monster newItem) {
|
||||
return oldItem.equals(newItem);
|
||||
public boolean areContentsTheSame(@NonNull Monster oldItem, @NonNull Monster newItem) {
|
||||
return Monster.areContentsTheSame(oldItem, newItem);
|
||||
}
|
||||
};
|
||||
private final ItemCallback mOnClick;
|
||||
@@ -43,14 +44,13 @@ public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, Dashboard
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@NotNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(CardMonsterBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
Logger.logUnimplementedMethod();
|
||||
Monster monster = getItem(position);
|
||||
holder.monster = monster;
|
||||
@@ -88,7 +88,7 @@ public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, Dashboard
|
||||
|
||||
holder.armorClass.setText(String.valueOf(monster.getArmorClassValue()));
|
||||
holder.hitPoints.setText(String.valueOf(monster.getHitPointsValue()));
|
||||
holder.challengeRating.setText("CR " + Helpers.getChallengeRatingAbbreviation(monster.challengeRating));
|
||||
holder.challengeRating.setText(holder.challengeRating.getResources().getString(R.string.label_challenge_rating_with_value, Helpers.getChallengeRatingAbbreviation(monster.challengeRating)));
|
||||
|
||||
int numActions = monster.actions.size();
|
||||
if (numActions > 0) {
|
||||
@@ -170,7 +170,7 @@ public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, Dashboard
|
||||
public final TextView challengeRating;
|
||||
public Monster monster;
|
||||
|
||||
public ViewHolder(CardMonsterBinding binding) {
|
||||
public ViewHolder(@NonNull CardMonsterBinding binding) {
|
||||
super(binding.getRoot());
|
||||
name = binding.name;
|
||||
meta = binding.meta;
|
||||
@@ -214,11 +214,13 @@ public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, Dashboard
|
||||
}
|
||||
|
||||
public static class Helpers {
|
||||
@NonNull
|
||||
public static String getModifierString(int value) {
|
||||
return String.format("%+d", value);
|
||||
return String.format(Locale.getDefault(), "%+d", value);
|
||||
}
|
||||
|
||||
public static String getAbilityScoreAbbreviation(AbilityScore abilityScore) {
|
||||
@NonNull
|
||||
public static String getAbilityScoreAbbreviation(@NonNull AbilityScore abilityScore) {
|
||||
switch (abilityScore) {
|
||||
case STRENGTH:
|
||||
return "S";
|
||||
@@ -238,7 +240,8 @@ public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, Dashboard
|
||||
}
|
||||
}
|
||||
|
||||
public static String getChallengeRatingAbbreviation(ChallengeRating challengeRating) {
|
||||
@NonNull
|
||||
public static String getChallengeRatingAbbreviation(@NonNull ChallengeRating challengeRating) {
|
||||
Logger.logUnimplementedMethod();
|
||||
switch (challengeRating) {
|
||||
case CUSTOM:
|
||||
@@ -317,7 +320,8 @@ public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, Dashboard
|
||||
}
|
||||
}
|
||||
|
||||
public static String getProficiencyAbbreviation(ProficiencyType proficiency) {
|
||||
@NonNull
|
||||
public static String getProficiencyAbbreviation(@NonNull ProficiencyType proficiency) {
|
||||
switch (proficiency) {
|
||||
case NONE:
|
||||
return "";
|
||||
@@ -331,7 +335,8 @@ public class DashboardRecyclerViewAdapter extends ListAdapter<Monster, Dashboard
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAdvantageAbbreviation(AdvantageType advantage) {
|
||||
@NonNull
|
||||
public static String getAdvantageAbbreviation(@NonNull AdvantageType advantage) {
|
||||
switch (advantage) {
|
||||
case NONE:
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user