Adds stubbed out method to navigate to the edit skill fragment.
Adds a click handler to the edit skills recycler view adapter. Makes tapping a skill in the edit skills view navigate to the editor for that skill. Makes adding a new skill immediately edit the skill.
This commit is contained in:
		| @@ -19,7 +19,9 @@ import androidx.recyclerview.widget.RecyclerView; | |||||||
|  |  | ||||||
| import com.google.android.material.floatingactionbutton.FloatingActionButton; | import com.google.android.material.floatingactionbutton.FloatingActionButton; | ||||||
| import com.majinnaibu.monstercards.R; | import com.majinnaibu.monstercards.R; | ||||||
|  | import com.majinnaibu.monstercards.models.Skill; | ||||||
| import com.majinnaibu.monstercards.ui.shared.SwipeToDeleteCallback; | import com.majinnaibu.monstercards.ui.shared.SwipeToDeleteCallback; | ||||||
|  | import com.majinnaibu.monstercards.utils.Logger; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * A fragment representing a list of Items. |  * A fragment representing a list of Items. | ||||||
| @@ -29,6 +31,10 @@ public class EditSkillsFragment extends Fragment { | |||||||
|     private EditMonsterViewModel mViewModel; |     private EditMonsterViewModel mViewModel; | ||||||
|     private ViewHolder mHolder; |     private ViewHolder mHolder; | ||||||
|  |  | ||||||
|  |     private void navigateToEditSkill(Skill skill) { | ||||||
|  |         Logger.logUnimplementedFeature("Navigate to the edit skill fragment."); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public View onCreateView(LayoutInflater inflater, ViewGroup container, |     public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||||
|                              Bundle savedInstanceState) { |                              Bundle savedInstanceState) { | ||||||
| @@ -51,7 +57,13 @@ public class EditSkillsFragment extends Fragment { | |||||||
|         recyclerView.setLayoutManager(layoutManager); |         recyclerView.setLayoutManager(layoutManager); | ||||||
|  |  | ||||||
|         mViewModel.getSkills().observe(getViewLifecycleOwner(), skills -> { |         mViewModel.getSkills().observe(getViewLifecycleOwner(), skills -> { | ||||||
|             EditSkillsRecyclerViewAdapter adapter = new EditSkillsRecyclerViewAdapter(mViewModel.getSkillsArray(), null); |             EditSkillsRecyclerViewAdapter adapter = new EditSkillsRecyclerViewAdapter(mViewModel.getSkillsArray(), skill -> { | ||||||
|  |                 if (skill != null) { | ||||||
|  |                     navigateToEditSkill(skill); | ||||||
|  |                 } else { | ||||||
|  |                     Logger.logError("Can't navigate to EditSkill with a null skill"); | ||||||
|  |                 } | ||||||
|  |             }, null); | ||||||
|             recyclerView.setAdapter(adapter); |             recyclerView.setAdapter(adapter); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
| @@ -64,12 +76,8 @@ public class EditSkillsFragment extends Fragment { | |||||||
|  |  | ||||||
|     private void setupAddSkillButton(@NonNull FloatingActionButton fab) { |     private void setupAddSkillButton(@NonNull FloatingActionButton fab) { | ||||||
|         fab.setOnClickListener(view -> { |         fab.setOnClickListener(view -> { | ||||||
|             mViewModel.addNewSkill(); |             Skill newSkill = mViewModel.addNewSkill(); | ||||||
|             // TODO: navigate to editing the new skill |             navigateToEditSkill(newSkill); | ||||||
| //            NavDirections action = MonsterDetailFragmentDirections.actionNavigationMonsterToEditMonsterFragment(monsterDetailViewModel.getId().getValue().toString()); |  | ||||||
| //            View view = getView(); |  | ||||||
| //            assert view != null; |  | ||||||
| //            Navigation.findNavController(view).navigate(action); |  | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,9 +17,11 @@ import java.util.List; | |||||||
| public class EditSkillsRecyclerViewAdapter extends RecyclerView.Adapter<EditSkillsRecyclerViewAdapter.ViewHolder> { | public class EditSkillsRecyclerViewAdapter extends RecyclerView.Adapter<EditSkillsRecyclerViewAdapter.ViewHolder> { | ||||||
|     private final List<Skill> mValues; |     private final List<Skill> mValues; | ||||||
|     private final ItemCallback mOnDelete; |     private final ItemCallback mOnDelete; | ||||||
|  |     private final ItemCallback mOnClick; | ||||||
|  |  | ||||||
|     public EditSkillsRecyclerViewAdapter(List<Skill> items, ItemCallback onDelete) { |     public EditSkillsRecyclerViewAdapter(List<Skill> items, ItemCallback onClick, ItemCallback onDelete) { | ||||||
|         mValues = items; |         mValues = items; | ||||||
|  |         mOnClick = onClick; | ||||||
|         mOnDelete = onDelete; |         mOnDelete = onDelete; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -32,6 +34,11 @@ public class EditSkillsRecyclerViewAdapter extends RecyclerView.Adapter<EditSkil | |||||||
|     public void onBindViewHolder(final ViewHolder holder, int position) { |     public void onBindViewHolder(final ViewHolder holder, int position) { | ||||||
|         holder.mItem = mValues.get(position); |         holder.mItem = mValues.get(position); | ||||||
|         holder.mContentView.setText(mValues.get(position).name); |         holder.mContentView.setText(mValues.get(position).name); | ||||||
|  |         holder.itemView.setOnClickListener(v -> { | ||||||
|  |             if (mOnClick != null) { | ||||||
|  |                 mOnClick.onItemCallback(holder.mItem); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user