Fix #5769
This commit is contained in:
parent
59a11d723a
commit
6ce93c1c8c
7 changed files with 172 additions and 45 deletions
|
@ -938,7 +938,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
||||||
if (searchFilter.getText().toString().length() > 0) {
|
if (searchFilter.getText().toString().length() > 0) {
|
||||||
nFilter.setSavedFilterByName(searchFilter.getText().toString());
|
nFilter.setSavedFilterByName(searchFilter.getText().toString());
|
||||||
}
|
}
|
||||||
if (app.getPoiFilters().createPoiFilter(nFilter)) {
|
if (app.getPoiFilters().createPoiFilter(nFilter, false)) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
SearchPOIActivity.this,
|
SearchPOIActivity.this,
|
||||||
MessageFormat.format(SearchPOIActivity.this.getText(R.string.edit_filter_create_message).toString(),
|
MessageFormat.format(SearchPOIActivity.this.getText(R.string.edit_filter_create_message).toString(),
|
||||||
|
|
|
@ -50,8 +50,10 @@ public class SearchHistoryHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNewItemToHistory(PoiUIFilter filter) {
|
public void addNewItemToHistory(PoiUIFilter filter) {
|
||||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_CUSTOM_POI_FILTER, filter.getFilterId());
|
String filterId = filter.getFilterId();
|
||||||
|
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_CUSTOM_POI_FILTER, filterId);
|
||||||
addNewItemToHistory(new HistoryEntry(0, 0, pd));
|
addNewItemToHistory(new HistoryEntry(0, 0, pd));
|
||||||
|
context.getPoiFilters().markHistory(filterId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HistoryEntry> getHistoryEntries(boolean onlyPoints) {
|
public List<HistoryEntry> getHistoryEntries(boolean onlyPoints) {
|
||||||
|
@ -71,6 +73,10 @@ public class SearchHistoryHelper {
|
||||||
public void remove(HistoryEntry model) {
|
public void remove(HistoryEntry model) {
|
||||||
HistoryItemDBHelper helper = checkLoadedEntries();
|
HistoryItemDBHelper helper = checkLoadedEntries();
|
||||||
if (helper.remove(model)) {
|
if (helper.remove(model)) {
|
||||||
|
PointDescription pd = model.getName();
|
||||||
|
if (pd.isCustomPoiFilter()) {
|
||||||
|
context.getPoiFilters().markHistory(pd.getName(), false);
|
||||||
|
}
|
||||||
loadedEntries.remove(model);
|
loadedEntries.remove(model);
|
||||||
mp.remove(model.getName());
|
mp.remove(model.getName());
|
||||||
}
|
}
|
||||||
|
@ -79,6 +85,7 @@ public class SearchHistoryHelper {
|
||||||
public void removeAll() {
|
public void removeAll() {
|
||||||
HistoryItemDBHelper helper = checkLoadedEntries();
|
HistoryItemDBHelper helper = checkLoadedEntries();
|
||||||
if (helper.removeAll()) {
|
if (helper.removeAll()) {
|
||||||
|
context.getPoiFilters().clearHistory();
|
||||||
loadedEntries.clear();
|
loadedEntries.clear();
|
||||||
mp.clear();
|
mp.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,9 @@ public class PoiFiltersHelper {
|
||||||
|
|
||||||
public PoiFiltersHelper(OsmandApplication application) {
|
public PoiFiltersHelper(OsmandApplication application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
|
PoiFilterDbHelper helper = openDbHelperNoPois();
|
||||||
|
helper.doDeletion();
|
||||||
|
helper.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NominatimPoiFilter getNominatimPOIFilter() {
|
public NominatimPoiFilter getNominatimPOIFilter() {
|
||||||
|
@ -121,6 +124,18 @@ public class PoiFiltersHelper {
|
||||||
return showAllPOIFilter;
|
return showAllPOIFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void markHistory(String filterId, boolean history) {
|
||||||
|
PoiFilterDbHelper helper = openDbHelperNoPois();
|
||||||
|
helper.markHistory(filterId, history);
|
||||||
|
helper.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearHistory() {
|
||||||
|
PoiFilterDbHelper helper = openDbHelperNoPois();
|
||||||
|
helper.clearHistory();
|
||||||
|
helper.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters) {
|
private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters) {
|
||||||
for (PoiUIFilter pf : filters) {
|
for (PoiUIFilter pf : filters) {
|
||||||
|
@ -132,10 +147,14 @@ public class PoiFiltersHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PoiUIFilter getFilterById(String filterId) {
|
public PoiUIFilter getFilterById(String filterId) {
|
||||||
|
return getFilterById(filterId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PoiUIFilter getFilterById(String filterId, boolean includeDeleted) {
|
||||||
if (filterId == null) {
|
if (filterId == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (PoiUIFilter f : getTopDefinedPoiFilters()) {
|
for (PoiUIFilter f : getTopDefinedPoiFilters(includeDeleted)) {
|
||||||
if (f.getFilterId().equals(filterId)) {
|
if (f.getFilterId().equals(filterId)) {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
@ -176,11 +195,11 @@ public class PoiFiltersHelper {
|
||||||
getTopDefinedPoiFilters();
|
getTopDefinedPoiFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PoiUIFilter> getUserDefinedPoiFilters() {
|
public List<PoiUIFilter> getUserDefinedPoiFilters(boolean includeDeleted) {
|
||||||
ArrayList<PoiUIFilter> userDefinedFilters = new ArrayList<>();
|
ArrayList<PoiUIFilter> userDefinedFilters = new ArrayList<>();
|
||||||
PoiFilterDbHelper helper = openDbHelper();
|
PoiFilterDbHelper helper = openDbHelper();
|
||||||
if (helper != null) {
|
if (helper != null) {
|
||||||
List<PoiUIFilter> userDefined = helper.getFilters(helper.getReadableDatabase());
|
List<PoiUIFilter> userDefined = helper.getFilters(helper.getReadableDatabase(), includeDeleted);
|
||||||
userDefinedFilters.addAll(userDefined);
|
userDefinedFilters.addAll(userDefined);
|
||||||
helper.close();
|
helper.close();
|
||||||
}
|
}
|
||||||
|
@ -200,10 +219,14 @@ public class PoiFiltersHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PoiUIFilter> getTopDefinedPoiFilters() {
|
public List<PoiUIFilter> getTopDefinedPoiFilters() {
|
||||||
|
return getTopDefinedPoiFilters(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PoiUIFilter> getTopDefinedPoiFilters(boolean includeDeleted) {
|
||||||
if (cacheTopStandardFilters == null) {
|
if (cacheTopStandardFilters == null) {
|
||||||
List<PoiUIFilter> top = new ArrayList<>();
|
List<PoiUIFilter> top = new ArrayList<>();
|
||||||
// user defined
|
// user defined
|
||||||
top.addAll(getUserDefinedPoiFilters());
|
top.addAll(getUserDefinedPoiFilters(true));
|
||||||
if (getLocalWikiPOIFilter() != null) {
|
if (getLocalWikiPOIFilter() != null) {
|
||||||
top.add(getLocalWikiPOIFilter());
|
top.add(getLocalWikiPOIFilter());
|
||||||
}
|
}
|
||||||
|
@ -216,11 +239,20 @@ public class PoiFiltersHelper {
|
||||||
Collections.sort(top);
|
Collections.sort(top);
|
||||||
cacheTopStandardFilters = top;
|
cacheTopStandardFilters = top;
|
||||||
}
|
}
|
||||||
List<PoiUIFilter> result = new ArrayList<>(cacheTopStandardFilters);
|
List<PoiUIFilter> result = new ArrayList<>();
|
||||||
|
for (PoiUIFilter filter : cacheTopStandardFilters) {
|
||||||
|
if (includeDeleted || !filter.isDeleted()) {
|
||||||
|
result.add(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
result.add(getShowAllPOIFilter());
|
result.add(getShowAllPOIFilter());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PoiFilterDbHelper openDbHelperNoPois() {
|
||||||
|
return new PoiFilterDbHelper(null, application);
|
||||||
|
}
|
||||||
|
|
||||||
private PoiFilterDbHelper openDbHelper() {
|
private PoiFilterDbHelper openDbHelper() {
|
||||||
if (!application.getPoiTypes().isInit()) {
|
if (!application.getPoiTypes().isInit()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -238,29 +270,24 @@ public class PoiFiltersHelper {
|
||||||
if (helper == null) {
|
if (helper == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
|
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter, false);
|
||||||
if (res) {
|
|
||||||
ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters);
|
|
||||||
copy.remove(filter);
|
|
||||||
cacheTopStandardFilters = copy;
|
|
||||||
}
|
|
||||||
helper.close();
|
helper.close();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean createPoiFilter(PoiUIFilter filter) {
|
public boolean createPoiFilter(PoiUIFilter filter, boolean forHistory) {
|
||||||
PoiFilterDbHelper helper = openDbHelper();
|
PoiFilterDbHelper helper = openDbHelper();
|
||||||
if (helper == null) {
|
if (helper == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
|
helper.deleteFilter(helper.getWritableDatabase(), filter, true);
|
||||||
Iterator<PoiUIFilter> it = cacheTopStandardFilters.iterator();
|
Iterator<PoiUIFilter> it = cacheTopStandardFilters.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if (it.next().getFilterId().equals(filter.getFilterId())) {
|
if (it.next().getFilterId().equals(filter.getFilterId())) {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = helper.addFilter(filter, helper.getWritableDatabase(), false);
|
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false, forHistory);
|
||||||
if (res) {
|
if (res) {
|
||||||
ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters);
|
ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters);
|
||||||
copy.add(filter);
|
copy.add(filter);
|
||||||
|
@ -362,19 +389,26 @@ public class PoiFiltersHelper {
|
||||||
|
|
||||||
public class PoiFilterDbHelper {
|
public class PoiFilterDbHelper {
|
||||||
|
|
||||||
|
private static final int TRUE_INT = 1;
|
||||||
|
private static final int FALSE_INT = 0;
|
||||||
|
|
||||||
public static final String DATABASE_NAME = "poi_filters";
|
public static final String DATABASE_NAME = "poi_filters";
|
||||||
private static final int DATABASE_VERSION = 5;
|
private static final int DATABASE_VERSION = 6;
|
||||||
|
|
||||||
private static final String FILTER_NAME = "poi_filters";
|
private static final String FILTER_NAME = "poi_filters";
|
||||||
private static final String FILTER_COL_NAME = "name";
|
private static final String FILTER_COL_NAME = "name";
|
||||||
private static final String FILTER_COL_ID = "id";
|
private static final String FILTER_COL_ID = "id";
|
||||||
private static final String FILTER_COL_FILTERBYNAME = "filterbyname";
|
private static final String FILTER_COL_FILTERBYNAME = "filterbyname";
|
||||||
|
private static final String FILTER_COL_HISTORY = "history";
|
||||||
|
private static final String FILTER_COL_DELETED = "deleted";
|
||||||
|
|
||||||
private static final String FILTER_TABLE_CREATE = "CREATE TABLE " +
|
private static final String FILTER_TABLE_CREATE = "CREATE TABLE " +
|
||||||
FILTER_NAME + " (" +
|
FILTER_NAME + " (" +
|
||||||
FILTER_COL_NAME + ", " +
|
FILTER_COL_NAME + ", " +
|
||||||
FILTER_COL_ID + ", " +
|
FILTER_COL_ID + ", " +
|
||||||
FILTER_COL_FILTERBYNAME + ");";
|
FILTER_COL_FILTERBYNAME + ", " +
|
||||||
|
FILTER_COL_HISTORY + ", " +
|
||||||
|
FILTER_COL_DELETED + ");";
|
||||||
|
|
||||||
private static final String CATEGORIES_NAME = "categories";
|
private static final String CATEGORIES_NAME = "categories";
|
||||||
private static final String CATEGORIES_FILTER_ID = "filter_id";
|
private static final String CATEGORIES_FILTER_ID = "filter_id";
|
||||||
|
@ -439,19 +473,61 @@ public class PoiFiltersHelper {
|
||||||
if (newVersion <= 5) {
|
if (newVersion <= 5) {
|
||||||
deleteOldFilters(conn);
|
deleteOldFilters(conn);
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 6) {
|
||||||
|
conn.execSQL("ALTER TABLE " + FILTER_NAME + " ADD " + FILTER_COL_HISTORY + " int DEFAULT " + FALSE_INT);
|
||||||
|
conn.execSQL("ALTER TABLE " + FILTER_NAME + " ADD " + FILTER_COL_DELETED + " int DEFAULT " + FALSE_INT);
|
||||||
|
}
|
||||||
conn.setVersion(newVersion);
|
conn.setVersion(newVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteOldFilters(SQLiteConnection conn) {
|
private void deleteOldFilters(SQLiteConnection conn) {
|
||||||
|
if (conn != null) {
|
||||||
for (String toDel : DEL) {
|
for (String toDel : DEL) {
|
||||||
deleteFilter(conn, "user_" + toDel);
|
deleteFilter(conn, "user_" + toDel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean addFilter(PoiUIFilter p, SQLiteConnection db, boolean addOnlyCategories) {
|
void doDeletion() {
|
||||||
|
SQLiteConnection conn = getWritableDatabase();
|
||||||
|
if (conn != null) {
|
||||||
|
String query = "SELECT " + FILTER_COL_ID + ", " + FILTER_COL_HISTORY + ", " + FILTER_COL_DELETED + " FROM " + FILTER_NAME;
|
||||||
|
SQLiteCursor cursor = conn.rawQuery(query, null);
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
if (cursor.getInt(1) == FALSE_INT && cursor.getInt(2) == TRUE_INT) {
|
||||||
|
deleteFilter(conn, cursor.getString(0));
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void markHistory(String filterId, boolean history) {
|
||||||
|
SQLiteConnection conn = getWritableDatabase();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.execSQL("UPDATE " + FILTER_NAME + " SET " + FILTER_COL_HISTORY + " = ? WHERE " + FILTER_COL_ID + " = ?",
|
||||||
|
new Object[]{history ? TRUE_INT : FALSE_INT, filterId});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearHistory() {
|
||||||
|
SQLiteConnection conn = getWritableDatabase();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.execSQL("UPDATE " + FILTER_NAME + " SET " + FILTER_COL_HISTORY + " = ?", new Object[]{FALSE_INT});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean addFilter(PoiUIFilter p, SQLiteConnection db, boolean addOnlyCategories, boolean forHistory) {
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
if (!addOnlyCategories) {
|
if (!addOnlyCategories) {
|
||||||
db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)", new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()});
|
p.setDeleted(forHistory);
|
||||||
|
int value = forHistory ? TRUE_INT : FALSE_INT;
|
||||||
|
db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?, ?, ?)",
|
||||||
|
new Object[]{p.getName(), p.getFilterId(), p.getFilterByName(), value, value});
|
||||||
}
|
}
|
||||||
Map<PoiCategory, LinkedHashSet<String>> types = p.getAcceptedTypes();
|
Map<PoiCategory, LinkedHashSet<String>> types = p.getAcceptedTypes();
|
||||||
SQLiteStatement insertCategories = db.compileStatement("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)");
|
SQLiteStatement insertCategories = db.compileStatement("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)");
|
||||||
|
@ -476,7 +552,7 @@ public class PoiFiltersHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<PoiUIFilter> getFilters(SQLiteConnection conn) {
|
protected List<PoiUIFilter> getFilters(SQLiteConnection conn, boolean includeDeleted) {
|
||||||
ArrayList<PoiUIFilter> list = new ArrayList<>();
|
ArrayList<PoiUIFilter> list = new ArrayList<>();
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
SQLiteCursor query = conn.rawQuery("SELECT " + CATEGORIES_FILTER_ID + ", " + CATEGORIES_COL_CATEGORY + "," + CATEGORIES_COL_SUBCATEGORY + " FROM " +
|
SQLiteCursor query = conn.rawQuery("SELECT " + CATEGORIES_FILTER_ID + ", " + CATEGORIES_COL_CATEGORY + "," + CATEGORIES_COL_SUBCATEGORY + " FROM " +
|
||||||
|
@ -505,15 +581,21 @@ public class PoiFiltersHelper {
|
||||||
query.close();
|
query.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
query = conn.rawQuery("SELECT " + FILTER_COL_ID + ", " + FILTER_COL_NAME + "," + FILTER_COL_FILTERBYNAME + " FROM " +
|
query = conn.rawQuery("SELECT " +
|
||||||
FILTER_NAME, null);
|
FILTER_COL_ID + ", " +
|
||||||
|
FILTER_COL_NAME + ", " +
|
||||||
|
FILTER_COL_FILTERBYNAME + ", " +
|
||||||
|
FILTER_COL_DELETED +
|
||||||
|
" FROM " + FILTER_NAME, null);
|
||||||
if (query != null && query.moveToFirst()) {
|
if (query != null && query.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
String filterId = query.getString(0);
|
String filterId = query.getString(0);
|
||||||
if (map.containsKey(filterId)) {
|
boolean deleted = query.getInt(3) == TRUE_INT;
|
||||||
|
if (map.containsKey(filterId) && (includeDeleted || !deleted)) {
|
||||||
PoiUIFilter filter = new PoiUIFilter(query.getString(1), filterId,
|
PoiUIFilter filter = new PoiUIFilter(query.getString(1), filterId,
|
||||||
map.get(filterId), application);
|
map.get(filterId), application);
|
||||||
filter.setSavedFilterByName(query.getString(2));
|
filter.setSavedFilterByName(query.getString(2));
|
||||||
|
filter.setDeleted(deleted);
|
||||||
list.add(filter);
|
list.add(filter);
|
||||||
}
|
}
|
||||||
} while (query.moveToNext());
|
} while (query.moveToNext());
|
||||||
|
@ -529,7 +611,7 @@ public class PoiFiltersHelper {
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
conn.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?",
|
conn.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?",
|
||||||
new Object[]{filter.getFilterId()});
|
new Object[]{filter.getFilterId()});
|
||||||
addFilter(filter, conn, true);
|
addFilter(filter, conn, true, false);
|
||||||
updateName(conn, filter);
|
updateName(conn, filter);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -541,19 +623,22 @@ public class PoiFiltersHelper {
|
||||||
+ FILTER_COL_ID + "= ?", new Object[]{filter.getFilterByName(), filter.getName(), filter.getFilterId()});
|
+ FILTER_COL_ID + "= ?", new Object[]{filter.getFilterByName(), filter.getName(), filter.getFilterId()});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean deleteFilter(SQLiteConnection db, PoiUIFilter p) {
|
protected boolean deleteFilter(SQLiteConnection db, PoiUIFilter p, boolean force) {
|
||||||
String key = p.getFilterId();
|
|
||||||
return deleteFilter(db, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean deleteFilter(SQLiteConnection db, String key) {
|
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " + FILTER_COL_ID + " = ?", new Object[]{key});
|
if (force) {
|
||||||
db.execSQL(
|
deleteFilter(db, p.getFilterId());
|
||||||
"DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", new Object[]{key});
|
} else {
|
||||||
|
db.execSQL("UPDATE " + FILTER_NAME + " SET " + FILTER_COL_DELETED + " = ? WHERE " + FILTER_COL_ID + " = ?",
|
||||||
|
new Object[]{TRUE_INT, p.getFilterId()});
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteFilter(@NonNull SQLiteConnection db, String key) {
|
||||||
|
db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " + FILTER_COL_ID + " = ?", new Object[]{key});
|
||||||
|
db.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", new Object[]{key});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
protected String savedFilterByName = null;
|
protected String savedFilterByName = null;
|
||||||
protected List<Amenity> currentSearchResult = null;
|
protected List<Amenity> currentSearchResult = null;
|
||||||
|
|
||||||
|
private boolean deleted;
|
||||||
|
|
||||||
// constructor for standard filters
|
// constructor for standard filters
|
||||||
public PoiUIFilter(AbstractPoiType type, OsmandApplication application, String idSuffix) {
|
public PoiUIFilter(AbstractPoiType type, OsmandApplication application, String idSuffix) {
|
||||||
this.app = application;
|
this.app = application;
|
||||||
|
@ -120,6 +122,14 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
name = app.getPoiFilters().getFiltersName(filtersToMerge);
|
name = app.getPoiFilters().getFiltersName(filtersToMerge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDeleted() {
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
public String getFilterByName() {
|
public String getFilterByName() {
|
||||||
return filterByName;
|
return filterByName;
|
||||||
}
|
}
|
||||||
|
@ -497,6 +507,17 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
return res.toString();
|
return res.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTypesName() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (PoiCategory p : acceptedTypes.keySet()) {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append(", ");
|
||||||
|
}
|
||||||
|
sb.append(p.getTranslation());
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type
|
* @param type
|
||||||
* @return null if all subtypes are accepted/ empty list if type is not accepted at all
|
* @return null if all subtypes are accepted/ empty list if type is not accepted at all
|
||||||
|
|
|
@ -728,7 +728,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
if (!Algorithms.isEmpty(filter.getFilterByName())) {
|
if (!Algorithms.isEmpty(filter.getFilterByName())) {
|
||||||
nFilter.setSavedFilterByName(filter.getFilterByName());
|
nFilter.setSavedFilterByName(filter.getFilterByName());
|
||||||
}
|
}
|
||||||
if (app.getPoiFilters().createPoiFilter(nFilter)) {
|
if (app.getPoiFilters().createPoiFilter(nFilter, false)) {
|
||||||
Toast.makeText(getContext(), MessageFormat.format(getContext().getText(R.string.edit_filter_create_message).toString(),
|
Toast.makeText(getContext(), MessageFormat.format(getContext().getText(R.string.edit_filter_create_message).toString(),
|
||||||
editText.getText().toString()), Toast.LENGTH_SHORT).show();
|
editText.getText().toString()), Toast.LENGTH_SHORT).show();
|
||||||
app.getSearchUICore().refreshCustomPoiFilters();
|
app.getSearchUICore().refreshCustomPoiFilters();
|
||||||
|
@ -2151,6 +2151,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
fabVisible = true;
|
fabVisible = true;
|
||||||
poiFilterApplied = true;
|
poiFilterApplied = true;
|
||||||
updateFab();
|
updateFab();
|
||||||
|
|
||||||
|
PoiUIFilter nFilter = new PoiUIFilter(filter.getTypesName(), null, filter.getAcceptedTypes(), app);
|
||||||
|
if (!Algorithms.isEmpty(filter.getFilterByName())) {
|
||||||
|
nFilter.setSavedFilterByName(filter.getFilterByName());
|
||||||
|
}
|
||||||
|
app.getPoiFilters().createPoiFilter(nFilter, true);
|
||||||
|
SearchHistoryHelper.getInstance(app).addNewItemToHistory(nFilter);
|
||||||
|
reloadHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchResult sr = new SearchResult(searchUICore.getPhrase());
|
SearchResult sr = new SearchResult(searchUICore.getPhrase());
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
public void refreshCustomPoiFilters() {
|
public void refreshCustomPoiFilters() {
|
||||||
core.clearCustomSearchPoiFilters();
|
core.clearCustomSearchPoiFilters();
|
||||||
PoiFiltersHelper poiFilters = app.getPoiFilters();
|
PoiFiltersHelper poiFilters = app.getPoiFilters();
|
||||||
for (CustomSearchPoiFilter udf : poiFilters.getUserDefinedPoiFilters()) {
|
for (CustomSearchPoiFilter udf : poiFilters.getUserDefinedPoiFilters(false)) {
|
||||||
core.addCustomSearchPoiFilter(udf, 0);
|
core.addCustomSearchPoiFilter(udf, 0);
|
||||||
}
|
}
|
||||||
PoiUIFilter localWikiPoiFilter = poiFilters.getLocalWikiPOIFilter();
|
PoiUIFilter localWikiPoiFilter = poiFilters.getLocalWikiPOIFilter();
|
||||||
|
@ -399,6 +399,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||||
int p = 0;
|
int p = 0;
|
||||||
for (HistoryEntry point : SearchHistoryHelper.getInstance(app).getHistoryEntries(false)) {
|
for (HistoryEntry point : SearchHistoryHelper.getInstance(app).getHistoryEntries(false)) {
|
||||||
|
boolean publish = false;
|
||||||
SearchResult sr = new SearchResult(phrase);
|
SearchResult sr = new SearchResult(phrase);
|
||||||
PointDescription pd = point.getName();
|
PointDescription pd = point.getName();
|
||||||
if (pd.isPoiType()) {
|
if (pd.isPoiType()) {
|
||||||
|
@ -408,13 +409,15 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
sr.object = pt;
|
sr.object = pt;
|
||||||
sr.priorityDistance = 0;
|
sr.priorityDistance = 0;
|
||||||
sr.objectType = ObjectType.POI_TYPE;
|
sr.objectType = ObjectType.POI_TYPE;
|
||||||
|
publish = true;
|
||||||
}
|
}
|
||||||
} else if (pd.isCustomPoiFilter()) {
|
} else if (pd.isCustomPoiFilter()) {
|
||||||
PoiUIFilter filter = app.getPoiFilters().getFilterById(pd.getName());
|
PoiUIFilter filter = app.getPoiFilters().getFilterById(pd.getName(), true);
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
sr.localeName = filter.getName();
|
sr.localeName = filter.getName();
|
||||||
sr.object = filter;
|
sr.object = filter;
|
||||||
sr.objectType = ObjectType.POI_TYPE;
|
sr.objectType = ObjectType.POI_TYPE;
|
||||||
|
publish = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sr.localeName = pd.getName();
|
sr.localeName = pd.getName();
|
||||||
|
@ -422,7 +425,9 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
sr.objectType = ObjectType.RECENT_OBJ;
|
sr.objectType = ObjectType.RECENT_OBJ;
|
||||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||||
sr.preferredZoom = 17;
|
sr.preferredZoom = 17;
|
||||||
|
publish = true;
|
||||||
}
|
}
|
||||||
|
if (publish) {
|
||||||
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++);
|
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++);
|
||||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||||
resultMatcher.publish(sr);
|
resultMatcher.publish(sr);
|
||||||
|
@ -430,6 +435,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
resultMatcher.publish(sr);
|
resultMatcher.publish(sr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,7 +370,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
if (!Algorithms.isEmpty(filter.getFilterByName())) {
|
if (!Algorithms.isEmpty(filter.getFilterByName())) {
|
||||||
nFilter.setSavedFilterByName(filter.getFilterByName());
|
nFilter.setSavedFilterByName(filter.getFilterByName());
|
||||||
}
|
}
|
||||||
if (app.getPoiFilters().createPoiFilter(nFilter)) {
|
if (app.getPoiFilters().createPoiFilter(nFilter, false)) {
|
||||||
Toast.makeText(getContext(), MessageFormat.format(getContext().getText(R.string.edit_filter_create_message).toString(),
|
Toast.makeText(getContext(), MessageFormat.format(getContext().getText(R.string.edit_filter_create_message).toString(),
|
||||||
editText.getText().toString()), Toast.LENGTH_SHORT).show();
|
editText.getText().toString()), Toast.LENGTH_SHORT).show();
|
||||||
app.getSearchUICore().refreshCustomPoiFilters();
|
app.getSearchUICore().refreshCustomPoiFilters();
|
||||||
|
|
Loading…
Reference in a new issue