commit
181382dccd
4 changed files with 42 additions and 63 deletions
|
@ -1,10 +1,5 @@
|
|||
package net.osmand.data;
|
||||
|
||||
import net.osmand.LocationConvert;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -13,6 +8,12 @@ import com.google.openlocationcode.OpenLocationCode;
|
|||
import com.jwetherell.openmap.common.LatLonPoint;
|
||||
import com.jwetherell.openmap.common.UTMPoint;
|
||||
|
||||
import net.osmand.LocationConvert;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class PointDescription {
|
||||
private String type = "";
|
||||
private String name = "";
|
||||
|
@ -46,6 +47,7 @@ public class PointDescription {
|
|||
public static final String POINT_TYPE_TRANSPORT_ROUTE = "transport_route";
|
||||
public static final String POINT_TYPE_TRANSPORT_STOP = "transport_stop";
|
||||
public static final String POINT_TYPE_MAPILLARY_IMAGE = "mapillary_image";
|
||||
public static final String POINT_TYPE_POI_TYPE = "poi_type";
|
||||
|
||||
|
||||
public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, "");
|
||||
|
@ -253,6 +255,10 @@ public class PointDescription {
|
|||
return POINT_TYPE_MY_LOCATION.equals(type);
|
||||
}
|
||||
|
||||
public boolean isPoiType() {
|
||||
return POINT_TYPE_POI_TYPE.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
|
|
@ -2,8 +2,8 @@ package net.osmand.plus.helpers;
|
|||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -43,6 +43,11 @@ public class SearchHistoryHelper {
|
|||
addNewItemToHistory(new HistoryEntry(latitude, longitude, pointDescription));
|
||||
}
|
||||
|
||||
public void addNewItemToHistory(AbstractPoiType pt) {
|
||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_POI_TYPE, pt.getKeyName());
|
||||
addNewItemToHistory(new HistoryEntry(0, 0, pd));
|
||||
}
|
||||
|
||||
public List<HistoryEntry> getHistoryEntries() {
|
||||
if (loadedEntries == null) {
|
||||
checkLoadedEntries();
|
||||
|
@ -276,7 +281,7 @@ public class SearchHistoryHelper {
|
|||
if (conn.getVersion() == 0 || DB_VERSION != conn.getVersion()) {
|
||||
if (readonly) {
|
||||
conn.close();
|
||||
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
|
||||
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
|
||||
}
|
||||
if (conn.getVersion() == 0) {
|
||||
onCreate(conn);
|
||||
|
@ -293,11 +298,9 @@ public class SearchHistoryHelper {
|
|||
}
|
||||
|
||||
public void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
|
||||
if (newVersion == 2) {
|
||||
db.execSQL(HISTORY_TABLE_CREATE);
|
||||
for (HistoryEntry he : getLegacyEntries(db)) {
|
||||
insert(he, db);
|
||||
}
|
||||
if (oldVersion < 2) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + HISTORY_TABLE_NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,46 +374,6 @@ public class SearchHistoryHelper {
|
|||
e.getIntervals(), e.getIntervalsValues(), e.getLat(), e.getLon()});
|
||||
}
|
||||
|
||||
List<HistoryEntry> getLegacyEntries(SQLiteConnection db) {
|
||||
List<HistoryEntry> entries = new ArrayList<>();
|
||||
if (db != null) {
|
||||
// LEGACY QUERY !!
|
||||
SQLiteCursor query = db.rawQuery(
|
||||
"SELECT name, latitude, longitude, time FROM history ORDER BY time DESC", null);
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
String name = query.getString(0);
|
||||
String type = PointDescription.POINT_TYPE_MARKER;
|
||||
// make it proper name with type
|
||||
if (name.contains(context.getString(R.string.favorite))) {
|
||||
type = PointDescription.POINT_TYPE_FAVORITE;
|
||||
} else if (name.contains(context.getString(R.string.search_address_building))) {
|
||||
type = PointDescription.POINT_TYPE_ADDRESS;
|
||||
} else if (name.contains(context.getString(R.string.search_address_city))) {
|
||||
type = PointDescription.POINT_TYPE_ADDRESS;
|
||||
} else if (name.contains(context.getString(R.string.search_address_street))) {
|
||||
type = PointDescription.POINT_TYPE_ADDRESS;
|
||||
} else if (name.contains(context.getString(R.string.search_address_street_option))) {
|
||||
type = PointDescription.POINT_TYPE_ADDRESS;
|
||||
} else if (name.contains(context.getString(R.string.poi))) {
|
||||
type = PointDescription.POINT_TYPE_POI;
|
||||
}
|
||||
if (name.contains(":")) {
|
||||
name = name.substring(name.indexOf(':') + 1);
|
||||
}
|
||||
HistoryEntry e = new HistoryEntry(query.getDouble(1), query.getDouble(2), new PointDescription(
|
||||
type, name));
|
||||
e.markAsAccessed(query.getLong(3));
|
||||
entries.add(e);
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if (query != null) {
|
||||
query.close();
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
public List<HistoryEntry> getEntries() {
|
||||
List<HistoryEntry> entries = new ArrayList<>();
|
||||
SQLiteConnection db = openConnection(true);
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.support.annotation.Nullable;
|
|||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
@ -68,7 +67,6 @@ import net.osmand.plus.OsmAndFormatter;
|
|||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -76,7 +74,6 @@ import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
|
|||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.resources.RegionAddressRepository;
|
||||
import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI;
|
||||
import net.osmand.plus.search.listitems.QuickSearchButtonListItem;
|
||||
|
@ -1776,6 +1773,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
}
|
||||
|
||||
public void completeQueryWithObject(SearchResult sr) {
|
||||
if (sr.object instanceof AbstractPoiType) {
|
||||
SearchHistoryHelper.getInstance(app).addNewItemToHistory((AbstractPoiType) sr.object);
|
||||
reloadHistory();
|
||||
}
|
||||
if (sr.object instanceof PoiType && ((PoiType) sr.object).isAdditional()) {
|
||||
PoiType additional = (PoiType) sr.object;
|
||||
AbstractPoiType parent = additional.getParentType();
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.plus.OsmAndFormatter;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.poi.NominatimPoiFilter;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
|
@ -395,17 +396,25 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
|
||||
List<SearchHistoryHelper.HistoryEntry> points = helper.getHistoryEntries();
|
||||
int p = 0;
|
||||
for (SearchHistoryHelper.HistoryEntry point : points) {
|
||||
for (HistoryEntry point : SearchHistoryHelper.getInstance(app).getHistoryEntries()) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getName().getName();
|
||||
sr.object = point;
|
||||
if (point.getName().isPoiType()) {
|
||||
AbstractPoiType pt = MapPoiTypes.getDefault().getAnyPoiTypeByKey(point.getName().getName());
|
||||
if (pt != null) {
|
||||
sr.localeName = pt.getTranslation();
|
||||
sr.object = pt;
|
||||
sr.priorityDistance = 0;
|
||||
sr.objectType = ObjectType.POI_TYPE;
|
||||
}
|
||||
} else {
|
||||
sr.localeName = point.getName().getName();
|
||||
sr.object = point;
|
||||
sr.objectType = ObjectType.RECENT_OBJ;
|
||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||
sr.preferredZoom = 17;
|
||||
}
|
||||
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++);
|
||||
sr.objectType = ObjectType.RECENT_OBJ;
|
||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
|
|
Loading…
Reference in a new issue