Fix POI edit activity

This commit is contained in:
vshcherb 2013-11-03 17:33:28 +01:00
parent ddc62db00e
commit d195ebc054
3 changed files with 26 additions and 8 deletions

View file

@ -171,18 +171,21 @@ public class PoiFiltersHelper {
cacheUserDefinedFilters = new ArrayList<PoiFilter>();
PoiFilterDbHelper helper = openDbHelper();
List<PoiFilter> userDefined = helper.getFilters(helper.getReadableDatabase());
final Collator instance = Collator.getInstance();
Collections.sort(userDefined, new Comparator<PoiFilter>() {
@Override
public int compare(PoiFilter object1, PoiFilter object2) {
return instance.compare(object1.getName(), object2.getName());
}
});
sortListOfFiltersByName(userDefined);
cacheUserDefinedFilters.addAll(userDefined);
helper.close();
}
return Collections.unmodifiableList(cacheUserDefinedFilters);
}
private void sortListOfFiltersByName(List<PoiFilter> userDefined) {
final Collator instance = Collator.getInstance();
Collections.sort(userDefined, new Comparator<PoiFilter>() {
@Override
public int compare(PoiFilter object1, PoiFilter object2) {
return instance.compare(object1.getName(), object2.getName());
}
});
}
public List<PoiFilter> getTopStandardFilters() {
if (cacheTopStandardFilters == null) {
@ -257,6 +260,7 @@ public class PoiFiltersHelper {
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false);
if(res){
cacheUserDefinedFilters.add(filter);
sortListOfFiltersByName(cacheUserDefinedFilters);
}
helper.close();
return res;

View file

@ -236,6 +236,15 @@ public class SearchActivity extends SherlockFragmentActivity implements OsmAndLo
} else {
updateSearchPoint(latLon, getString(R.string.search_position_fixed), true);
}
} else if (requestCode == SearchPoiFilterActivity.REQUEST_POI_EDIT) {
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof SearchPoiFilterActivity) {
if(!f.isDetached()) {
((SearchPoiFilterActivity) f).refreshPoiListAdapter();
}
}
}
}
}

View file

@ -38,6 +38,7 @@ public class SearchPoiFilterActivity extends SherlockListFragment implements Se
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT;
public static final String SEARCH_LON = SearchActivity.SEARCH_LON;
public static final int REQUEST_POI_EDIT = 55;
@Override
@ -59,6 +60,10 @@ public class SearchPoiFilterActivity extends SherlockListFragment implements Se
}
});
refreshPoiListAdapter();
}
public void refreshPoiListAdapter() {
PoiFiltersHelper poiFilters = getApp().getPoiFilters();
List<PoiFilter> filters = new ArrayList<PoiFilter>() ;
filters.addAll(poiFilters.getTopStandardFilters());
@ -95,7 +100,7 @@ public class SearchPoiFilterActivity extends SherlockListFragment implements Se
// folder selected
newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, poi.getFilterId());
updateIntentToLaunch(newIntent);
startActivityForResult(newIntent, 0);
startActivityForResult(newIntent, REQUEST_POI_EDIT);
}
@Override