Guest User

Untitled

a guest
Dec 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Observable.just(AssetsUtil.getCountryList(context))
  2. .flatMapIterable(new Function<List<Country>, Iterable<?>>() {
  3. @Override
  4. public Iterable<?> apply(List<Country> countryList) throws Exception {
  5. return countryList;
  6. }
  7. })
  8. .subscribeOn(Schedulers.io())
  9. .observeOn(AndroidSchedulers.mainThread())
  10. .subscribe(item -> mView.onCountryListReceive((Country) item));
  11.  
  12. @Override
  13. public void onCountryListReceive(Country country) {
  14. countries.add(country);
  15. PreferencesUtil.putCountryList(getActivity(), countries);
  16. }
  17.  
  18. public static List<Country> getCountryList(Context context) {
  19. String countryJson = loadJSONFromAsset(context);
  20.  
  21. List<Country> countryList = new Gson().fromJson(countryJson, new TypeToken<List<Country>>(){}.getType());
  22.  
  23. cityList = new ArrayList<>();
  24.  
  25. if (countryList != null) {
  26. for (Country country : countryList){
  27. cityList.addAll(country.getCities());
  28. }
  29. }
  30.  
  31. return countryList;
  32. }
Add Comment
Please, Sign In to add comment