Adds Edit Monster placeholder fragment.
This commit is contained in:
		| @@ -0,0 +1,72 @@ | ||||
| package com.majinnaibu.monstercards.placeholder; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
|  | ||||
| /** | ||||
|  * Helper class for providing sample content for user interfaces created by | ||||
|  * Android template wizards. | ||||
|  * <p> | ||||
|  * TODO: Replace all uses of this class before publishing your app. | ||||
|  */ | ||||
| public class PlaceholderContent { | ||||
|  | ||||
|     /** | ||||
|      * An array of sample (placeholder) items. | ||||
|      */ | ||||
|     public static final List<PlaceholderItem> ITEMS = new ArrayList<PlaceholderItem>(); | ||||
|  | ||||
|     /** | ||||
|      * A map of sample (placeholder) items, by ID. | ||||
|      */ | ||||
|     public static final Map<String, PlaceholderItem> ITEM_MAP = new HashMap<String, PlaceholderItem>(); | ||||
|  | ||||
|     private static final int COUNT = 25; | ||||
|  | ||||
|     static { | ||||
|         // Add some sample items. | ||||
|         for (int i = 1; i <= COUNT; i++) { | ||||
|             addItem(createPlaceholderItem(i)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void addItem(PlaceholderItem item) { | ||||
|         ITEMS.add(item); | ||||
|         ITEM_MAP.put(item.id, item); | ||||
|     } | ||||
|  | ||||
|     private static PlaceholderItem createPlaceholderItem(int position) { | ||||
|         return new PlaceholderItem(String.valueOf(position), "Item " + position, makeDetails(position)); | ||||
|     } | ||||
|  | ||||
|     private static String makeDetails(int position) { | ||||
|         StringBuilder builder = new StringBuilder(); | ||||
|         builder.append("Details about Item: ").append(position); | ||||
|         for (int i = 0; i < position; i++) { | ||||
|             builder.append("\nMore details information here."); | ||||
|         } | ||||
|         return builder.toString(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * A placeholder item representing a piece of content. | ||||
|      */ | ||||
|     public static class PlaceholderItem { | ||||
|         public final String id; | ||||
|         public final String content; | ||||
|         public final String details; | ||||
|  | ||||
|         public PlaceholderItem(String id, String content, String details) { | ||||
|             this.id = id; | ||||
|             this.content = content; | ||||
|             this.details = details; | ||||
|         } | ||||
|  | ||||
|         @Override | ||||
|         public String toString() { | ||||
|             return content; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,72 @@ | ||||
| package com.majinnaibu.monstercards.ui.monster; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.os.Bundle; | ||||
|  | ||||
| import androidx.fragment.app.Fragment; | ||||
| import androidx.recyclerview.widget.GridLayoutManager; | ||||
| import androidx.recyclerview.widget.LinearLayoutManager; | ||||
| import androidx.recyclerview.widget.RecyclerView; | ||||
|  | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
|  | ||||
| import com.majinnaibu.monstercards.R; | ||||
| import com.majinnaibu.monstercards.placeholder.PlaceholderContent; | ||||
|  | ||||
| /** | ||||
|  * A fragment representing a list of Items. | ||||
|  */ | ||||
| public class EditMonsterFragment extends Fragment { | ||||
|  | ||||
|     // TODO: Customize parameter argument names | ||||
|     private static final String ARG_COLUMN_COUNT = "column-count"; | ||||
|     // TODO: Customize parameters | ||||
|     private int mColumnCount = 1; | ||||
|  | ||||
|     /** | ||||
|      * Mandatory empty constructor for the fragment manager to instantiate the | ||||
|      * fragment (e.g. upon screen orientation changes). | ||||
|      */ | ||||
|     public EditMonsterFragment() { | ||||
|     } | ||||
|  | ||||
|     // TODO: Customize parameter initialization | ||||
|     @SuppressWarnings("unused") | ||||
|     public static EditMonsterFragment newInstance(int columnCount) { | ||||
|         EditMonsterFragment fragment = new EditMonsterFragment(); | ||||
|         Bundle args = new Bundle(); | ||||
|         args.putInt(ARG_COLUMN_COUNT, columnCount); | ||||
|         fragment.setArguments(args); | ||||
|         return fragment; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|  | ||||
|         if (getArguments() != null) { | ||||
|             mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||
|                              Bundle savedInstanceState) { | ||||
|         View view = inflater.inflate(R.layout.fragment_edit_monster_list, container, false); | ||||
|  | ||||
|         // Set the adapter | ||||
|         if (view instanceof RecyclerView) { | ||||
|             Context context = view.getContext(); | ||||
|             RecyclerView recyclerView = (RecyclerView) view; | ||||
|             if (mColumnCount <= 1) { | ||||
|                 recyclerView.setLayoutManager(new LinearLayoutManager(context)); | ||||
|             } else { | ||||
|                 recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); | ||||
|             } | ||||
|             recyclerView.setAdapter(new EditMonsterRecyclerViewAdapter(PlaceholderContent.ITEMS)); | ||||
|         } | ||||
|         return view; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,61 @@ | ||||
| package com.majinnaibu.monstercards.ui.monster; | ||||
|  | ||||
| import androidx.recyclerview.widget.RecyclerView; | ||||
|  | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.TextView; | ||||
|  | ||||
| import com.majinnaibu.monstercards.placeholder.PlaceholderContent.PlaceholderItem; | ||||
| import com.majinnaibu.monstercards.databinding.FragmentEditMonsterBinding; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * {@link RecyclerView.Adapter} that can display a {@link PlaceholderItem}. | ||||
|  * TODO: Replace the implementation with code for your data type. | ||||
|  */ | ||||
| public class EditMonsterRecyclerViewAdapter extends RecyclerView.Adapter<EditMonsterRecyclerViewAdapter.ViewHolder> { | ||||
|  | ||||
|     private final List<PlaceholderItem> mValues; | ||||
|  | ||||
|     public EditMonsterRecyclerViewAdapter(List<PlaceholderItem> items) { | ||||
|         mValues = items; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||||
|  | ||||
|         return new ViewHolder(FragmentEditMonsterBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onBindViewHolder(final ViewHolder holder, int position) { | ||||
|         holder.mItem = mValues.get(position); | ||||
|         holder.mIdView.setText(mValues.get(position).id); | ||||
|         holder.mContentView.setText(mValues.get(position).content); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getItemCount() { | ||||
|         return mValues.size(); | ||||
|     } | ||||
|  | ||||
|     public class ViewHolder extends RecyclerView.ViewHolder { | ||||
|         public final TextView mIdView; | ||||
|         public final TextView mContentView; | ||||
|         public PlaceholderItem mItem; | ||||
|  | ||||
|         public ViewHolder(FragmentEditMonsterBinding binding) { | ||||
|             super(binding.getRoot()); | ||||
|             mIdView = binding.itemNumber; | ||||
|             mContentView = binding.content; | ||||
|         } | ||||
|  | ||||
|         @Override | ||||
|         public String toString() { | ||||
|             return super.toString() + " '" + mContentView.getText() + "'"; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -10,14 +10,16 @@ import android.util.TypedValue; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuInflater; | ||||
| import android.view.MenuItem; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.LinearLayout; | ||||
| import android.widget.TextView; | ||||
|  | ||||
| import androidx.annotation.NonNull; | ||||
| import androidx.annotation.Nullable; | ||||
| import androidx.lifecycle.ViewModelProvider; | ||||
| import androidx.navigation.NavDirections; | ||||
| import androidx.navigation.Navigation; | ||||
|  | ||||
| import com.majinnaibu.monstercards.R; | ||||
| import com.majinnaibu.monstercards.data.MonsterRepository; | ||||
| @@ -235,4 +237,16 @@ public class MonsterDetailFragment extends MCFragment { | ||||
|         inflater.inflate(R.menu.monster_detail_menu, menu); | ||||
|         super.onCreateOptionsMenu(menu, inflater); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean onOptionsItemSelected(@NonNull MenuItem item) { | ||||
|         if (item.getItemId() == R.id.menu_action_edit_monster) { | ||||
|             NavDirections action = MonsterDetailFragmentDirections.actionNavigationMonsterToEditMonsterFragment(monsterDetailViewModel.getId().toString()); | ||||
|             View view = getView(); | ||||
|             assert view != null; | ||||
|             Navigation.findNavController(view).navigate(action); | ||||
|             return true; | ||||
|         } | ||||
|         return super.onOptionsItemSelected(item); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import com.majinnaibu.monstercards.models.Monster; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.UUID; | ||||
|  | ||||
| public class MonsterDetailViewModel extends ViewModel { | ||||
|  | ||||
| @@ -57,6 +58,8 @@ public class MonsterDetailViewModel extends ViewModel { | ||||
|         mStrength.setValue(""); | ||||
|         mWisdom = new MutableLiveData<>(); | ||||
|         mWisdom.setValue(""); | ||||
|         mMonsterId = new MutableLiveData<>(); | ||||
|         mMonsterId.setValue(UUID.fromString("00000000-0000-0000-0000-000000000000")); | ||||
|     } | ||||
|  | ||||
|     private final MutableLiveData<List<String>> mAbilities; | ||||
| @@ -191,6 +194,12 @@ public class MonsterDetailViewModel extends ViewModel { | ||||
|         return mWisdom; | ||||
|     } | ||||
|  | ||||
|     private final MutableLiveData<UUID> mMonsterId; | ||||
|  | ||||
|     public LiveData<UUID> getId() { | ||||
|         return mMonsterId; | ||||
|     } | ||||
|  | ||||
|     private Monster mMonster; | ||||
|  | ||||
|     public void setMonster(Monster monster) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user