Back to project page octodroid.
The source code is released under:
MIT License
If you think the Android project octodroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.octodroid.adapters; //from ww w . j a v a 2 s .c o m import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.ViewGroup; import com.example.octodroid.views.holders.RepositoryItemViewHolder; import com.rejasupotaro.octodroid.GitHub; import com.rejasupotaro.octodroid.http.Response; import com.rejasupotaro.octodroid.models.Repository; import java.util.ArrayList; import java.util.List; import rx.android.view.ViewObservable; public class HottestRepositoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<Repository> repositories = new ArrayList<>(); public HottestRepositoryAdapter(RecyclerView recyclerView) { LinearLayoutManager layoutManager = new LinearLayoutManager(recyclerView.getContext()); recyclerView.setHasFixedSize(false); recyclerView.setLayoutManager(layoutManager); ViewObservable.bindView(recyclerView, GitHub.client().hottestRepositories()) .map(Response::entity) .subscribe(searchResult -> { if (searchResult.getItems() == null || searchResult.getItems().isEmpty()) { return; } List<Repository> repositories = searchResult.getItems(); addRepositories(repositories); }); } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return RepositoryItemViewHolder.create(parent); } @Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { Repository repository = repositories.get(position); ((RepositoryItemViewHolder) viewHolder).bind(repository); } @Override public int getItemCount() { return repositories.size(); } private void addRepositories(List<Repository> repositories) { this.repositories.addAll(repositories); notifyDataSetChanged(); } }