use of be.brunoparmentier.openbikesharing.app.adapters.BikeNetworksListAdapter in project OpenBikeSharing by bparmentier.
the class BikeNetworksListActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bike_networks_list, menu);
SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public // TODO: avoid redundancy
boolean onQueryTextChange(String s) {
if (bikeNetworks == null) {
return false;
}
searchedBikeNetworks = new ArrayList<>();
for (BikeNetworkInfo network : bikeNetworks) {
if (network.getName().toLowerCase().contains(s.toLowerCase()) || network.getLocation().getCity().toLowerCase().contains(s.toLowerCase())) {
searchedBikeNetworks.add(network);
}
}
bikeNetworksListAdapter = new BikeNetworksListAdapter(BikeNetworksListActivity.this, android.R.layout.simple_expandable_list_item_2, android.R.id.text1, searchedBikeNetworks);
listView.setAdapter(bikeNetworksListAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(BikeNetworksListActivity.this);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PREF_KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
editor.putString(PREF_KEY_NETWORK_NAME, searchedBikeNetworks.get(position).getName());
editor.putString(PREF_KEY_NETWORK_CITY, searchedBikeNetworks.get(position).getLocation().getCity());
editor.putLong(PREF_KEY_NETWORK_LATITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLatitude()));
editor.putLong(PREF_KEY_NETWORK_LONGITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLongitude()));
editor.apply();
Toast.makeText(BikeNetworksListActivity.this, searchedBikeNetworks.get(position).getName() + " (" + searchedBikeNetworks.get(position).getLocation().getCity() + ") " + getString(R.string.network_selected), Toast.LENGTH_SHORT).show();
Intent resultIntent = new Intent();
resultIntent.putExtra(KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
if (getParent() == null) {
setResult(Activity.RESULT_OK, resultIntent);
} else {
getParent().setResult(Activity.RESULT_OK, resultIntent);
}
finish();
}
});
return true;
}
});
return true;
}
Aggregations