Created
May 10, 2015 23:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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