Skip to content

Instantly share code, notes, and snippets.

@fnk0
Created May 10, 2015 23:07
Show Gist options
  • Select an option

  • Save fnk0/d70155c60b9375b0e094 to your computer and use it in GitHub Desktop.

Select an option

Save fnk0/d70155c60b9375b0e094 to your computer and use it in GitHub Desktop.
First code snippet using rxJava. Retrieves a list of repositories from Github and passes it to a CardsList
public class FragmentRepos extends DefaultListFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
GithubClient client = new GithubClient(true);
RepoService repoService = client.createService(RepoService.class);
Observable<List<Repo>> repos = repoService.getRepos("fnk0");
AppObservable.bindFragment(this, repos);
repos.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<Repo>>() {
@Override
public void call(List<Repo> repos) {
Collections.sort(repos);
ArrayList<Card> cards = new ArrayList<>();
for (Repo r : repos) {
cards.add(new CardRepo(getActivity(), r));
}
mCardArrayAdapter = new CardArrayRecyclerViewAdapter(getActivity(), cards);
recyclerViewList.setAdapter(mCardArrayAdapter);
refreshList();
progressWheel.setVisibility(View.GONE);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment