Skip to content

Commit e5dbcd4

Browse files
committed
create adapter with recyclerview
1 parent bc52a11 commit e5dbcd4

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ android {
2121
dependencies {
2222
implementation fileTree(dir: 'libs', include: ['*.jar'])
2323
implementation 'com.android.support:appcompat-v7:26.1.0'
24+
implementation 'com.android.support:recyclerview-v7:26.1.0'
2425
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
2526
testImplementation 'junit:junit:4.12'
2627
androidTestImplementation 'com.android.support.test:runner:1.0.1'
@@ -31,4 +32,7 @@ dependencies {
3132
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
3233
implementation 'io.reactivex:rxandroid:1.2.1'
3334
implementation 'io.reactivex:rxjava:1.3.0'
35+
36+
implementation 'com.jakewharton:butterknife:8.8.1'
37+
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
3438
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.omrobbie.githubrxjava.adapter;
2+
3+
import android.support.v7.widget.RecyclerView;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.TextView;
8+
9+
import com.omrobbie.githubrxjava.R;
10+
import com.omrobbie.githubrxjava.data.GitHubRepo;
11+
12+
import java.util.List;
13+
14+
import butterknife.BindView;
15+
import butterknife.ButterKnife;
16+
17+
/**
18+
* Created by omrobbie on 07/12/2017.
19+
*/
20+
21+
public class GitHubRepoAdapter extends RecyclerView.Adapter<GitHubRepoAdapter.ViewHolder> {
22+
23+
private List<GitHubRepo> list;
24+
25+
public GitHubRepoAdapter(List<GitHubRepo> list) {
26+
this.list = list;
27+
}
28+
29+
public void replaceAll(List<GitHubRepo> items) {
30+
list = items;
31+
notifyDataSetChanged();
32+
}
33+
34+
@Override
35+
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
36+
return new ViewHolder(
37+
LayoutInflater.from(parent.getContext()).inflate(
38+
R.layout.item_repo, parent, false
39+
)
40+
);
41+
}
42+
43+
@Override
44+
public void onBindViewHolder(ViewHolder holder, int position) {
45+
46+
}
47+
48+
@Override
49+
public int getItemCount() {
50+
return 0;
51+
}
52+
53+
public class ViewHolder extends RecyclerView.ViewHolder {
54+
55+
@BindView(R.id.tv_repo_name)
56+
TextView tv_repo_name;
57+
58+
@BindView(R.id.tv_repo_desc)
59+
TextView tv_repo_desc;
60+
61+
@BindView(R.id.tv_repo_lang)
62+
TextView tv_repo_lang;
63+
64+
@BindView(R.id.tv_repo_stars)
65+
TextView tv_repo_stars;
66+
67+
public ViewHolder(View itemView) {
68+
super(itemView);
69+
ButterKnife.bind(this, itemView);
70+
}
71+
72+
public void bind(GitHubRepo item) {
73+
tv_repo_name.setText(item.getName());
74+
tv_repo_desc.setText(item.getDescription());
75+
tv_repo_lang.setText(itemView.getContext().getString(R.string.label_lang) + " " + item.getLanguage());
76+
tv_repo_stars.setText(itemView.getContext().getString(R.string.label_stars) + " " + item.getStargazersCount());
77+
}
78+
}
79+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
android:orientation="vertical"
77
tools:context="com.omrobbie.githubrxjava.MainActivity">
88

9-
<ListView
10-
android:id="@+id/lv_repos"
9+
<android.support.v7.widget.RecyclerView
10+
android:id="@+id/rv_repos"
1111
android:layout_width="match_parent"
1212
android:layout_height="0dp"
1313
android:layout_weight="1"

0 commit comments

Comments
 (0)