@ -0,0 +1,73 @@ | |||
package gq.yigit.mycity.vote; | |||
import android.support.v7.widget.RecyclerView; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.TextView; | |||
import gq.yigit.mycity.R; | |||
import gq.yigit.mycity.vote.VotesFragment.OnListFragmentInteractionListener; | |||
import gq.yigit.mycity.vote.VotesContent.VoteItem; | |||
import java.util.List; | |||
public class MyVotesRecyclerViewAdapter extends RecyclerView.Adapter<MyVotesRecyclerViewAdapter.ViewHolder> { | |||
private final List<VoteItem> mValues; | |||
private final OnListFragmentInteractionListener mListener; | |||
public MyVotesRecyclerViewAdapter(List<VoteItem> items, OnListFragmentInteractionListener listener) { | |||
mValues = items; | |||
mListener = listener; | |||
} | |||
@Override | |||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |||
View view = LayoutInflater.from(parent.getContext()) | |||
.inflate(R.layout.fragment_votes, parent, false); | |||
return new ViewHolder(view); | |||
} | |||
@Override | |||
public void onBindViewHolder(final ViewHolder holder, int position) { | |||
holder.mItem = mValues.get(position); | |||
holder.mIdView.setText(mValues.get(position).name); | |||
holder.mContentView.setText(mValues.get(position).details); | |||
holder.mView.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (null != mListener) { | |||
mListener.onListFragmentInteraction(holder.mItem); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mValues.size(); | |||
} | |||
public class ViewHolder extends RecyclerView.ViewHolder { | |||
public final View mView; | |||
public final TextView mIdView; | |||
public final TextView mContentView; | |||
public VoteItem mItem; | |||
public ViewHolder(View view) { | |||
super(view); | |||
mView = view; | |||
mIdView = (TextView) view.findViewById(R.id.item_number); | |||
mContentView = (TextView) view.findViewById(R.id.content); | |||
} | |||
@Override | |||
public String toString() { | |||
return super.toString() + " '" + mContentView.getText() + "'"; | |||
} | |||
} | |||
} |
@ -0,0 +1,48 @@ | |||
package gq.yigit.mycity.vote; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
public class VotesContent { | |||
public static final List<VoteItem> ITEMS = new ArrayList<VoteItem>(); | |||
public static final Map<String, VoteItem> ITEM_MAP = new HashMap<String, VoteItem>(); | |||
private static void addItem(VoteItem item) { | |||
ITEMS.add(item); | |||
ITEM_MAP.put(item.id, item); | |||
} | |||
private static VoteItem creaVoteItem(int position) { | |||
return new VoteItem(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(); | |||
} | |||
public static class VoteItem { | |||
public final String id; | |||
public final String name; | |||
public final String details; | |||
public VoteItem(String id, String name, String details) { | |||
this.id = id; | |||
this.name = name; | |||
this.details = details; | |||
} | |||
@Override | |||
public String toString() { | |||
return name; | |||
} | |||
} | |||
} |
@ -0,0 +1,86 @@ | |||
package gq.yigit.mycity.vote; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.support.v4.app.Fragment; | |||
import android.support.v7.widget.GridLayoutManager; | |||
import android.support.v7.widget.LinearLayoutManager; | |||
import android.support.v7.widget.RecyclerView; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import gq.yigit.mycity.FileActions; | |||
import gq.yigit.mycity.R; | |||
import gq.yigit.mycity.vote.VotesContent.VoteItem; | |||
public class VotesFragment extends Fragment { | |||
private static final String ARG_COLUMN_COUNT = "column-count"; | |||
private int mColumnCount = 1; | |||
private OnListFragmentInteractionListener mListener; | |||
public VotesFragment() { | |||
} | |||
public static VotesFragment newInstance(int columnCount) { | |||
VotesFragment fragment = new VotesFragment(); | |||
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_votes_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)); | |||
} | |||
FileActions file_manager = new FileActions(); | |||
recyclerView.setAdapter(new MyVotesRecyclerViewAdapter(VotesContent.ITEMS, mListener)); | |||
} | |||
return view; | |||
} | |||
@Override | |||
public void onAttach(Context context) { | |||
super.onAttach(context); | |||
if (context instanceof OnListFragmentInteractionListener) { | |||
mListener = (OnListFragmentInteractionListener) context; | |||
} else { | |||
throw new RuntimeException(context.toString() | |||
+ " must implement OnListFragmentInteractionListener"); | |||
} | |||
} | |||
@Override | |||
public void onDetach() { | |||
super.onDetach(); | |||
mListener = null; | |||
} | |||
public interface OnListFragmentInteractionListener { | |||
void onListFragmentInteraction(VoteItem item); | |||
} | |||
} |
@ -0,0 +1,12 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:shape="rectangle"> | |||
<corners | |||
android:radius="2dp" | |||
android:topRightRadius="0dp" | |||
android:bottomRightRadius="0dp" | |||
android:bottomLeftRadius="0dp"/> | |||
<stroke | |||
android:width="1dp" | |||
android:color="@android:color/black" /> | |||
</shape> |
@ -0,0 +1,29 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:background="@drawable/vote_style"> | |||
<ImageView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" app:srcCompat="@mipmap/ic_launcher" android:id="@+id/imageView2" | |||
android:layout_weight="1"/> | |||
<LinearLayout | |||
android:orientation="vertical" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" android:layout_weight="1"> | |||
<TextView | |||
android:id="@+id/item_number" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="@dimen/text_margin" | |||
android:textAppearance="?attr/textAppearanceListItem"/> | |||
<TextView | |||
android:id="@+id/content" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="@dimen/text_margin" | |||
android:textAppearance="?attr/textAppearanceListItem"/> | |||
</LinearLayout> | |||
</LinearLayout> |
@ -0,0 +1,16 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<android.support.v7.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="gq.yigit.mycity.VotesFragment" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_marginLeft="16dp" | |||
android:layout_marginRight="16dp" | |||
app:layoutManager="LinearLayoutManager" | |||
tools:context=".vote.VotesFragment" | |||
tools:listitem="@layout/fragment_votes" | |||
android:divider="@android:color/transparent" | |||
android:dividerHeight="10.0sp"/> |
@ -1,14 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Bonjour!" | |||
app:layout_constraintBottom_toBottomOf="parent" | |||
app:layout_constraintLeft_toLeftOf="parent" | |||
app:layout_constraintRight_toRightOf="parent" | |||
app:layout_constraintTop_toTopOf="parent"/> | |||
</android.support.constraint.ConstraintLayout> |