Adds edit challenge rating screen.
This commit is contained in:
		| @@ -12,6 +12,7 @@ import android.widget.TextView; | |||||||
|  |  | ||||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||||
| import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||||
|  | import androidx.fragment.app.Fragment; | ||||||
| import androidx.lifecycle.ViewModelProvider; | import androidx.lifecycle.ViewModelProvider; | ||||||
| import androidx.navigation.NavBackStackEntry; | import androidx.navigation.NavBackStackEntry; | ||||||
| import androidx.navigation.NavController; | import androidx.navigation.NavController; | ||||||
| @@ -20,19 +21,20 @@ import androidx.navigation.Navigation; | |||||||
| import com.majinnaibu.monstercards.R; | import com.majinnaibu.monstercards.R; | ||||||
| import com.majinnaibu.monstercards.data.enums.ChallengeRating; | import com.majinnaibu.monstercards.data.enums.ChallengeRating; | ||||||
| import com.majinnaibu.monstercards.helpers.ArrayHelper; | import com.majinnaibu.monstercards.helpers.ArrayHelper; | ||||||
| import com.majinnaibu.monstercards.ui.shared.MCFragment; |  | ||||||
| import com.majinnaibu.monstercards.utils.TextChangedListener; | import com.majinnaibu.monstercards.utils.TextChangedListener; | ||||||
|  |  | ||||||
| public class EditChallengeRatingFragment extends MCFragment { | public class EditChallengeRatingFragment extends Fragment { | ||||||
|     private EditMonsterViewModel mViewModel; |     private EditMonsterViewModel mViewModel; | ||||||
|     private ViewHolder mHolder; |     private ViewHolder mHolder; | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, |     public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||||
|                              Bundle savedInstanceState) { |                              Bundle savedInstanceState) { | ||||||
|         NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment); |         NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment); | ||||||
|         NavBackStackEntry backStackEntry = navController.getBackStackEntry(R.id.edit_monster_navigation); |         NavBackStackEntry backStackEntry = navController.getBackStackEntry(R.id.edit_monster_navigation); | ||||||
|         mViewModel = new ViewModelProvider(backStackEntry).get(EditMonsterViewModel.class); |         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); |         View root = inflater.inflate(R.layout.fragment_edit_challenge_rating, container, false); | ||||||
|         mHolder = new ViewHolder(root); |         mHolder = new ViewHolder(root); | ||||||
|  |  | ||||||
| @@ -82,7 +84,7 @@ public class EditChallengeRatingFragment extends MCFragment { | |||||||
|         final EditText customChallengeRatingDescription; |         final EditText customChallengeRatingDescription; | ||||||
|         final EditText customProficiencyBonus; |         final EditText customProficiencyBonus; | ||||||
|  |  | ||||||
|         ViewHolder(@NonNull View root) { |         ViewHolder(View root) { | ||||||
|             challengeRating = root.findViewById(R.id.challengeRating); |             challengeRating = root.findViewById(R.id.challengeRating); | ||||||
|             customChallengeRatingDescription = root.findViewById(R.id.customChallengeRatingDescription); |             customChallengeRatingDescription = root.findViewById(R.id.customChallengeRatingDescription); | ||||||
|             customProficiencyBonus = root.findViewById(R.id.customProficiencyBonus); |             customProficiencyBonus = root.findViewById(R.id.customProficiencyBonus); | ||||||
|   | |||||||
| @@ -83,37 +83,32 @@ public class EditMonsterFragment extends MCFragment { | |||||||
|  |  | ||||||
|         mHolder.basicInfoButton.setOnClickListener(v -> { |         mHolder.basicInfoButton.setOnClickListener(v -> { | ||||||
|             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditBasicInfoFragment(); |             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditBasicInfoFragment(); | ||||||
|             View view = getView(); |             Navigation.findNavController(requireView()).navigate(action); | ||||||
|             assert view != null; |  | ||||||
|             Navigation.findNavController(view).navigate(action); |  | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         mHolder.armorButton.setOnClickListener(v -> { |         mHolder.armorButton.setOnClickListener(v -> { | ||||||
|             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditArmorFragment(); |             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditArmorFragment(); | ||||||
|             View view = getView(); |             Navigation.findNavController(requireView()).navigate(action); | ||||||
|             assert view != null; |  | ||||||
|             Navigation.findNavController(view).navigate(action); |  | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         mHolder.speedButton.setOnClickListener(v -> { |         mHolder.speedButton.setOnClickListener(v -> { | ||||||
|             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSpeedFragment(); |             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSpeedFragment(); | ||||||
|             View view = getView(); |             Navigation.findNavController(requireView()).navigate(action); | ||||||
|             assert view != null; |  | ||||||
|             Navigation.findNavController(view).navigate(action); |  | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         mHolder.abilityScoresButton.setOnClickListener(v -> { |         mHolder.abilityScoresButton.setOnClickListener(v -> { | ||||||
|             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditAbilityScoresFragment(); |             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditAbilityScoresFragment(); | ||||||
|             View view = getView(); |             Navigation.findNavController(requireView()).navigate(action); | ||||||
|             assert view != null; |  | ||||||
|             Navigation.findNavController(view).navigate(action); |  | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         mHolder.savingThrows.setOnClickListener(v -> { |         mHolder.savingThrows.setOnClickListener(v -> { | ||||||
|             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSavingThrowsFragment(); |             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSavingThrowsFragment(); | ||||||
|             View view = getView(); |             Navigation.findNavController(requireView()).navigate(action); | ||||||
|             assert view != null; |         }); | ||||||
|             Navigation.findNavController(view).navigate(action); |  | ||||||
|  |         mHolder.challengeRating.setOnClickListener(v -> { | ||||||
|  |             NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditChallengeRatingFragment(); | ||||||
|  |             Navigation.findNavController(requireView()).navigate(action); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) { |         requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) { | ||||||
|   | |||||||
| @@ -729,6 +729,15 @@ public class EditMonsterViewModel extends ViewModel { | |||||||
|         mCustomProficiencyBonus.setValue(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() { |     public LiveData<Integer> getBlindsightRange() { | ||||||
|         return mBlindsightRange; |         return mBlindsightRange; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -24,7 +24,6 @@ | |||||||
|                 android:id="@+id/naturalArmorBonus" |                 android:id="@+id/naturalArmorBonus" | ||||||
|                 android:layout_width="match_parent" |                 android:layout_width="match_parent" | ||||||
|                 android:layout_height="wrap_content" |                 android:layout_height="wrap_content" | ||||||
|                 android:digits="0123456789" |  | ||||||
|                 android:hint="@string/label_natural_armor_bonus" |                 android:hint="@string/label_natural_armor_bonus" | ||||||
|                 android:importantForAutofill="no" |                 android:importantForAutofill="no" | ||||||
|                 android:inputType="numberSigned" |                 android:inputType="numberSigned" | ||||||
| @@ -48,7 +47,6 @@ | |||||||
|                 android:id="@+id/shieldBonus" |                 android:id="@+id/shieldBonus" | ||||||
|                 android:layout_width="match_parent" |                 android:layout_width="match_parent" | ||||||
|                 android:layout_height="wrap_content" |                 android:layout_height="wrap_content" | ||||||
|                 android:digits="0123456789" |  | ||||||
|                 android:hint="@string/label_shield_bonus" |                 android:hint="@string/label_shield_bonus" | ||||||
|                 android:importantForAutofill="no" |                 android:importantForAutofill="no" | ||||||
|                 android:inputType="numberSigned" |                 android:inputType="numberSigned" | ||||||
|   | |||||||
| @@ -87,6 +87,9 @@ | |||||||
|             <action |             <action | ||||||
|                 android:id="@+id/action_editMonsterFragment_to_editSavingThrowsFragment" |                 android:id="@+id/action_editMonsterFragment_to_editSavingThrowsFragment" | ||||||
|                 app:destination="@id/editSavingThrowsFragment" /> |                 app:destination="@id/editSavingThrowsFragment" /> | ||||||
|  |             <action | ||||||
|  |                 android:id="@+id/action_editMonsterFragment_to_editChallengeRatingFragment" | ||||||
|  |                 app:destination="@id/editChallengeRatingFragment" /> | ||||||
|         </fragment> |         </fragment> | ||||||
|         <fragment |         <fragment | ||||||
|             android:id="@+id/editBasicInfoFragment" |             android:id="@+id/editBasicInfoFragment" | ||||||
| @@ -112,6 +115,11 @@ | |||||||
|             android:name="com.majinnaibu.monstercards.ui.editmonster.EditSavingThrowsFragment" |             android:name="com.majinnaibu.monstercards.ui.editmonster.EditSavingThrowsFragment" | ||||||
|             android:label="fragment_edit_saving_throws" |             android:label="fragment_edit_saving_throws" | ||||||
|             tools:layout="@layout/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> | ||||||
|  |  | ||||||
| </navigation> | </navigation> | ||||||
| @@ -28,7 +28,9 @@ | |||||||
|     <string name="label_condition_immunities">Condition Immunities</string> |     <string name="label_condition_immunities">Condition Immunities</string> | ||||||
|     <string name="label_constitution">Constitution</string> |     <string name="label_constitution">Constitution</string> | ||||||
|     <string name="label_custom_armor">Custom Armor</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_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_custom_speed">Custom Speed</string> | ||||||
|     <string name="label_damage_immunities">Damage Immunities</string> |     <string name="label_damage_immunities">Damage Immunities</string> | ||||||
|     <string name="label_damage_resistances">Damage Resistances</string> |     <string name="label_damage_resistances">Damage Resistances</string> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tom Hicks
						Tom Hicks