private void loadPage(int page) { api.getActivities(categories[currentCategory], page, PAGE_SIZE) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( new Action1<List<Activity>>() { @Override public void call(List<Activity> activities) { ActivitiesFragment.this.activities.addAll(activities); list.getAdapter().notifyDataSetChanged(); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { Timber.e( "failed to fetch " + categories[currentCategory] + " activities", throwable); throwable.printStackTrace(); } }); }
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ActivitiesFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.activities_fragment, container, false); binding.setCategory(category); Toolbar toolbar = binding.toolbar; AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(toolbar); assert activity.getSupportActionBar() != null; final ActionBar ab = activity.getSupportActionBar(); ab.setDisplayShowTitleEnabled(false); ab.setDisplayHomeAsUpEnabled(false); Spinner spinner = binding.spinner; spinner.setAdapter( new ArrayAdapter<>( ab.getThemedContext(), android.R.layout.simple_spinner_item, localizedCategory)); spinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (currentCategory != position) { currentCategory = position; category.set(localizedCategory[currentCategory]); activities.clear(); list.getAdapter().notifyDataSetChanged(); } } @Override public void onNothingSelected(AdapterView<?> parent) {} }); slider = binding.slider; slider.setCustomIndicator(binding.customIndicator); slider.setDuration(3500); slider.setPresetTransformer(SliderLayout.Transformer.Fade); api.getActivities("recommendations", 0, 5) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( new Action1<List<Activity>>() { @Override public void call(List<Activity> activities) { slider.stopAutoCycle(); slider.removeAllSliders(); for (Activity activity : activities) { ActivitySliderView view = new ActivitySliderView(getContext(), activity); view.bundle(new Bundle()); view.getBundle().putLong("id", activity.getId()); view.setOnSliderClickListener(sliderClickListener); slider.addSlider(view); } slider.startAutoCycle(); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { Timber.e("failed to fetch recommended activities", throwable); throwable.printStackTrace(); } }); list = binding.list; LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); list.setLayoutManager(linearLayoutManager); list.addItemDecoration(new MarginDownDecoration(getContext())); list.setAdapter(new ActivitiesAdapter(activities)); list.addOnScrollListener( new EndlessRecyclerOnScrollListener(linearLayoutManager) { @Override public void onLoadMore(int currentPage) { loadPage(currentPage); } }); // loadPage(0); return binding.getRoot(); }