Update poi edit

This commit is contained in:
Victor Shcherb 2015-04-10 00:52:26 +02:00
parent d236bc718c
commit 6c9995efd3
4 changed files with 37 additions and 30 deletions

View file

@ -52,6 +52,7 @@ public class EditPOIFilterActivity extends OsmandListActivity {
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; //$NON-NLS-1$
public static final String SEARCH_LON = SearchActivity.SEARCH_LON; //$NON-NLS-1$
private static final int FILTER = 2;
public static final int EDIT_ACTIVITY_RESULT_OK = 20;
@Override
@ -79,7 +80,9 @@ public class EditPOIFilterActivity extends OsmandListActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == FILTER) {
filterPOI();
// filterPOI();
setResult(EDIT_ACTIVITY_RESULT_OK);
finish();
return true;
}
return super.onOptionsItemSelected(item);
@ -115,19 +118,7 @@ public class EditPOIFilterActivity extends OsmandListActivity {
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
if (searchNearBy) {
AlertDialog.Builder b = new AlertDialog.Builder(EditPOIFilterActivity.this);
b.setItems(new String[] { getString(R.string.search_nearby), getString(R.string.search_near_map) },
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 1) {
newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, lat);
newIntent.putExtra(SearchPOIActivity.SEARCH_LON, lon);
}
startActivity(newIntent);
}
});
b.show();
startActivity(newIntent);
} else {
newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, lat);
newIntent.putExtra(SearchPOIActivity.SEARCH_LON, lon);

View file

@ -110,6 +110,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
private MenuItem showOnMapItem;
private MenuItem searchPOILevel;
private static int RESULT_REQUEST_CODE = 54;
private static int RESULT_CUSTOM_REQUEST_CODE = 55;
@Override
public boolean onCreateOptionsMenu(Menu omenu) {
@ -262,7 +263,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
String filterId = bundle.getString(AMENITY_FILTER);
this.filter = app.getPoiFilters().getFilterById(filterId);
if (filter != null) {
if(filter.isEmpty()) {
if(filter.isEmpty() && !isNameSearch()) {
showEditActivity(filter);
} else {
filter.clearPreviousZoom();
@ -333,13 +334,9 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if(!f.isStandardFilter()) {
showEditActivity(f);
} else {
PoiLegacyFilter filter = getMyApplication().getPoiFilters().getCustomPOIFilter();
filter.updateTypesToAccept(f);
showEditActivity(filter);
}
PoiLegacyFilter custom = getMyApplication().getPoiFilters().getCustomPOIFilter();
custom.updateTypesToAccept(f);
showEditActivity(custom);
return true;
}
});
@ -354,18 +351,25 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
newIntent.putExtra(SearchActivity.SEARCH_LAT, location.getLatitude());
newIntent.putExtra(SearchActivity.SEARCH_LON, location.getLongitude());
}
startActivityForResult(newIntent, RESULT_REQUEST_CODE);
startActivityForResult(newIntent, poi.getFilterId().equals(PoiLegacyFilter.CUSTOM_FILTER_ID) ?
RESULT_CUSTOM_REQUEST_CODE : RESULT_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RESULT_REQUEST_CODE) {
String filterId = getIntent().getExtras().getString(AMENITY_FILTER);
PoiLegacyFilter filter = app.getPoiFilters().getFilterById(filterId);
if (filter == null || filter.isEmpty()) {
finish();
if (requestCode == RESULT_REQUEST_CODE && resultCode == EditPOIFilterActivity.EDIT_ACTIVITY_RESULT_OK) {
PoiLegacyFilter custom = app.getPoiFilters().getCustomPOIFilter();
if(this.filter.isStandardFilter()) {
PoiLegacyFilter old = this.filter;
this.filter = custom;
this.filter.setFilterByName(old.getFilterByName());
} else {
this.filter.updateTypesToAccept(custom);
}
}
if (filter == null || filter.isEmpty()) {
finish();
}
}
private void updateButtonState() {
@ -862,6 +866,11 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.edit_filter_save_as_menu_item);
final EditText editText = new EditText(this);
if(filter.isStandardFilter()) {
editText.setText((filter.getName() + " " + searchFilter.getText()).trim());
} else {
editText.setText(filter.getName());
}
LinearLayout ll = new LinearLayout(this);
ll.setPadding(5, 3, 5, 0);
ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

View file

@ -5,6 +5,7 @@ import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@ -215,7 +216,14 @@ public class PoiFiltersHelper {
if(helper == null){
return false;
}
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false);
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
Iterator<PoiLegacyFilter> it = cacheTopStandardFilters.iterator();
while(it.hasNext()) {
if(it.next().getFilterId().equals(filter.getFilterId())) {
it.remove();
}
}
res = helper.addFilter(filter, helper.getWritableDatabase(), false);
if(res){
cacheTopStandardFilters.add(filter);
sortListOfFilters(cacheTopStandardFilters);

View file

@ -360,7 +360,6 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
public void updateTypesToAccept(PoiLegacyFilter f) {
acceptedTypes.clear();
acceptedTypes.putAll(f.acceptedTypes);
filterByName = f.filterByName;
}