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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user