Replaces EditMonsterFragment with a basic ConstraintLayout.
This commit is contained in:
@@ -78,6 +78,8 @@ dependencies {
|
|||||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||||
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
|
||||||
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
|||||||
@@ -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() + "'";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="wrap_content"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="wrap_content"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:orientation="horizontal">
|
android:id="@+id/frameLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.editmonster.EditMonsterFragment">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/item_number"
|
android:id="@+id/textView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:layout_margin="@dimen/text_margin"
|
android:text="Edit Monster"
|
||||||
android:textAppearance="?attr/textAppearanceListItem" />
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<TextView
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
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>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<?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.EditMonsterFragment"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginLeft="16dp"
|
|
||||||
android:layout_marginRight="16dp"
|
|
||||||
app:layoutManager="LinearLayoutManager"
|
|
||||||
tools:context=".ui.monster.EditMonsterFragment"
|
|
||||||
tools:listitem="@layout/fragment_edit_monster" />
|
|
||||||
@@ -59,9 +59,9 @@
|
|||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/editMonsterFragment"
|
android:id="@+id/editMonsterFragment"
|
||||||
android:name="com.majinnaibu.monstercards.ui.monster.EditMonsterFragment"
|
android:name="com.majinnaibu.monstercards.ui.editmonster.EditMonsterFragment"
|
||||||
android:label="fragment_edit_monster_list"
|
android:label="fragment_edit_monster"
|
||||||
tools:layout="@layout/fragment_edit_monster_list" >
|
tools:layout="@layout/fragment_edit_monster" >
|
||||||
<argument
|
<argument
|
||||||
android:name="monster_id"
|
android:name="monster_id"
|
||||||
app:argType="string" />
|
app:argType="string" />
|
||||||
|
|||||||
Reference in New Issue
Block a user