Replaces EditMonsterFragment with a basic ConstraintLayout.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.majinnaibu.monstercards.ui.editmonster;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
|
||||
public class EditMonsterFragment extends Fragment {
|
||||
|
||||
private EditMonsterViewModel mViewModel;
|
||||
|
||||
public static EditMonsterFragment newInstance() {
|
||||
return new EditMonsterFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_edit_monster, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mViewModel = new ViewModelProvider(this).get(EditMonsterViewModel.class);
|
||||
// TODO: Use the ViewModel
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.majinnaibu.monstercards.ui.editmonster;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class EditMonsterViewModel extends ViewModel {
|
||||
// TODO: Implement the ViewModel
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
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() + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user