diff --git a/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditChallengeRatingFragment.java b/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditChallengeRatingFragment.java index 33196cd..ec4b724 100644 --- a/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditChallengeRatingFragment.java +++ b/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditChallengeRatingFragment.java @@ -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,10 +84,10 @@ 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); } } -} +} \ No newline at end of file diff --git a/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterFragment.java b/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterFragment.java index 51bb80a..a7975bd 100644 --- a/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterFragment.java +++ b/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterFragment.java @@ -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) { diff --git a/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterViewModel.java b/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterViewModel.java index fb24062..5c0c022 100644 --- a/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterViewModel.java +++ b/Android/app/src/main/java/com/majinnaibu/monstercards/ui/editmonster/EditMonsterViewModel.java @@ -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 mCustomHitPoints; private final ChangeTrackedLiveData mCustomArmor; private final ChangeTrackedLiveData mCustomSpeed; + private final ChangeTrackedLiveData mChallengeRating; + private final ChangeTrackedLiveData mCustomChallengeRatingDescription; + private final ChangeTrackedLiveData mCustomProficiencyBonus; + private final ChangeTrackedLiveData mBlindsightRange; + private final ChangeTrackedLiveData mIsBlindBeyondBlindsightRange; + private final ChangeTrackedLiveData mDarkvisionRange; + private final ChangeTrackedLiveData mTremorsenseRange; + private final ChangeTrackedLiveData mTruesightRange; + private final ChangeTrackedLiveData mTelepathyRange; + private final ChangeTrackedLiveData mUnderstandsButDescription; + private final ChangeTrackedLiveData> mSkills; + private final ChangeTrackedLiveData> mDamageImmunities; + private final ChangeTrackedLiveData> mDamageResistances; + private final ChangeTrackedLiveData> mDamageVulnerabilities; + private final ChangeTrackedLiveData> mConditionImmunities; + private final ChangeTrackedLiveData> mLanguages; + private final ChangeTrackedLiveData> mAbilities; + private final ChangeTrackedLiveData> mActions; + private final ChangeTrackedLiveData> mReactions; + private final ChangeTrackedLiveData> mLairActions; + private final ChangeTrackedLiveData> mLegendaryActions; + private final ChangeTrackedLiveData> 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 getChallengeRating() { + return mChallengeRating; + } + + public void setChallengeRating(ChallengeRating challengeRating) { + mChallengeRating.setValue(challengeRating); + } + + public LiveData getCustomChallengeRatingDescription() { + return mCustomChallengeRatingDescription; + } + + public void setCustomChallengeRatingDescription(String customChallengeRatingDescription) { + mCustomChallengeRatingDescription.setValue(customChallengeRatingDescription); + } + + public LiveData 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 getBlindsightRange() { + return mBlindsightRange; + } + + public void setBlindsightRange(int blindsightRange) { + mBlindsightRange.setValue(blindsightRange); + } + + public LiveData getIsBlindBeyondBlindsightRange() { + return mIsBlindBeyondBlindsightRange; + } + + public void setIsBlindBeyondBlindsightRange(boolean isBlindBeyondBlindsightRange) { + mIsBlindBeyondBlindsightRange.setValue(isBlindBeyondBlindsightRange); + } + + public LiveData getDarkvisionRange() { + return mDarkvisionRange; + } + + public void setDarkvisionRange(int darkvisionRange) { + mDarkvisionRange.setValue(darkvisionRange); + } + + public LiveData getTremorsenseRange() { + return mTremorsenseRange; + } + + public void setTremorsenseRange(int tremorsenseRange) { + mTremorsenseRange.setValue(tremorsenseRange); + } + + public LiveData getTruesightRange() { + return mTruesightRange; + } + + public void setTruesightRange(int truesightRange) { + mTruesightRange.setValue(truesightRange); + } + + public LiveData getTelepathyRange() { + return mTelepathyRange; + } + + public void setTelepathyRange(int telepathyRange) { + mTelepathyRange.setValue(telepathyRange); + } + + public LiveData 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; } diff --git a/Android/app/src/main/res/layout/fragment_edit_armor.xml b/Android/app/src/main/res/layout/fragment_edit_armor.xml index 36c4206..765d887 100644 --- a/Android/app/src/main/res/layout/fragment_edit_armor.xml +++ b/Android/app/src/main/res/layout/fragment_edit_armor.xml @@ -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" diff --git a/Android/app/src/main/res/navigation/mobile_navigation.xml b/Android/app/src/main/res/navigation/mobile_navigation.xml index fe6f878..56c5290 100644 --- a/Android/app/src/main/res/navigation/mobile_navigation.xml +++ b/Android/app/src/main/res/navigation/mobile_navigation.xml @@ -87,6 +87,9 @@ + + \ No newline at end of file diff --git a/Android/app/src/main/res/values/strings.xml b/Android/app/src/main/res/values/strings.xml index 9934f06..ad74cda 100644 --- a/Android/app/src/main/res/values/strings.xml +++ b/Android/app/src/main/res/values/strings.xml @@ -28,7 +28,9 @@ Condition Immunities Constitution Custom Armor + Custom CR Custom HP + Custom Proficiency Bonus Custom Speed Damage Immunities Damage Resistances