@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { ArrayList<Site> historyList = new ArrayList<Site>(); data.moveToFirst(); for (int i = 0; i < data.getCount(); i++) { Site site = HistoryDbAdapter.mapToSite(data); historyList.add(site); data.moveToNext(); } mDefaultListAdapter.setHistoryData(this, historyList); }
void setupHistoryViews() { mHistoryRecyclerView = (RecyclerView) findViewById(R.id.search_history_list); mHistoryRecyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(this); mHistoryRecyclerView.setLayoutManager(layoutManager); mHistoryRecyclerView.addOnScrollListener(new HideKeyboardOnScroll(this, mSearchEdit)); // For now, skip the extras if we only searching for stops. if (mSearchOnlyStops) { return; } mDefaultListAdapter = new DefaultListAdapter(this); List<SimpleItemBinder.Item> options = new ArrayList<>(); options.add( new SimpleItemBinder.Item(R.drawable.ic_my_location_24dp, getText(R.string.my_location))); options.add(new SimpleItemBinder.Item(R.drawable.ic_map_24dp, getText(R.string.point_on_map))); mDefaultListAdapter.setOptions(options); mHistoryRecyclerView.setAdapter(mDefaultListAdapter); ItemClickSupport.addTo(mHistoryRecyclerView) .setOnItemClickListener( new ItemClickSupport.OnItemClickListener() { @Override public void onItemClicked(RecyclerView recyclerView, int position, View v) { int viewType = mDefaultListAdapter.getItemViewType(position); DataBinder binder = mDefaultListAdapter.getDataBinder(viewType); int binderPosition = mDefaultListAdapter.getBinderPosition(position); if (binder instanceof HistoryBinder) { Site site = ((HistoryBinder) binder).getItem(binderPosition); deliverResult(site); } else if (binder instanceof SimpleItemBinder) { switch (binderPosition) { case 0: Site currentLocation = new Site(); currentLocation.setName(Site.TYPE_MY_LOCATION); deliverResult(currentLocation); break; case 1: Intent i = new Intent(PlaceSearchActivity.this, PointOnMapActivity.class); i.putExtra(PointOnMapActivity.EXTRA_STOP, new Site()); i.putExtra( PointOnMapActivity.EXTRA_HELP_TEXT, getString(R.string.tap_your_start_point_on_map)); startActivityForResult(i, REQUEST_CODE_POINT_ON_MAP); break; } } } }); }