Adds edit challenge rating screen.

This commit is contained in:
2021-05-31 20:23:39 -07:00
committed by Tom Hicks
parent 153c49fe7b
commit 00463c8092
6 changed files with 36 additions and 22 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,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);
}
}
}
}

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

@@ -729,6 +729,15 @@ public class EditMonsterViewModel extends ViewModel {
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;
}

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>