Add damage resistances and damage vulnerabilities to the monster editor.
This commit is contained in:
@@ -0,0 +1,92 @@
|
|||||||
|
package com.majinnaibu.monstercards.ui.editmonster;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.navigation.NavBackStackEntry;
|
||||||
|
import androidx.navigation.NavController;
|
||||||
|
import androidx.navigation.NavDirections;
|
||||||
|
import androidx.navigation.Navigation;
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.majinnaibu.monstercards.R;
|
||||||
|
import com.majinnaibu.monstercards.ui.shared.MCFragment;
|
||||||
|
import com.majinnaibu.monstercards.ui.shared.SwipeToDeleteCallback;
|
||||||
|
import com.majinnaibu.monstercards.utils.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A fragment representing a list of Items.
|
||||||
|
*/
|
||||||
|
public class EditDamageImmunitiesFragment extends MCFragment {
|
||||||
|
private EditMonsterViewModel mViewModel;
|
||||||
|
private ViewHolder mHolder;
|
||||||
|
|
||||||
|
private void navigateToEditDamageImmunity(String damageImmunity) {
|
||||||
|
NavDirections action = EditDamageImmunitiesFragmentDirections.actionEditDamageImmunitiesFragmentToEditDamageImmunityFragment(damageImmunity);
|
||||||
|
View view = getView();
|
||||||
|
assert view != null;
|
||||||
|
Navigation.findNavController(view).navigate(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
View root = inflater.inflate(R.layout.fragment_edit_damage_immunities_list, container, false);
|
||||||
|
mHolder = new ViewHolder(root);
|
||||||
|
setupRecyclerView(mHolder.list);
|
||||||
|
setupAddDamageImmunityButton(mHolder.addDamageImmunity);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
|
Context context = requireContext();
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
||||||
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
mViewModel.getDamageImmunities().observe(getViewLifecycleOwner(), damageImmunities -> {
|
||||||
|
EditDamageImmunitiesRecyclerViewAdapter adapter = new EditDamageImmunitiesRecyclerViewAdapter(mViewModel.getDamageImmunitiesArray(), damageImmunity -> {
|
||||||
|
if (damageImmunity != null) {
|
||||||
|
navigateToEditDamageImmunity(damageImmunity);
|
||||||
|
} else {
|
||||||
|
Logger.logError("Can't navigate to EditDamageImmunity with a null damageImmunity");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
});
|
||||||
|
|
||||||
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(context, layoutManager.getOrientation());
|
||||||
|
recyclerView.addItemDecoration(dividerItemDecoration);
|
||||||
|
|
||||||
|
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new SwipeToDeleteCallback(context, mViewModel::removeDamageImmunity));
|
||||||
|
itemTouchHelper.attachToRecyclerView(recyclerView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupAddDamageImmunityButton(@NonNull FloatingActionButton fab) {
|
||||||
|
fab.setOnClickListener(view -> {
|
||||||
|
String newDamageImmunity = mViewModel.addNewDamageImmunity();
|
||||||
|
navigateToEditDamageImmunity(newDamageImmunity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
RecyclerView list;
|
||||||
|
FloatingActionButton addDamageImmunity;
|
||||||
|
|
||||||
|
ViewHolder(View root) {
|
||||||
|
list = root.findViewById(R.id.list);
|
||||||
|
addDamageImmunity = root.findViewById(R.id.add_damage_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.majinnaibu.monstercards.ui.editmonster;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.majinnaibu.monstercards.databinding.FragmentEditDamageImmunitiesListItemBinding;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* x
|
||||||
|
* {@link RecyclerView.Adapter} that can display a {@link String}.
|
||||||
|
*/
|
||||||
|
public class EditDamageImmunitiesRecyclerViewAdapter extends RecyclerView.Adapter<EditDamageImmunitiesRecyclerViewAdapter.ViewHolder> {
|
||||||
|
private final List<String> mValues;
|
||||||
|
private final ItemCallback mOnClick;
|
||||||
|
|
||||||
|
public EditDamageImmunitiesRecyclerViewAdapter(List<String> items, ItemCallback onClick) {
|
||||||
|
mValues = items;
|
||||||
|
mOnClick = onClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
|
||||||
|
return new ViewHolder(FragmentEditDamageImmunitiesListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||||
|
holder.mItem = mValues.get(position);
|
||||||
|
holder.mContentView.setText(mValues.get(position));
|
||||||
|
holder.itemView.setOnClickListener(v -> {
|
||||||
|
if (mOnClick != null) {
|
||||||
|
mOnClick.onItemCallback(holder.mItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mValues.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ItemCallback {
|
||||||
|
void onItemCallback(String sense);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
public final TextView mContentView;
|
||||||
|
public String mItem;
|
||||||
|
|
||||||
|
public ViewHolder(FragmentEditDamageImmunitiesListItemBinding binding) {
|
||||||
|
super(binding.getRoot());
|
||||||
|
mContentView = binding.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " '" + mContentView.getText() + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.majinnaibu.monstercards.ui.editmonster;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.navigation.NavBackStackEntry;
|
||||||
|
import androidx.navigation.NavController;
|
||||||
|
import androidx.navigation.Navigation;
|
||||||
|
|
||||||
|
import com.majinnaibu.monstercards.R;
|
||||||
|
import com.majinnaibu.monstercards.ui.shared.MCFragment;
|
||||||
|
import com.majinnaibu.monstercards.utils.Logger;
|
||||||
|
import com.majinnaibu.monstercards.utils.TextChangedListener;
|
||||||
|
|
||||||
|
public class EditDamageImmunityFragment extends MCFragment {
|
||||||
|
private EditMonsterViewModel mEditMonsterViewModel;
|
||||||
|
private EditStringViewModel mViewModel;
|
||||||
|
private EditDamageImmunityFragment.ViewHolder mHolder;
|
||||||
|
private String mOldDamageImmunity;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
mViewModel = new ViewModelProvider(this).get(EditStringViewModel.class);
|
||||||
|
if (getArguments() != null) {
|
||||||
|
EditDamageImmunityFragmentArgs args = EditDamageImmunityFragmentArgs.fromBundle(getArguments());
|
||||||
|
mOldDamageImmunity = args.getDamageType();
|
||||||
|
mViewModel.resetValue(mOldDamageImmunity);
|
||||||
|
} else {
|
||||||
|
Logger.logWTF("EditDamageImmunityFragment needs arguments");
|
||||||
|
mOldDamageImmunity = null;
|
||||||
|
}
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
|
||||||
|
NavBackStackEntry backStackEntry = navController.getBackStackEntry(R.id.edit_monster_navigation);
|
||||||
|
mEditMonsterViewModel = new ViewModelProvider(backStackEntry).get(EditMonsterViewModel.class);
|
||||||
|
|
||||||
|
View root = inflater.inflate(R.layout.fragment_edit_damage_immunity, container, false);
|
||||||
|
|
||||||
|
mHolder = new EditDamageImmunityFragment.ViewHolder(root);
|
||||||
|
|
||||||
|
mHolder.value.setText(mViewModel.getValueAsString());
|
||||||
|
mHolder.value.addTextChangedListener(new TextChangedListener((TextChangedListener.OnTextChangedCallback) (s, start, before, count) -> mViewModel.setValue(s.toString())));
|
||||||
|
|
||||||
|
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
if (mViewModel.hasChanges()) {
|
||||||
|
mEditMonsterViewModel.replaceDamageImmunity(mOldDamageImmunity, mViewModel.getValueAsString());
|
||||||
|
}
|
||||||
|
Navigation.findNavController(requireView()).navigateUp();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
EditText value;
|
||||||
|
|
||||||
|
ViewHolder(View root) {
|
||||||
|
value = root.findViewById(R.id.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.majinnaibu.monstercards.ui.editmonster;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.navigation.NavBackStackEntry;
|
||||||
|
import androidx.navigation.NavController;
|
||||||
|
import androidx.navigation.NavDirections;
|
||||||
|
import androidx.navigation.Navigation;
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.majinnaibu.monstercards.R;
|
||||||
|
import com.majinnaibu.monstercards.ui.shared.MCFragment;
|
||||||
|
import com.majinnaibu.monstercards.ui.shared.SwipeToDeleteCallback;
|
||||||
|
import com.majinnaibu.monstercards.utils.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A fragment representing a list of Items.
|
||||||
|
*/
|
||||||
|
public class EditDamageVulnerabilitiesFragment extends MCFragment {
|
||||||
|
private EditMonsterViewModel mViewModel;
|
||||||
|
private ViewHolder mHolder;
|
||||||
|
|
||||||
|
private void navigateToEditDamageVulnerability(String damageVulnerability) {
|
||||||
|
NavDirections action = EditDamageVulnerabilitiesFragmentDirections.actionEditDamageVulnerabilitiesFragmentToEditDamageVulnerabilityFragment(damageVulnerability);
|
||||||
|
View view = getView();
|
||||||
|
assert view != null;
|
||||||
|
Navigation.findNavController(view).navigate(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
View root = inflater.inflate(R.layout.fragment_edit_damage_vulnerabilities_list, container, false);
|
||||||
|
mHolder = new ViewHolder(root);
|
||||||
|
setupRecyclerView(mHolder.list);
|
||||||
|
setupAddDamageVulnerabilityButton(mHolder.addDamageVulnerability);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
|
Context context = requireContext();
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
||||||
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
mViewModel.getDamageVulnerabilities().observe(getViewLifecycleOwner(), damageVulnerabilities -> {
|
||||||
|
EditDamageVulnerabilitiesRecyclerViewAdapter adapter = new EditDamageVulnerabilitiesRecyclerViewAdapter(mViewModel.getDamageVulnerabilitiesArray(), damageVulnerability -> {
|
||||||
|
if (damageVulnerability != null) {
|
||||||
|
navigateToEditDamageVulnerability(damageVulnerability);
|
||||||
|
} else {
|
||||||
|
Logger.logError("Can't navigate to EditDamageVulnerability with a null damageVulnerability");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
});
|
||||||
|
|
||||||
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(context, layoutManager.getOrientation());
|
||||||
|
recyclerView.addItemDecoration(dividerItemDecoration);
|
||||||
|
|
||||||
|
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new SwipeToDeleteCallback(context, mViewModel::removeDamageVulnerability));
|
||||||
|
itemTouchHelper.attachToRecyclerView(recyclerView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupAddDamageVulnerabilityButton(@NonNull FloatingActionButton fab) {
|
||||||
|
fab.setOnClickListener(view -> {
|
||||||
|
String newDamageVulnerability = mViewModel.addNewDamageVulnerability();
|
||||||
|
navigateToEditDamageVulnerability(newDamageVulnerability);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
RecyclerView list;
|
||||||
|
FloatingActionButton addDamageVulnerability;
|
||||||
|
|
||||||
|
ViewHolder(View root) {
|
||||||
|
list = root.findViewById(R.id.list);
|
||||||
|
addDamageVulnerability = root.findViewById(R.id.add_damage_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.majinnaibu.monstercards.ui.editmonster;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.majinnaibu.monstercards.databinding.FragmentEditDamageVulnerabilitiesListItemBinding;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* x
|
||||||
|
* {@link RecyclerView.Adapter} that can display a {@link String}.
|
||||||
|
*/
|
||||||
|
public class EditDamageVulnerabilitiesRecyclerViewAdapter extends RecyclerView.Adapter<EditDamageVulnerabilitiesRecyclerViewAdapter.ViewHolder> {
|
||||||
|
private final List<String> mValues;
|
||||||
|
private final ItemCallback mOnClick;
|
||||||
|
|
||||||
|
public EditDamageVulnerabilitiesRecyclerViewAdapter(List<String> items, ItemCallback onClick) {
|
||||||
|
mValues = items;
|
||||||
|
mOnClick = onClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
|
||||||
|
return new ViewHolder(FragmentEditDamageVulnerabilitiesListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||||
|
holder.mItem = mValues.get(position);
|
||||||
|
holder.mContentView.setText(mValues.get(position));
|
||||||
|
holder.itemView.setOnClickListener(v -> {
|
||||||
|
if (mOnClick != null) {
|
||||||
|
mOnClick.onItemCallback(holder.mItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mValues.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ItemCallback {
|
||||||
|
void onItemCallback(String sense);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
public final TextView mContentView;
|
||||||
|
public String mItem;
|
||||||
|
|
||||||
|
public ViewHolder(FragmentEditDamageVulnerabilitiesListItemBinding binding) {
|
||||||
|
super(binding.getRoot());
|
||||||
|
mContentView = binding.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " '" + mContentView.getText() + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.majinnaibu.monstercards.ui.editmonster;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.navigation.NavBackStackEntry;
|
||||||
|
import androidx.navigation.NavController;
|
||||||
|
import androidx.navigation.Navigation;
|
||||||
|
|
||||||
|
import com.majinnaibu.monstercards.R;
|
||||||
|
import com.majinnaibu.monstercards.ui.shared.MCFragment;
|
||||||
|
import com.majinnaibu.monstercards.utils.Logger;
|
||||||
|
import com.majinnaibu.monstercards.utils.TextChangedListener;
|
||||||
|
|
||||||
|
public class EditDamageVulnerabilityFragment extends MCFragment {
|
||||||
|
private EditMonsterViewModel mEditMonsterViewModel;
|
||||||
|
private EditStringViewModel mViewModel;
|
||||||
|
private EditDamageVulnerabilityFragment.ViewHolder mHolder;
|
||||||
|
private String mOldDamageVulnerability;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
mViewModel = new ViewModelProvider(this).get(EditStringViewModel.class);
|
||||||
|
if (getArguments() != null) {
|
||||||
|
EditDamageVulnerabilityFragmentArgs args = EditDamageVulnerabilityFragmentArgs.fromBundle(getArguments());
|
||||||
|
mOldDamageVulnerability = args.getDamageType();
|
||||||
|
mViewModel.resetValue(mOldDamageVulnerability);
|
||||||
|
} else {
|
||||||
|
Logger.logWTF("EditDamageVulnerabilityFragment needs arguments");
|
||||||
|
mOldDamageVulnerability = null;
|
||||||
|
}
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
|
||||||
|
NavBackStackEntry backStackEntry = navController.getBackStackEntry(R.id.edit_monster_navigation);
|
||||||
|
mEditMonsterViewModel = new ViewModelProvider(backStackEntry).get(EditMonsterViewModel.class);
|
||||||
|
|
||||||
|
View root = inflater.inflate(R.layout.fragment_edit_damage_vulnerability, container, false);
|
||||||
|
|
||||||
|
mHolder = new EditDamageVulnerabilityFragment.ViewHolder(root);
|
||||||
|
|
||||||
|
mHolder.value.setText(mViewModel.getValueAsString());
|
||||||
|
mHolder.value.addTextChangedListener(new TextChangedListener((TextChangedListener.OnTextChangedCallback) (s, start, before, count) -> mViewModel.setValue(s.toString())));
|
||||||
|
|
||||||
|
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
if (mViewModel.hasChanges()) {
|
||||||
|
mEditMonsterViewModel.replaceDamageVulnerability(mOldDamageVulnerability, mViewModel.getValueAsString());
|
||||||
|
}
|
||||||
|
Navigation.findNavController(requireView()).navigateUp();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
EditText value;
|
||||||
|
|
||||||
|
ViewHolder(View root) {
|
||||||
|
value = root.findViewById(R.id.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,11 +125,21 @@ public class EditMonsterFragment extends MCFragment {
|
|||||||
Navigation.findNavController(requireView()).navigate(action);
|
Navigation.findNavController(requireView()).navigate(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mHolder.damageImmunities.setOnClickListener(v -> {
|
||||||
|
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditDamageImmunitiesFragment();
|
||||||
|
Navigation.findNavController(requireView()).navigate(action);
|
||||||
|
});
|
||||||
|
|
||||||
mHolder.damageResistances.setOnClickListener(v -> {
|
mHolder.damageResistances.setOnClickListener(v -> {
|
||||||
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditDamageResistancesFragment();
|
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditDamageResistancesFragment();
|
||||||
Navigation.findNavController(requireView()).navigate(action);
|
Navigation.findNavController(requireView()).navigate(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mHolder.damageVulnerabilities.setOnClickListener(v -> {
|
||||||
|
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditDamageVulnerabilitiesFragment();
|
||||||
|
Navigation.findNavController(requireView()).navigate(action);
|
||||||
|
});
|
||||||
|
|
||||||
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||||
@Override
|
@Override
|
||||||
public void handleOnBackPressed() {
|
public void handleOnBackPressed() {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.editmonster.EditDamageResistancesFragment">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:divider="?android:attr/dividerVertical"
|
||||||
|
android:dividerPadding="@dimen/text_margin"
|
||||||
|
app:layoutManager="LinearLayoutManager"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:listitem="@layout/fragment_edit_damage_resistances_list_item" />
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/add_damage_type"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="@dimen/fab_margin"
|
||||||
|
android:contentDescription="@string/add_damage_type"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:srcCompat="@android:drawable/ic_input_add"
|
||||||
|
app:tint="@android:color/white" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/text_margin"
|
||||||
|
android:textAppearance="?attr/textAppearanceListItem" />
|
||||||
|
</LinearLayout>
|
||||||
17
app/src/main/res/layout/fragment_edit_damage_immunity.xml
Normal file
17
app/src/main/res/layout/fragment_edit_damage_immunity.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/text_margin"
|
||||||
|
tools:context=".ui.editmonster.EditDamageResistanceFragment">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/value"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/label_damage_type"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="text"
|
||||||
|
tools:text="bludgeoning" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.editmonster.EditDamageResistancesFragment">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:divider="?android:attr/dividerVertical"
|
||||||
|
android:dividerPadding="@dimen/text_margin"
|
||||||
|
app:layoutManager="LinearLayoutManager"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:listitem="@layout/fragment_edit_damage_resistances_list_item" />
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/add_damage_type"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="@dimen/fab_margin"
|
||||||
|
android:contentDescription="@string/add_damage_type"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:srcCompat="@android:drawable/ic_input_add"
|
||||||
|
app:tint="@android:color/white" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/text_margin"
|
||||||
|
android:textAppearance="?attr/textAppearanceListItem" />
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/text_margin"
|
||||||
|
tools:context=".ui.editmonster.EditDamageResistanceFragment">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/value"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/label_damage_type"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="text"
|
||||||
|
tools:text="bludgeoning" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
@@ -102,6 +102,12 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_editMonsterFragment_to_editDamageResistancesFragment"
|
android:id="@+id/action_editMonsterFragment_to_editDamageResistancesFragment"
|
||||||
app:destination="@id/editDamageResistancesFragment" />
|
app:destination="@id/editDamageResistancesFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_editMonsterFragment_to_editDamageVulnerabilitiesFragment"
|
||||||
|
app:destination="@id/editDamageVulnerabilitiesFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_editMonsterFragment_to_editDamageImmunitiesFragment"
|
||||||
|
app:destination="@id/editDamageImmunitiesFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/editBasicInfoFragment"
|
android:id="@+id/editBasicInfoFragment"
|
||||||
@@ -213,5 +219,37 @@
|
|||||||
android:name="damageType"
|
android:name="damageType"
|
||||||
app:argType="string" />
|
app:argType="string" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/editDamageVulnerabilityFragment"
|
||||||
|
android:name="com.majinnaibu.monstercards.ui.editmonster.EditDamageVulnerabilityFragment"
|
||||||
|
android:label="EditDamageVulnerabilityFragment">
|
||||||
|
<argument
|
||||||
|
android:name="damageType"
|
||||||
|
app:argType="string" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/editDamageImmunitiesFragment"
|
||||||
|
android:name="com.majinnaibu.monstercards.ui.editmonster.EditDamageImmunitiesFragment"
|
||||||
|
android:label="EditDamageImmunitiesFragment">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_editDamageImmunitiesFragment_to_editDamageImmunityFragment"
|
||||||
|
app:destination="@id/editDamageImmunityFragment" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/editDamageImmunityFragment"
|
||||||
|
android:name="com.majinnaibu.monstercards.ui.editmonster.EditDamageImmunityFragment"
|
||||||
|
android:label="EditDamageImmunityFragment">
|
||||||
|
<argument
|
||||||
|
android:name="damageType"
|
||||||
|
app:argType="string" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/editDamageVulnerabilitiesFragment"
|
||||||
|
android:name="com.majinnaibu.monstercards.ui.editmonster.EditDamageVulnerabilitiesFragment"
|
||||||
|
android:label="EditDamageVulnerabilitiesFragment">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_editDamageVulnerabilitiesFragment_to_editDamageVulnerabilityFragment"
|
||||||
|
app:destination="@id/editDamageVulnerabilityFragment" />
|
||||||
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
||||||
</navigation>
|
</navigation>
|
||||||
|
|||||||
Reference in New Issue
Block a user