From 61b076e27f04f256343a580193b2642318628227 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 24 Sep 2018 16:19:59 +0300 Subject: [PATCH 1/2] Remove old code; fix readonly --- .../plus/helpers/SearchHistoryHelper.java | 51 ++----------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java index decc023bfe..78e9b0f848 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java @@ -3,7 +3,6 @@ package net.osmand.plus.helpers; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; 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; @@ -276,7 +275,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 +292,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 +368,6 @@ public class SearchHistoryHelper { e.getIntervals(), e.getIntervalsValues(), e.getLat(), e.getLon()}); } - List getLegacyEntries(SQLiteConnection db) { - List 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 getEntries() { List entries = new ArrayList<>(); SQLiteConnection db = openConnection(true); From cc28fa43123bae7991e7d6e2a156898cad134fdb Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 24 Sep 2018 16:33:38 +0300 Subject: [PATCH 2/2] Add categories to search history --- .../src/net/osmand/data/PointDescription.java | 16 ++++++++---- .../plus/helpers/SearchHistoryHelper.java | 6 +++++ .../search/QuickSearchDialogFragment.java | 7 +++--- .../osmand/plus/search/QuickSearchHelper.java | 25 +++++++++++++------ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index 285171cce5..fd5e406b41 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java index 78e9b0f848..6f33854f4c 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java @@ -2,6 +2,7 @@ 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.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; @@ -42,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 getHistoryEntries() { if (loadedEntries == null) { checkLoadedEntries(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index f46f9abef7..1cc5dab5b2 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -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(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 26e398f86b..ffe0d8361c 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -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 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)) {