Adds edit skills view.
This commit is contained in:
@@ -111,6 +111,11 @@ public class EditMonsterFragment extends MCFragment {
|
||||
Navigation.findNavController(requireView()).navigate(action);
|
||||
});
|
||||
|
||||
mHolder.skills.setOnClickListener(v -> {
|
||||
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSkillsFragment();
|
||||
Navigation.findNavController(requireView()).navigate(action);
|
||||
});
|
||||
|
||||
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.majinnaibu.monstercards.data.enums.AbilityScore;
|
||||
import com.majinnaibu.monstercards.data.enums.AdvantageType;
|
||||
import com.majinnaibu.monstercards.data.enums.ArmorType;
|
||||
import com.majinnaibu.monstercards.data.enums.ChallengeRating;
|
||||
@@ -16,7 +17,9 @@ import com.majinnaibu.monstercards.models.Skill;
|
||||
import com.majinnaibu.monstercards.models.Trait;
|
||||
import com.majinnaibu.monstercards.utils.ChangeTrackedLiveData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -76,7 +79,7 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
private final ChangeTrackedLiveData<Integer> mTruesightRange;
|
||||
private final ChangeTrackedLiveData<Integer> mTelepathyRange;
|
||||
private final ChangeTrackedLiveData<String> mUnderstandsButDescription;
|
||||
private final ChangeTrackedLiveData<Set<Skill>> mSkills;
|
||||
private final ChangeTrackedLiveData<List<Skill>> mSkills;
|
||||
private final ChangeTrackedLiveData<Set<String>> mDamageImmunities;
|
||||
private final ChangeTrackedLiveData<Set<String>> mDamageResistances;
|
||||
private final ChangeTrackedLiveData<Set<String>> mDamageVulnerabilities;
|
||||
@@ -146,7 +149,7 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
mTruesightRange = new ChangeTrackedLiveData<>(0, onDirtied);
|
||||
mTelepathyRange = new ChangeTrackedLiveData<>(0, onDirtied);
|
||||
mUnderstandsButDescription = new ChangeTrackedLiveData<>("", onDirtied);
|
||||
mSkills = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
|
||||
mSkills = new ChangeTrackedLiveData<>(new ArrayList<>(), onDirtied);
|
||||
mDamageImmunities = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
|
||||
mDamageResistances = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
|
||||
mDamageVulnerabilities = new ChangeTrackedLiveData<>(new HashSet<>(), onDirtied);
|
||||
@@ -211,7 +214,15 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
mTruesightRange.resetValue(monster.truesightRange);
|
||||
mTelepathyRange.resetValue(monster.telepathyRange);
|
||||
mUnderstandsButDescription.resetValue(monster.understandsButDescription);
|
||||
mSkills.resetValue(monster.skills);
|
||||
|
||||
if (monster.skills.size() == 0) {
|
||||
ArrayList<Skill> skills = new ArrayList<>();
|
||||
skills.add(new Skill("Acrobatics", AbilityScore.STRENGTH));
|
||||
skills.add(new Skill("Stealth", AbilityScore.DEXTERITY));
|
||||
mSkills.resetValue(skills);
|
||||
} else {
|
||||
mSkills.resetValue(new ArrayList<>(monster.skills));
|
||||
}
|
||||
mDamageImmunities.resetValue(monster.damageImmunities);
|
||||
mDamageResistances.resetValue(monster.damageResistances);
|
||||
mDamageVulnerabilities.resetValue(monster.damageVulnerabilities);
|
||||
@@ -794,6 +805,10 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
mUnderstandsButDescription.setValue(understandsButDescription);
|
||||
}
|
||||
|
||||
public LiveData<List<Skill>> getSkills() {
|
||||
return mSkills;
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: add getters and setters for
|
||||
Senses
|
||||
@@ -862,7 +877,7 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
monster.truesightRange = mTruesightRange.getValue();
|
||||
monster.telepathyRange = mTelepathyRange.getValue();
|
||||
monster.understandsButDescription = mUnderstandsButDescription.getValue();
|
||||
monster.skills = mSkills.getValue();
|
||||
monster.skills = new HashSet<>(mSkills.getValue());
|
||||
monster.damageImmunities = mDamageImmunities.getValue();
|
||||
monster.damageResistances = mDamageResistances.getValue();
|
||||
monster.damageVulnerabilities = mDamageVulnerabilities.getValue();
|
||||
@@ -877,4 +892,8 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
|
||||
return monster;
|
||||
}
|
||||
|
||||
public List<Skill> getSkillsArray() {
|
||||
return mSkills.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
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.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavBackStackEntry;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
|
||||
/**
|
||||
* A fragment representing a list of Items.
|
||||
*/
|
||||
public class EditSkillsFragment extends Fragment {
|
||||
private EditMonsterViewModel mViewModel;
|
||||
// private ViewHolder mHolder;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_edit_skills_list, container, false);
|
||||
|
||||
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);
|
||||
|
||||
// Set the adapter
|
||||
if (view instanceof RecyclerView) {
|
||||
Context context = view.getContext();
|
||||
RecyclerView recyclerView = (RecyclerView) view;
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
mViewModel.getSkills().observe(getViewLifecycleOwner(), skills -> recyclerView.setAdapter(new EditSkillsRecyclerViewAdapter(mViewModel.getSkillsArray())));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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.FragmentEditSkillsListItemBinding;
|
||||
import com.majinnaibu.monstercards.models.Skill;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link RecyclerView.Adapter} that can display a {@link Skill}.
|
||||
* TODO: Replace the implementation with code for your data type.
|
||||
*/
|
||||
public class EditSkillsRecyclerViewAdapter extends RecyclerView.Adapter<EditSkillsRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
private final List<Skill> mValues;
|
||||
|
||||
public EditSkillsRecyclerViewAdapter(List<Skill> items) {
|
||||
mValues = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(FragmentEditSkillsListItemBinding.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).name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mValues.size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public final TextView mContentView;
|
||||
public Skill mItem;
|
||||
|
||||
public ViewHolder(FragmentEditSkillsListItemBinding binding) {
|
||||
super(binding.getRoot());
|
||||
mContentView = binding.content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " '" + mContentView.getText() + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
13
app/src/main/res/layout/fragment_edit_skills_list.xml
Normal file
13
app/src/main/res/layout/fragment_edit_skills_list.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView 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:id="@+id/list"
|
||||
android:name="com.majinnaibu.monstercards.ui.editmonster.EditSkillsFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context=".ui.editmonster.EditSkillsFragment"
|
||||
tools:listitem="@layout/fragment_edit_skills_list_item" />
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
@@ -90,6 +90,9 @@
|
||||
<action
|
||||
android:id="@+id/action_editMonsterFragment_to_editChallengeRatingFragment"
|
||||
app:destination="@id/editChallengeRatingFragment" />
|
||||
<action
|
||||
android:id="@+id/action_editMonsterFragment_to_editSkillsFragment"
|
||||
app:destination="@id/editSkillsFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/editBasicInfoFragment"
|
||||
@@ -120,6 +123,11 @@
|
||||
android:name="com.majinnaibu.monstercards.ui.editmonster.EditChallengeRatingFragment"
|
||||
android:label="fragment_edit_challenge_rating"
|
||||
tools:layout="@layout/fragment_edit_challenge_rating" />
|
||||
<fragment
|
||||
android:id="@+id/editSkillsFragment"
|
||||
android:name="com.majinnaibu.monstercards.ui.editmonster.EditSkillsFragment"
|
||||
android:label="fragment_edit_skills_list"
|
||||
tools:layout="@layout/fragment_edit_skills_list" />
|
||||
</navigation>
|
||||
|
||||
</navigation>
|
||||
Reference in New Issue
Block a user