diff --git a/app/src/main/java/com/example/tampopo_client/views/FriendListFragment.java b/app/src/main/java/com/example/tampopo_client/views/FriendListFragment.java new file mode 100644 index 0000000..b616b19 --- /dev/null +++ b/app/src/main/java/com/example/tampopo_client/views/FriendListFragment.java @@ -0,0 +1,72 @@ +package com.example.tampopo_client.views; + +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.example.tampopo_client.R; +import com.example.tampopo_client.views.placeholder.PlaceholderContent; + +/** + * A fragment representing a list of Items. + */ +public class FriendListFragment 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 FriendListFragment() { + } + + // TODO: Customize parameter initialization + @SuppressWarnings("unused") + public static FriendListFragment newInstance(int columnCount) { + FriendListFragment fragment = new FriendListFragment(); + 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_friend_list_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 MyFriendRecyclerViewAdapter(PlaceholderContent.ITEMS)); + } + return view; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tampopo_client/views/MyFriendRecyclerViewAdapter.java b/app/src/main/java/com/example/tampopo_client/views/MyFriendRecyclerViewAdapter.java new file mode 100644 index 0000000..5ee7ffe --- /dev/null +++ b/app/src/main/java/com/example/tampopo_client/views/MyFriendRecyclerViewAdapter.java @@ -0,0 +1,62 @@ +package com.example.tampopo_client.views; + +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.example.tampopo_client.views.placeholder.PlaceholderContent.PlaceholderItem; +import com.example.tampopo_client.databinding.FragmentFriendListBinding; + +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 MyFriendRecyclerViewAdapter extends RecyclerView.Adapter { + + private final List mValues; + + public MyFriendRecyclerViewAdapter(List items) { + mValues = items; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + + return new ViewHolder(FragmentFriendListBinding.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(FragmentFriendListBinding binding) { + super(binding.getRoot()); + mIdView = binding.itemNumber; + mContentView = binding.content; + } + + @Override + public String toString() { + return super.toString() + " '" + mContentView.getText() + "'"; + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_friend_list.xml b/app/src/main/res/layout/fragment_friend_list.xml new file mode 100644 index 0000000..1877568 --- /dev/null +++ b/app/src/main/res/layout/fragment_friend_list.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_friend_list_list.xml b/app/src/main/res/layout/fragment_friend_list_list.xml new file mode 100644 index 0000000..f9368e4 --- /dev/null +++ b/app/src/main/res/layout/fragment_friend_list_list.xml @@ -0,0 +1,13 @@ + + \ No newline at end of file