Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"

compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton.timber:timber:4.1.2'
compile 'io.realm:realm-android:0.84.1'
compile 'com.android.support:support-v4:23.3.0'
}
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";
}


}
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);
}
}
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";
}

}
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);
}
}
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();
Copy link
Copy Markdown
Member

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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();
}
}
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;
}

}
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);

}
32 changes: 32 additions & 0 deletions app/src/main/res/layout/card_article_large.xml
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>
36 changes: 36 additions & 0 deletions app/src/main/res/layout/card_article_small.xml
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>
6 changes: 0 additions & 6 deletions app/src/main/res/values-w820dp/dimens.xml

This file was deleted.

3 changes: 3 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<dimen name="circular_img_view_height">76dp</dimen>
<dimen name="circular_img_view_width">76dp</dimen>

<dimen name="card_inner_padding">12dp</dimen>
<dimen name="card_article_title_font_size">16sp</dimen>

</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
</style>


<!-- Style for the article title in cards -->
<style name="card_article_title">
<item name="android:textSize">@dimen/card_article_title_font_size</item>
<item name="android:fontFamily">serif</item>
<item name="android:textColor">@color/black</item>
</style>


</resources>