Permalink
Browse files

onClick for comments in feed item

  • Loading branch information...
frogermcs committed Nov 23, 2014
1 parent d2e5723 commit ec3d47bd546f4bdcb7ba1a2a5afe58112972ea0a
@@ -10,18 +10,19 @@
import butterknife.ButterKnife;
import butterknife.InjectView;
-import hugo.weaving.DebugLog;
/**
* Created by froger_mcs on 05.11.14.
*/
-public class FeedAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+public class FeedAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener {
private static final int ANIMATED_ITEMS_COUNT = 2;
private Context context;
private int lastAnimatedPosition = -1;
private int itemsCount = 0;
+ private OnFeedItemClickListener onFeedItemClickListener;
+
public FeedAdapter(Context context) {
this.context = context;
}
@@ -59,13 +60,34 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
holder.ivFeedCenter.setImageResource(R.drawable.img_feed_center_2);
holder.ivFeedBottom.setImageResource(R.drawable.img_feed_bottom_2);
}
+
+ holder.ivFeedBottom.setOnClickListener(this);
+ holder.ivFeedBottom.setTag(position);
}
@Override
public int getItemCount() {
return itemsCount;
}
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.ivFeedBottom) {
+ if (onFeedItemClickListener != null) {
+ onFeedItemClickListener.onCommentsClick(v, (Integer) v.getTag());
+ }
+ }
+ }
+
+ public void updateItems() {
+ itemsCount = 10;
+ notifyDataSetChanged();
+ }
+
+ public void setOnFeedItemClickListener(OnFeedItemClickListener onFeedItemClickListener) {
+ this.onFeedItemClickListener = onFeedItemClickListener;
+ }
+
public static class CellFeedViewHolder extends RecyclerView.ViewHolder {
@InjectView(R.id.ivFeedCenter)
SquaredImageView ivFeedCenter;
@@ -78,8 +100,7 @@ public CellFeedViewHolder(View view) {
}
}
- public void updateItems() {
- itemsCount = 10;
- notifyDataSetChanged();
+ public interface OnFeedItemClickListener {
+ public void onCommentsClick(View v, int position);
}
}
@@ -10,7 +10,6 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewTreeObserver;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageButton;
import android.widget.ImageView;
@@ -19,7 +18,7 @@
import butterknife.InjectView;
-public class MainActivity extends ActionBarActivity {
+public class MainActivity extends ActionBarActivity implements FeedAdapter.OnFeedItemClickListener {
private static final int ANIM_DURATION_TOOLBAR = 300;
private static final int ANIM_DURATION_FAB = 400;
@@ -59,7 +58,9 @@ private void setupToolbar() {
private void setupFeed() {
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
rvFeed.setLayoutManager(linearLayoutManager);
+
feedAdapter = new FeedAdapter(this);
+ feedAdapter.setOnFeedItemClickListener(this);
rvFeed.setAdapter(feedAdapter);
}
@@ -113,4 +114,8 @@ private void startContentAnimation() {
.start();
feedAdapter.updateItems();
}
+
+ @Override
+ public void onCommentsClick(View v, int position) {
+ }
}

0 comments on commit ec3d47b

Please sign in to comment.