Formatting
This commit is contained in:
parent
30c71820aa
commit
89e14101b1
1 changed files with 142 additions and 143 deletions
|
@ -59,26 +59,26 @@ public class PoiFiltersHelper {
|
|||
UDF_PUBLIC_TRANSPORT, UDF_ACCOMMODATION, UDF_RESTAURANTS, UDF_PARKING
|
||||
};
|
||||
|
||||
public PoiFiltersHelper(OsmandApplication application){
|
||||
public PoiFiltersHelper(OsmandApplication application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public NominatimPoiFilter getNominatimPOIFilter() {
|
||||
if(nominatimPOIFilter == null){
|
||||
if (nominatimPOIFilter == null) {
|
||||
nominatimPOIFilter = new NominatimPoiFilter(application, false);
|
||||
}
|
||||
return nominatimPOIFilter;
|
||||
}
|
||||
|
||||
public NominatimPoiFilter getNominatimAddressFilter() {
|
||||
if(nominatimAddressFilter == null){
|
||||
if (nominatimAddressFilter == null) {
|
||||
nominatimAddressFilter = new NominatimPoiFilter(application, true);
|
||||
}
|
||||
return nominatimAddressFilter;
|
||||
}
|
||||
|
||||
public PoiUIFilter getSearchByNamePOIFilter() {
|
||||
if(searchByNamePOIFilter == null){
|
||||
if (searchByNamePOIFilter == null) {
|
||||
PoiUIFilter filter = new SearchByNameFilter(application);
|
||||
filter.setStandardFilter(true);
|
||||
searchByNamePOIFilter = filter;
|
||||
|
@ -87,7 +87,7 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
|
||||
public PoiUIFilter getCustomPOIFilter() {
|
||||
if (customPOIFilter == null){
|
||||
if (customPOIFilter == null) {
|
||||
PoiUIFilter filter = new PoiUIFilter(application.getString(R.string.poi_filter_custom_filter),
|
||||
PoiUIFilter.CUSTOM_FILTER_ID, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(), application); //$NON-NLS-1$
|
||||
filter.setStandardFilter(true);
|
||||
|
@ -97,12 +97,12 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
|
||||
public PoiUIFilter getLocalWikiPOIFilter() {
|
||||
if (localWikiPoiFilter == null){
|
||||
if (localWikiPoiFilter == null) {
|
||||
PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place");
|
||||
if (place != null && !Algorithms.isEmpty(application.getLanguage())) {
|
||||
PoiUIFilter filter = new PoiUIFilter(place, application, " " +
|
||||
application.getLangTranslation(application.getLanguage())); //$NON-NLS-1$
|
||||
filter.setSavedFilterByName("wiki:lang:"+application.getLanguage());
|
||||
filter.setSavedFilterByName("wiki:lang:" + application.getLanguage());
|
||||
filter.setStandardFilter(true);
|
||||
localWikiPoiFilter = filter;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
|
||||
public PoiUIFilter getShowAllPOIFilter() {
|
||||
if (showAllPOIFilter == null){
|
||||
if (showAllPOIFilter == null) {
|
||||
PoiUIFilter filter = new PoiUIFilter(null, application, ""); //$NON-NLS-1$
|
||||
filter.setStandardFilter(true);
|
||||
showAllPOIFilter = filter;
|
||||
|
@ -120,7 +120,7 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
|
||||
|
||||
private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters){
|
||||
private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters) {
|
||||
for (PoiUIFilter pf : filters) {
|
||||
if (pf.getFilterId().equals(filterId)) {
|
||||
return pf;
|
||||
|
@ -129,8 +129,8 @@ public class PoiFiltersHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public PoiUIFilter getFilterById(String filterId){
|
||||
if (filterId == null){
|
||||
public PoiUIFilter getFilterById(String filterId) {
|
||||
if (filterId == null) {
|
||||
return null;
|
||||
}
|
||||
for (PoiUIFilter f : getTopDefinedPoiFilters()) {
|
||||
|
@ -220,14 +220,14 @@ public class PoiFiltersHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
private PoiFilterDbHelper openDbHelper(){
|
||||
if(!application.getPoiTypes().isInit()) {
|
||||
private PoiFilterDbHelper openDbHelper() {
|
||||
if (!application.getPoiTypes().isInit()) {
|
||||
return null;
|
||||
}
|
||||
return new PoiFilterDbHelper(application.getPoiTypes(), application);
|
||||
}
|
||||
|
||||
public boolean removePoiFilter(PoiUIFilter filter){
|
||||
public boolean removePoiFilter(PoiUIFilter filter) {
|
||||
if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
|
||||
filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) ||
|
||||
filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) {
|
||||
|
@ -247,20 +247,20 @@ public class PoiFiltersHelper {
|
|||
return res;
|
||||
}
|
||||
|
||||
public boolean createPoiFilter(PoiUIFilter filter){
|
||||
public boolean createPoiFilter(PoiUIFilter filter) {
|
||||
PoiFilterDbHelper helper = openDbHelper();
|
||||
if(helper == null){
|
||||
if (helper == null) {
|
||||
return false;
|
||||
}
|
||||
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
|
||||
Iterator<PoiUIFilter> it = cacheTopStandardFilters.iterator();
|
||||
while(it.hasNext()) {
|
||||
if(it.next().getFilterId().equals(filter.getFilterId())) {
|
||||
while (it.hasNext()) {
|
||||
if (it.next().getFilterId().equals(filter.getFilterId())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
res = helper.addFilter(filter, helper.getWritableDatabase(), false);
|
||||
if(res){
|
||||
if (res) {
|
||||
ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters);
|
||||
copy.add(filter);
|
||||
Collections.sort(copy);
|
||||
|
@ -329,7 +329,7 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
|
||||
public boolean isPoiFilterSelected(String filterId) {
|
||||
for (PoiUIFilter filter: selectedPoiFilters) {
|
||||
for (PoiUIFilter filter : selectedPoiFilters) {
|
||||
if (filter.filterId.equals(filterId)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -339,14 +339,14 @@ public class PoiFiltersHelper {
|
|||
|
||||
public void loadSelectedPoiFilters() {
|
||||
Set<String> filters = application.getSettings().getSelectedPoiFilters();
|
||||
for (String f: filters) {
|
||||
for (String f : filters) {
|
||||
selectedPoiFilters.add(getFilterById(f));
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSelectedPoiFilters() {
|
||||
Set<String> filters = new HashSet<>();
|
||||
for (PoiUIFilter f: selectedPoiFilters) {
|
||||
for (PoiUIFilter f : selectedPoiFilters) {
|
||||
filters.add(f.filterId);
|
||||
}
|
||||
application.getSettings().setSelectedPoiFilters(filters);
|
||||
|
@ -384,7 +384,7 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
|
||||
public void close() {
|
||||
if(conn != null) {
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
conn = null;
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ public class PoiFiltersHelper {
|
|||
|
||||
|
||||
public void onUpgrade(SQLiteConnection conn, int oldVersion, int newVersion) {
|
||||
if(newVersion <= 5) {
|
||||
if (newVersion <= 5) {
|
||||
deleteOldFilters(conn);
|
||||
}
|
||||
conn.setVersion(newVersion);
|
||||
|
@ -431,21 +431,21 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean addFilter(PoiUIFilter p, SQLiteConnection db, boolean addOnlyCategories){
|
||||
if(db != null){
|
||||
if(!addOnlyCategories){
|
||||
db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()}); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
protected boolean addFilter(PoiUIFilter p, SQLiteConnection db, boolean addOnlyCategories) {
|
||||
if (db != null) {
|
||||
if (!addOnlyCategories) {
|
||||
db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)", new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()}); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
Map<PoiCategory, LinkedHashSet<String>> types = p.getAcceptedTypes();
|
||||
SQLiteStatement insertCategories = db.compileStatement("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
for(PoiCategory a : types.keySet()){
|
||||
if(types.get(a) == null){
|
||||
for (PoiCategory a : types.keySet()) {
|
||||
if (types.get(a) == null) {
|
||||
insertCategories.bindString(1, p.getFilterId());
|
||||
insertCategories.bindString(2, a.getKeyName());
|
||||
insertCategories.bindNull(3);
|
||||
insertCategories.execute();
|
||||
} else {
|
||||
for(String s : types.get(a)){
|
||||
for (String s : types.get(a)) {
|
||||
insertCategories.bindString(1, p.getFilterId());
|
||||
insertCategories.bindString(2, a.getKeyName());
|
||||
insertCategories.bindString(3, s);
|
||||
|
@ -459,45 +459,45 @@ public class PoiFiltersHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected List<PoiUIFilter> getFilters(SQLiteConnection conn){
|
||||
protected List<PoiUIFilter> getFilters(SQLiteConnection conn) {
|
||||
ArrayList<PoiUIFilter> list = new ArrayList<PoiUIFilter>();
|
||||
if(conn != null){
|
||||
SQLiteCursor query = conn.rawQuery("SELECT " + CATEGORIES_FILTER_ID +", " + CATEGORIES_COL_CATEGORY +"," + CATEGORIES_COL_SUBCATEGORY +" FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
if (conn != null) {
|
||||
SQLiteCursor query = conn.rawQuery("SELECT " + CATEGORIES_FILTER_ID + ", " + CATEGORIES_COL_CATEGORY + "," + CATEGORIES_COL_SUBCATEGORY + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
CATEGORIES_NAME, null);
|
||||
Map<String, Map<PoiCategory, LinkedHashSet<String>>> map = new LinkedHashMap<String, Map<PoiCategory,LinkedHashSet<String>>>();
|
||||
if(query.moveToFirst()){
|
||||
Map<String, Map<PoiCategory, LinkedHashSet<String>>> map = new LinkedHashMap<String, Map<PoiCategory, LinkedHashSet<String>>>();
|
||||
if (query.moveToFirst()) {
|
||||
do {
|
||||
String filterId = query.getString(0);
|
||||
if(!map.containsKey(filterId)){
|
||||
if (!map.containsKey(filterId)) {
|
||||
map.put(filterId, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>());
|
||||
}
|
||||
Map<PoiCategory, LinkedHashSet<String>> m = map.get(filterId);
|
||||
PoiCategory a = mapPoiTypes.getPoiCategoryByName(query.getString(1).toLowerCase(), false);
|
||||
String subCategory = query.getString(2);
|
||||
if(subCategory == null){
|
||||
if (subCategory == null) {
|
||||
m.put(a, null);
|
||||
} else {
|
||||
if(m.get(a) == null){
|
||||
if (m.get(a) == null) {
|
||||
m.put(a, new LinkedHashSet<String>());
|
||||
}
|
||||
m.get(a).add(subCategory);
|
||||
}
|
||||
} while(query.moveToNext());
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
query.close();
|
||||
|
||||
query = conn.rawQuery("SELECT " + FILTER_COL_ID +", " + FILTER_COL_NAME +"," + FILTER_COL_FILTERBYNAME +" FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
query = conn.rawQuery("SELECT " + FILTER_COL_ID + ", " + FILTER_COL_NAME + "," + FILTER_COL_FILTERBYNAME + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
FILTER_NAME, null);
|
||||
if(query.moveToFirst()){
|
||||
if (query.moveToFirst()) {
|
||||
do {
|
||||
String filterId = query.getString(0);
|
||||
if(map.containsKey(filterId)){
|
||||
if (map.containsKey(filterId)) {
|
||||
PoiUIFilter filter = new PoiUIFilter(query.getString(1), filterId,
|
||||
map.get(filterId), application);
|
||||
filter.setSavedFilterByName(query.getString(2));
|
||||
list.add(filter);
|
||||
}
|
||||
} while(query.moveToNext());
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
query.close();
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ public class PoiFiltersHelper {
|
|||
protected boolean editFilter(SQLiteConnection conn, PoiUIFilter filter) {
|
||||
if (conn != null) {
|
||||
conn.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
new Object[] { filter.getFilterId() });
|
||||
new Object[]{filter.getFilterId()});
|
||||
addFilter(filter, conn, true);
|
||||
updateName(conn, filter);
|
||||
return true;
|
||||
|
@ -517,26 +517,25 @@ public class PoiFiltersHelper {
|
|||
|
||||
private void updateName(SQLiteConnection db, PoiUIFilter filter) {
|
||||
db.execSQL("UPDATE " + FILTER_NAME + " SET " + FILTER_COL_FILTERBYNAME + " = ?, " + FILTER_COL_NAME + " = ? " + " WHERE " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||
+ FILTER_COL_ID + "= ?", new Object[] { filter.getFilterByName(), filter.getName(), filter.getFilterId() }); //$NON-NLS-1$
|
||||
+ FILTER_COL_ID + "= ?", new Object[]{filter.getFilterByName(), filter.getName(), filter.getFilterId()}); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected boolean deleteFilter(SQLiteConnection db, PoiUIFilter p){
|
||||
protected boolean deleteFilter(SQLiteConnection db, PoiUIFilter p) {
|
||||
String key = p.getFilterId();
|
||||
return deleteFilter(db, key);
|
||||
}
|
||||
|
||||
private boolean deleteFilter(SQLiteConnection db, String key) {
|
||||
if (db != null) {
|
||||
db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " + FILTER_COL_ID + " = ?", new Object[] { key }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " + FILTER_COL_ID + " = ?", new Object[]{key}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
db.execSQL(
|
||||
"DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", new Object[] { key }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", new Object[]{key}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue