void setupSearchResultViews() { mSearchResultRecyclerView = (RecyclerView) findViewById(R.id.search_results); mSearchResultRecyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(this); mSearchResultRecyclerView.setLayoutManager(layoutManager); mSearchResultRecyclerView.addOnScrollListener(new HideKeyboardOnScroll(this, mSearchEdit)); mSearchResultAdapter = new PlaceSearchResultAdapter(this); mSearchResultRecyclerView.setAdapter(mSearchResultAdapter); // Search result filters. AutocompleteResultCallback autocompleteResultCallback = new AutocompleteResultCallback(); mSthlmTravelingSearchFilter = new SiteFilter(mSearchResultAdapter, this, mSearchOnlyStops); mSthlmTravelingSearchFilter.setFilterResultCallback(autocompleteResultCallback); mGoogleSearchFilter = new GooglePlacesFilter(mSearchResultAdapter, getGoogleApiClient()); mGoogleSearchFilter.setFilterResultCallback(autocompleteResultCallback); ItemClickSupport.addTo(mSearchResultRecyclerView) .setOnItemClickListener( new ItemClickSupport.OnItemClickListener() { @Override public void onItemClicked(RecyclerView recyclerView, int position, View v) { if (position >= mSearchResultAdapter.getContentItemCount()) { // We end up here if picking one of the footer views. Only supporting one for now. if (mCurrentSearchFilterType == FILTER_TYPE_GOOGLE) { setSearchFilter(FILTER_TYPE_STHLM_TRAVELING); } else { setSearchFilter(FILTER_TYPE_GOOGLE); } } else { // We seen some crashes where the provided position did not match the items // hold by the adapter, this is a guard for these cases. if (position >= 0 && position < mSearchResultAdapter.getContentItemCount()) { PlaceItem item = mSearchResultAdapter.getItem(position); mSearchResultAdapter .getFilter() .setResultCallback( item, new PlaceSearchResultAdapter.PlaceFilter.PlaceItemResultCallback() { @Override public void onResult(Site site) { deliverResult(site); } @Override public void onError() { Toast.makeText( PlaceSearchActivity.this, R.string.planner_error_title, Toast.LENGTH_SHORT) .show(); } }); } } } }); }
@Override public void onMyLocationFound(Location location) { if (location != null) { LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude()); if (!AppConfig.GREATER_STHLM_BOUNDS.contains(currentLatLng)) { mGoogleSearchFilter.setSearchLocation(location); mCurrentSearchFilterType = FILTER_TYPE_GOOGLE; setSearchFilter(mCurrentSearchFilterType); } } }