Adds edit challenge rating screen.

This commit is contained in:
2021-05-31 20:23:39 -07:00
committed by Tom Hicks
parent 218f39f6c2
commit 42a2994f2c
6 changed files with 226 additions and 23 deletions

View File

@@ -12,6 +12,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavBackStackEntry;
import androidx.navigation.NavController;
@@ -20,19 +21,20 @@ import androidx.navigation.Navigation;
import com.majinnaibu.monstercards.R;
import com.majinnaibu.monstercards.data.enums.ChallengeRating;
import com.majinnaibu.monstercards.helpers.ArrayHelper;
import com.majinnaibu.monstercards.ui.shared.MCFragment;
import com.majinnaibu.monstercards.utils.TextChangedListener;
public class EditChallengeRatingFragment extends MCFragment {
public class EditChallengeRatingFragment extends Fragment {
private EditMonsterViewModel mViewModel;
private ViewHolder mHolder;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
NavBackStackEntry backStackEntry = navController.getBackStackEntry(R.id.edit_monster_navigation);
mViewModel = new ViewModelProvider(backStackEntry).get(EditMonsterViewModel.class);
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_edit_challenge_rating, container, false);
mHolder = new ViewHolder(root);
@@ -82,7 +84,7 @@ public class EditChallengeRatingFragment extends MCFragment {
final EditText customChallengeRatingDescription;
final EditText customProficiencyBonus;
ViewHolder(@NonNull View root) {
ViewHolder(View root) {
challengeRating = root.findViewById(R.id.challengeRating);
customChallengeRatingDescription = root.findViewById(R.id.customChallengeRatingDescription);
customProficiencyBonus = root.findViewById(R.id.customProficiencyBonus);

View File

@@ -83,37 +83,32 @@ public class EditMonsterFragment extends MCFragment {
mHolder.basicInfoButton.setOnClickListener(v -> {
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditBasicInfoFragment();
View view = getView();
assert view != null;
Navigation.findNavController(view).navigate(action);
Navigation.findNavController(requireView()).navigate(action);
});
mHolder.armorButton.setOnClickListener(v -> {
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditArmorFragment();
View view = getView();
assert view != null;
Navigation.findNavController(view).navigate(action);
Navigation.findNavController(requireView()).navigate(action);
});
mHolder.speedButton.setOnClickListener(v -> {
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSpeedFragment();
View view = getView();
assert view != null;
Navigation.findNavController(view).navigate(action);
Navigation.findNavController(requireView()).navigate(action);
});
mHolder.abilityScoresButton.setOnClickListener(v -> {
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditAbilityScoresFragment();
View view = getView();
assert view != null;
Navigation.findNavController(view).navigate(action);
Navigation.findNavController(requireView()).navigate(action);
});
mHolder.savingThrows.setOnClickListener(v -> {
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSavingThrowsFragment();
View view = getView();
assert view != null;
Navigation.findNavController(view).navigate(action);
Navigation.findNavController(requireView()).navigate(action);
});
mHolder.challengeRating.setOnClickListener(v -> {
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditChallengeRatingFragment();
Navigation.findNavController(requireView()).navigate(action);
});
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {

View File

@@ -7,11 +7,17 @@ import androidx.lifecycle.ViewModel;
import com.majinnaibu.monstercards.data.enums.AdvantageType;
import com.majinnaibu.monstercards.data.enums.ArmorType;
import com.majinnaibu.monstercards.data.enums.ChallengeRating;
import com.majinnaibu.monstercards.data.enums.ProficiencyType;
import com.majinnaibu.monstercards.helpers.StringHelper;
import com.majinnaibu.monstercards.models.Language;
import com.majinnaibu.monstercards.models.Monster;
import com.majinnaibu.monstercards.models.Skill;
import com.majinnaibu.monstercards.models.Trait;
import com.majinnaibu.monstercards.utils.ChangeTrackedLiveData;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@SuppressWarnings({"ConstantConditions", "unused"})
@@ -60,6 +66,28 @@ public class EditMonsterViewModel extends ViewModel {
private final ChangeTrackedLiveData<String> mCustomHitPoints;
private final ChangeTrackedLiveData<String> mCustomArmor;
private final ChangeTrackedLiveData<String> mCustomSpeed;
private final ChangeTrackedLiveData<ChallengeRating> mChallengeRating;
private final ChangeTrackedLiveData<String> mCustomChallengeRatingDescription;
private final ChangeTrackedLiveData<Integer> mCustomProficiencyBonus;
private final ChangeTrackedLiveData<Integer> mBlindsightRange;
private final ChangeTrackedLiveData<Boolean> mIsBlindBeyondBlindsightRange;
private final ChangeTrackedLiveData<Integer> mDarkvisionRange;
private final ChangeTrackedLiveData<Integer> mTremorsenseRange;
private final ChangeTrackedLiveData<Integer> mTruesightRange;
private final ChangeTrackedLiveData<Integer> mTelepathyRange;
private final ChangeTrackedLiveData<String> mUnderstandsButDescription;
private final ChangeTrackedLiveData<Set<Skill>> mSkills;
private final ChangeTrackedLiveData<Set<String>> mDamageImmunities;
private final ChangeTrackedLiveData<Set<String>> mDamageResistances;
private final ChangeTrackedLiveData<Set<String>> mDamageVulnerabilities;
private final ChangeTrackedLiveData<Set<String>> mConditionImmunities;
private final ChangeTrackedLiveData<Set<Language>> mLanguages;
private final ChangeTrackedLiveData<Set<Trait>> mAbilities;
private final ChangeTrackedLiveData<Set<Trait>> mActions;
private final ChangeTrackedLiveData<Set<Trait>> mReactions;
private final ChangeTrackedLiveData<Set<Trait>> mLairActions;
private final ChangeTrackedLiveData<Set<Trait>> mLegendaryActions;
private final ChangeTrackedLiveData<Set<Trait>> mRegionalActions;
public EditMonsterViewModel() {
mErrorMessage = new MutableLiveData<>("");
@@ -108,6 +136,28 @@ public class EditMonsterViewModel extends ViewModel {
mWisdomAdvantage = new ChangeTrackedLiveData<>(AdvantageType.NONE, onDirtied);
mCharismaProficiency = new ChangeTrackedLiveData<>(ProficiencyType.NONE, onDirtied);
mCharismaAdvantage = new ChangeTrackedLiveData<>(AdvantageType.NONE, onDirtied);
mChallengeRating = new ChangeTrackedLiveData<>(ChallengeRating.ONE_EIGHTH, onDirtied);
mCustomChallengeRatingDescription = new ChangeTrackedLiveData<>("", onDirtied);
mCustomProficiencyBonus = new ChangeTrackedLiveData<>(0, onDirtied);
mBlindsightRange = new ChangeTrackedLiveData<>(0, onDirtied);
mIsBlindBeyondBlindsightRange = new ChangeTrackedLiveData<>(false, onDirtied);
mDarkvisionRange = new ChangeTrackedLiveData<>(0, onDirtied);
mTremorsenseRange = new ChangeTrackedLiveData<>(0, onDirtied);
mTruesightRange = new ChangeTrackedLiveData<>(0, onDirtied);
mTelepathyRange = new ChangeTrackedLiveData<>(0, onDirtied);
mUnderstandsButDescription = new ChangeTrackedLiveData<>("", onDirtied);
mSkills = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mDamageImmunities = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mDamageResistances = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mDamageVulnerabilities = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mConditionImmunities = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mLanguages = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mAbilities = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mActions = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mReactions = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mLairActions = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mLegendaryActions = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
mRegionalActions = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
}
public void copyFromMonster(Monster monster) {
@@ -151,7 +201,28 @@ public class EditMonsterViewModel extends ViewModel {
mWisdomAdvantage.resetValue(monster.wisdomSavingThrowAdvantage);
mCharismaProficiency.resetValue(monster.charismaSavingThrowProficiency);
mCharismaAdvantage.resetValue(monster.charismaSavingThrowAdvantage);
mChallengeRating.resetValue(monster.challengeRating);
mCustomChallengeRatingDescription.resetValue(monster.customChallengeRatingDescription);
mCustomProficiencyBonus.resetValue(monster.customProficiencyBonus);
mBlindsightRange.resetValue(monster.blindsightRange);
mIsBlindBeyondBlindsightRange.resetValue(monster.isBlindBeyondBlindsightRange);
mDarkvisionRange.resetValue(monster.darkvisionRange);
mTremorsenseRange.resetValue(monster.tremorsenseRange);
mTruesightRange.resetValue(monster.truesightRange);
mTelepathyRange.resetValue(monster.telepathyRange);
mUnderstandsButDescription.resetValue(monster.understandsButDescription);
mSkills.resetValue(monster.skills);
mDamageImmunities.resetValue(monster.damageImmunities);
mDamageResistances.resetValue(monster.damageResistances);
mDamageVulnerabilities.resetValue(monster.damageVulnerabilities);
mConditionImmunities.resetValue(monster.conditionImmunities);
mLanguages.resetValue(monster.languages);
mAbilities.resetValue(monster.abilities);
mActions.resetValue(monster.actions);
mReactions.resetValue(monster.reactions);
mLairActions.resetValue(monster.lairActions);
mLegendaryActions.resetValue(monster.legendaryActions);
mRegionalActions.resetValue(monster.regionalActions);
mHasChanges.setValue(false);
}
@@ -634,6 +705,111 @@ public class EditMonsterViewModel extends ViewModel {
mCharismaAdvantage.setValue(advantage);
}
public LiveData<ChallengeRating> getChallengeRating() {
return mChallengeRating;
}
public void setChallengeRating(ChallengeRating challengeRating) {
mChallengeRating.setValue(challengeRating);
}
public LiveData<String> getCustomChallengeRatingDescription() {
return mCustomChallengeRatingDescription;
}
public void setCustomChallengeRatingDescription(String customChallengeRatingDescription) {
mCustomChallengeRatingDescription.setValue(customChallengeRatingDescription);
}
public LiveData<Integer> getCustomProficiencyBonus() {
return mCustomProficiencyBonus;
}
public void setCustomProficiencyBonus(int proficiencyBonus) {
mCustomProficiencyBonus.setValue(proficiencyBonus);
}
public void setCustomProficiencyBonus(String proficiencyBonus) {
Integer parsedValue = StringHelper.parseInt(proficiencyBonus);
this.setCustomProficiencyBonus(parsedValue != null ? parsedValue : 0);
}
public String getCustomProficiencyBonusValueAsString() {
return mCustomProficiencyBonus.getValue().toString();
}
public LiveData<Integer> getBlindsightRange() {
return mBlindsightRange;
}
public void setBlindsightRange(int blindsightRange) {
mBlindsightRange.setValue(blindsightRange);
}
public LiveData<Boolean> getIsBlindBeyondBlindsightRange() {
return mIsBlindBeyondBlindsightRange;
}
public void setIsBlindBeyondBlindsightRange(boolean isBlindBeyondBlindsightRange) {
mIsBlindBeyondBlindsightRange.setValue(isBlindBeyondBlindsightRange);
}
public LiveData<Integer> getDarkvisionRange() {
return mDarkvisionRange;
}
public void setDarkvisionRange(int darkvisionRange) {
mDarkvisionRange.setValue(darkvisionRange);
}
public LiveData<Integer> getTremorsenseRange() {
return mTremorsenseRange;
}
public void setTremorsenseRange(int tremorsenseRange) {
mTremorsenseRange.setValue(tremorsenseRange);
}
public LiveData<Integer> getTruesightRange() {
return mTruesightRange;
}
public void setTruesightRange(int truesightRange) {
mTruesightRange.setValue(truesightRange);
}
public LiveData<Integer> getTelepathyRange() {
return mTelepathyRange;
}
public void setTelepathyRange(int telepathyRange) {
mTelepathyRange.setValue(telepathyRange);
}
public LiveData<String> getUnderstandsButDescription() {
return mUnderstandsButDescription;
}
public void setUnderstandsButDescription(String understandsButDescription) {
mUnderstandsButDescription.setValue(understandsButDescription);
}
/*
// TODO: add getters and setters for
Senses
Skills
Damage Immunities
DamageResistances
DamageVulnerabilities
ConditionImmunities
Languages
Abilities
Actions
Reactions
LairActions
LegendaryActions
RegionalActions
*/
public Monster buildMonster() {
Monster monster = new Monster();
@@ -676,6 +852,28 @@ public class EditMonsterViewModel extends ViewModel {
monster.wisdomSavingThrowProficiency = mWisdomProficiency.getValue();
monster.charismaSavingThrowAdvantage = mCharismaAdvantage.getValue();
monster.charismaSavingThrowProficiency = mCharismaProficiency.getValue();
monster.challengeRating = mChallengeRating.getValue();
monster.customChallengeRatingDescription = mCustomChallengeRatingDescription.getValue();
monster.customProficiencyBonus = mCustomProficiencyBonus.getValue();
monster.blindsightRange = mBlindsightRange.getValue();
monster.isBlindBeyondBlindsightRange = mIsBlindBeyondBlindsightRange.getValue();
monster.darkvisionRange = mDarkvisionRange.getValue();
monster.tremorsenseRange = mTremorsenseRange.getValue();
monster.truesightRange = mTruesightRange.getValue();
monster.telepathyRange = mTelepathyRange.getValue();
monster.understandsButDescription = mUnderstandsButDescription.getValue();
monster.skills = mSkills.getValue();
monster.damageImmunities = mDamageImmunities.getValue();
monster.damageResistances = mDamageResistances.getValue();
monster.damageVulnerabilities = mDamageVulnerabilities.getValue();
monster.conditionImmunities = mConditionImmunities.getValue();
monster.languages = mLanguages.getValue();
monster.abilities = mAbilities.getValue();
monster.actions = mActions.getValue();
monster.reactions = mReactions.getValue();
monster.lairActions = mLairActions.getValue();
monster.legendaryActions = mLegendaryActions.getValue();
monster.regionalActions = mRegionalActions.getValue();
return monster;
}

View File

@@ -24,7 +24,6 @@
android:id="@+id/naturalArmorBonus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="0123456789"
android:hint="@string/label_natural_armor_bonus"
android:importantForAutofill="no"
android:inputType="numberSigned"
@@ -48,7 +47,6 @@
android:id="@+id/shieldBonus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="0123456789"
android:hint="@string/label_shield_bonus"
android:importantForAutofill="no"
android:inputType="numberSigned"

View File

@@ -87,6 +87,9 @@
<action
android:id="@+id/action_editMonsterFragment_to_editSavingThrowsFragment"
app:destination="@id/editSavingThrowsFragment" />
<action
android:id="@+id/action_editMonsterFragment_to_editChallengeRatingFragment"
app:destination="@id/editChallengeRatingFragment" />
</fragment>
<fragment
android:id="@+id/editBasicInfoFragment"
@@ -112,6 +115,11 @@
android:name="com.majinnaibu.monstercards.ui.editmonster.EditSavingThrowsFragment"
android:label="fragment_edit_saving_throws"
tools:layout="@layout/fragment_edit_saving_throws" />
<fragment
android:id="@+id/editChallengeRatingFragment"
android:name="com.majinnaibu.monstercards.ui.editmonster.EditChallengeRatingFragment"
android:label="fragment_edit_challenge_rating"
tools:layout="@layout/fragment_edit_challenge_rating" />
</navigation>
</navigation>

View File

@@ -28,7 +28,9 @@
<string name="label_condition_immunities">Condition Immunities</string>
<string name="label_constitution">Constitution</string>
<string name="label_custom_armor">Custom Armor</string>
<string name="label_custom_challenge_rating_description">Custom CR</string>
<string name="label_custom_hp">Custom HP</string>
<string name="label_custom_proficiency_bonus">Custom Proficiency Bonus</string>
<string name="label_custom_speed">Custom Speed</string>
<string name="label_damage_immunities">Damage Immunities</string>
<string name="label_damage_resistances">Damage Resistances</string>