This repository was archived by the owner on Apr 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Implement Recycler View for Newsfeed #2
Open
prabirmsp
wants to merge
4
commits into
develop
Choose a base branch
from
mainRecyclerView
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f06abb
create new recycler view adapter class
prabirmsp c1fb43a
Create abstraction for view types in RecyclerView
prabirmsp 374b078
Add example small and large exmaple article card implementations
prabirmsp 1f066df
add small and large example cards to recyclerview adapter
prabirmsp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...n/java/edu/grinnell/grinnell_publications_android/Controllers/Cards/LargeArticleCard.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package edu.grinnell.grinnell_publications_android.Controllers.Cards; | ||
|
|
||
| import edu.grinnell.grinnell_publications_android.Controllers.RecyclerItem; | ||
| import edu.grinnell.grinnell_publications_android.R; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class LargeArticleCard extends RecyclerItem { | ||
|
|
||
| public static final int LARGE_ARTICLE = R.layout.card_article_large; | ||
|
|
||
| String title; | ||
|
|
||
| public LargeArticleCard() { | ||
| super(LARGE_ARTICLE); | ||
| title = "This is a Large Article"; | ||
| } | ||
|
|
||
|
|
||
| } |
30 changes: 30 additions & 0 deletions
30
...java/edu/grinnell/grinnell_publications_android/Controllers/Cards/LargeArticleHolder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package edu.grinnell.grinnell_publications_android.Controllers.Cards; | ||
|
|
||
| import android.app.Activity; | ||
| import android.view.View; | ||
| import android.widget.TextView; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
| import edu.grinnell.grinnell_publications_android.Controllers.RecyclerViewHolder; | ||
| import edu.grinnell.grinnell_publications_android.R; | ||
|
|
||
| /** | ||
| */ | ||
| public class LargeArticleHolder extends RecyclerViewHolder<LargeArticleCard> { | ||
|
|
||
| @Bind(R.id.tv_article_title) | ||
| TextView title; | ||
|
|
||
| public LargeArticleHolder(View itemView) { | ||
| super(itemView); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void bindView(LargeArticleCard largeArticleCard, Activity activity) { | ||
| ButterKnife.bind(activity); | ||
|
|
||
| title.setText(largeArticleCard.title); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...n/java/edu/grinnell/grinnell_publications_android/Controllers/Cards/SmallArticleCard.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package edu.grinnell.grinnell_publications_android.Controllers.Cards; | ||
|
|
||
| import edu.grinnell.grinnell_publications_android.Controllers.RecyclerItem; | ||
| import edu.grinnell.grinnell_publications_android.R; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class SmallArticleCard extends RecyclerItem { | ||
|
|
||
| public static final int SMALL_ARTICLE = R.layout.card_article_small; | ||
| String title; | ||
|
|
||
| public SmallArticleCard() { | ||
| super(SMALL_ARTICLE); | ||
| title = "This is a Small Article"; | ||
| } | ||
|
|
||
| } |
29 changes: 29 additions & 0 deletions
29
...java/edu/grinnell/grinnell_publications_android/Controllers/Cards/SmallArticleHolder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package edu.grinnell.grinnell_publications_android.Controllers.Cards; | ||
|
|
||
| import android.app.Activity; | ||
| import android.view.View; | ||
| import android.widget.TextView; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
| import edu.grinnell.grinnell_publications_android.Controllers.RecyclerViewHolder; | ||
| import edu.grinnell.grinnell_publications_android.R; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class SmallArticleHolder extends RecyclerViewHolder<SmallArticleCard> { | ||
| @Bind(R.id.tv_article_title) | ||
| TextView title; | ||
|
|
||
| public SmallArticleHolder(View itemView) { | ||
| super(itemView); | ||
| } | ||
|
|
||
| @Override | ||
| public void bindView(SmallArticleCard smallArticleCard, Activity activity) { | ||
| ButterKnife.bind(activity); | ||
|
|
||
| title.setText(smallArticleCard.title); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
.../java/edu/grinnell/grinnell_publications_android/Controllers/MainRecyclerViewAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package edu.grinnell.grinnell_publications_android.Controllers; | ||
|
|
||
| import android.app.Activity; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.view.LayoutInflater; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import edu.grinnell.grinnell_publications_android.Controllers.Cards.LargeArticleCard; | ||
| import edu.grinnell.grinnell_publications_android.Controllers.Cards.LargeArticleHolder; | ||
| import edu.grinnell.grinnell_publications_android.Controllers.Cards.SmallArticleCard; | ||
| import edu.grinnell.grinnell_publications_android.Controllers.Cards.SmallArticleHolder; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class MainRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolder> { | ||
|
|
||
| private List<RecyclerItem> data; | ||
| private Activity activity; | ||
|
|
||
| public MainRecyclerViewAdapter(Activity activity) { | ||
| this.data = new ArrayList<>(); | ||
| this.activity = activity; | ||
| } | ||
|
|
||
| /** | ||
| * Update the data for the recycler view | ||
| * | ||
| * @param data a list of recycler items that will populate the recycler view | ||
| */ | ||
| public void setData(List<RecyclerItem> data) { | ||
| this.data = data; | ||
| notifyDataSetChanged(); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
| LayoutInflater li = activity.getLayoutInflater(); | ||
| RecyclerViewHolder holder; | ||
| switch (viewType) { | ||
| case SmallArticleCard.SMALL_ARTICLE: | ||
| holder = new SmallArticleHolder(li.inflate(SmallArticleCard.SMALL_ARTICLE, parent)); | ||
| break; | ||
| case LargeArticleCard.LARGE_ARTICLE: | ||
| holder = new LargeArticleHolder(li.inflate(LargeArticleCard.LARGE_ARTICLE, parent)); | ||
| break; | ||
| default: | ||
| holder = null; | ||
| } | ||
| return holder; | ||
| } | ||
|
|
||
| @Override | ||
| public void onBindViewHolder(RecyclerViewHolder holder, int position) { | ||
| holder.bindView(data.get(position), activity); | ||
| } | ||
|
|
||
| @Override | ||
| public int getItemCount() { | ||
| return 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return data.size() and not 0 |
||
| } | ||
|
|
||
| @Override | ||
| public int getItemViewType(int position) { | ||
| return data.get(position).getViewType(); | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
app/src/main/java/edu/grinnell/grinnell_publications_android/Controllers/RecyclerItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package edu.grinnell.grinnell_publications_android.Controllers; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public abstract class RecyclerItem { | ||
|
|
||
| private int viewType; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param layoutId the integer identifier for the view type. | ||
| * Use the resource id of the layout as the view type. | ||
| */ | ||
| public RecyclerItem(int layoutId) { | ||
| this.viewType = layoutId; | ||
|
|
||
| } | ||
|
|
||
| public int getViewType() { | ||
| return viewType; | ||
| } | ||
|
|
||
| } |
33 changes: 33 additions & 0 deletions
33
.../main/java/edu/grinnell/grinnell_publications_android/Controllers/RecyclerViewHolder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package edu.grinnell.grinnell_publications_android.Controllers; | ||
|
|
||
| import android.app.Activity; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.view.View; | ||
|
|
||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public abstract class RecyclerViewHolder<T extends RecyclerItem> extends RecyclerView.ViewHolder{ | ||
|
|
||
|
|
||
| public RecyclerViewHolder(View itemView) { | ||
| super(itemView); | ||
| } | ||
|
|
||
| /** | ||
| * Getter for the itemView from the super class | ||
| * @return the itemView for the recycler item | ||
| */ | ||
| public View getItemView() { | ||
| return super.itemView; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @param recyclerItem | ||
| * @param activity | ||
| */ | ||
| public abstract void bindView(T recyclerItem, Activity activity); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:id="@+id/card_view" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="vertical"> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:orientation="vertical"> | ||
|
|
||
| <ImageView | ||
| android:id="@+id/iv_article" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="200dp" | ||
| android:src="@mipmap/ic_launcher" /> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:padding="@dimen/card_inner_padding"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/tv_article_title" | ||
| style="@style/card_article_title" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="Article Title" /> | ||
| </LinearLayout> | ||
| </LinearLayout> | ||
| </android.support.v7.widget.CardView> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:id="@+id/card_view" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="vertical"> | ||
|
|
||
| <RelativeLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:padding="@dimen/card_inner_padding"> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_toStartOf="@id/iv_article"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/tv_article_title" | ||
| style="@style/card_article_title" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="Article Title" /> | ||
| </LinearLayout> | ||
|
|
||
| <ImageView | ||
| android:id="@+id/iv_article" | ||
| android:layout_width="100dp" | ||
| android:layout_height="100dp" | ||
| android:layout_alignParentEnd="true" | ||
| android:layout_centerVertical="true" | ||
| android:src="@mipmap/ic_launcher" /> | ||
|
|
||
|
|
||
| </RelativeLayout> | ||
| </android.support.v7.widget.CardView> |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the LayoutInflater instance to something more appropriate eg. inflater, layoutInflater