|
| 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 | +} |
0 commit comments