Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Observable.just(AssetsUtil.getCountryList(context))
- .flatMapIterable(new Function<List<Country>, Iterable<?>>() {
- @Override
- public Iterable<?> apply(List<Country> countryList) throws Exception {
- return countryList;
- }
- })
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(item -> mView.onCountryListReceive((Country) item));
- @Override
- public void onCountryListReceive(Country country) {
- countries.add(country);
- PreferencesUtil.putCountryList(getActivity(), countries);
- }
- public static List<Country> getCountryList(Context context) {
- String countryJson = loadJSONFromAsset(context);
- List<Country> countryList = new Gson().fromJson(countryJson, new TypeToken<List<Country>>(){}.getType());
- cityList = new ArrayList<>();
- if (countryList != null) {
- for (Country country : countryList){
- cityList.addAll(country.getCities());
- }
- }
- return countryList;
- }
Add Comment
Please, Sign In to add comment