diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java b/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java index c14d5cff07..df81a9ce18 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/ObjectType.java @@ -8,7 +8,7 @@ public enum ObjectType { // LOCATION LOCATION(true), PARTIAL_LOCATION(false), // UI OBJECTS - FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true), + FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true), GPX_TRACK(false), // ONLINE SEARCH ONLINE_SEARCH(true), diff --git a/OsmAnd/res/layout/search_gpx_list_item.xml b/OsmAnd/res/layout/search_gpx_list_item.xml new file mode 100644 index 0000000000..090513c7be --- /dev/null +++ b/OsmAnd/res/layout/search_gpx_list_item.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index 28c5e12519..41c46d0dcf 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -47,6 +47,7 @@ public class PointDescription { public static final String POINT_TYPE_OSM_BUG = "bug"; public static final String POINT_TYPE_WORLD_REGION = "world_region"; public static final String POINT_TYPE_GPX_ITEM = "gpx_item"; + public static final String POINT_TYPE_GPX_FILE = "gpx_file"; public static final String POINT_TYPE_WORLD_REGION_SHOW_ON_MAP = "world_region_show_on_map"; public static final String POINT_TYPE_BLOCKED_ROAD = "blocked_road"; public static final String POINT_TYPE_TRANSPORT_ROUTE = "transport_route"; @@ -297,6 +298,10 @@ public class PointDescription { return POINT_TYPE_GPX.equals(type); } + public boolean isGpxFile() { + return POINT_TYPE_GPX_FILE.equals(type); + } + @Override public int hashCode() { final int prime = 31; diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 69c159bed0..72aa50552e 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -27,6 +27,7 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; +import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.plus.mapmarkers.MapMarkersHelper; @@ -581,7 +582,7 @@ public class GpxSelectionHelper { } else if (obj.has(BACKUP)) { selectedGpxFilesBackUp.put(gpx, gpx.modifiedTime); } else { - SelectedGpxFile file = selectGpxFile(gpx, true, false, true, selectedByUser, false); + SelectedGpxFile file = selectGpxFile(gpx, true, false, true, selectedByUser, false, false); if (obj.has(HIDDEN_GROUPS)) { readHiddenGroups(file, obj.getString(HIDDEN_GROUPS)); } @@ -684,7 +685,13 @@ public class GpxSelectionHelper { app.getSettings().SELECTED_GPX.set(ar.toString()); } - private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, GpxDataItem dataItem, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) { + private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, + GpxDataItem dataItem, + boolean show, + boolean notShowNavigationDialog, + boolean syncGroup, + boolean selectedByUser, + boolean addToHistory) { boolean displayed; SelectedGpxFile sf; if (gpx != null && gpx.showCurrentTrack) { @@ -724,6 +731,12 @@ public class GpxSelectionHelper { if (sf != null) { sf.splitProcessed = false; } + if (show && selectedByUser && addToHistory) { + String path = gpx.path; + String rootGpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath() + '/'; + String fileName = path.replace(rootGpxDir, ""); + SearchHistoryHelper.getInstance(app).addGpxFileToHistory(fileName); + } return sf; } @@ -749,18 +762,39 @@ public class GpxSelectionHelper { return selectGpxFile(gpx, show, notShowNavigationDialog, true, true, true); } - public SelectedGpxFile selectGpxFile(GPXFile gpx, GpxDataItem dataItem, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) { - SelectedGpxFile sf = selectGpxFileImpl(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser); + public SelectedGpxFile selectGpxFile(GPXFile gpx, + GpxDataItem dataItem, + boolean show, + boolean notShowNavigationDialog, + boolean syncGroup, + boolean selectedByUser, + boolean addToHistory) { + SelectedGpxFile sf = selectGpxFileImpl(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser, addToHistory); saveCurrentSelections(); return sf; } - public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser, boolean canAddToMarkers) { + public SelectedGpxFile selectGpxFile(GPXFile gpx, + boolean show, + boolean notShowNavigationDialog, + boolean syncGroup, + boolean selectedByUser, + boolean canAddToMarkers) { + return selectGpxFile(gpx, show, notShowNavigationDialog, syncGroup, selectedByUser, canAddToMarkers, true); + } + + public SelectedGpxFile selectGpxFile(GPXFile gpx, + boolean show, + boolean notShowNavigationDialog, + boolean syncGroup, + boolean selectedByUser, + boolean canAddToMarkers, + boolean addToHistory) { GpxDataItem dataItem = app.getGpxDbHelper().getItem(new File(gpx.path)); if (canAddToMarkers && show && dataItem != null && dataItem.isShowAsMarkers()) { app.getMapMarkersHelper().addOrEnableGroup(gpx); } - return selectGpxFile(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser); + return selectGpxFile(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser, addToHistory); } public void clearPoints(GPXFile gpxFile) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index c2f3d831b8..a4cdd3e264 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -93,7 +93,6 @@ import net.osmand.plus.activities.ActivityResultListener; import net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.PluginsFragment; -import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.GpxAppearanceAdapter; import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; import net.osmand.plus.helpers.enums.MetricsConstants; @@ -751,13 +750,32 @@ public class GpxUiHelper { gpxDbHelper.updateShowStartFinish(item, showStartFinish); } - public static void updateGpxInfoView(View v, String itemTitle, GPXInfo info, GpxDataItem dataItem, boolean currentlyRecordingTrack, OsmandApplication app) { + public static void updateGpxInfoView(OsmandApplication app, + View v, + String itemTitle, + Drawable iconDrawable, + GPXInfo info) { + GpxDataItem dataItem = getDataItem(app, info); + updateGpxInfoView(v, itemTitle, info, dataItem, false, app); + if (iconDrawable != null) { + ImageView icon = (ImageView) v.findViewById(R.id.icon); + icon.setImageDrawable(iconDrawable); + icon.setVisibility(View.VISIBLE); + } + } + + public static void updateGpxInfoView(View v, + String itemTitle, + GPXInfo info, + GpxDataItem dataItem, + boolean currentlyRecordingTrack, + OsmandApplication app) { TextView viewName = ((TextView) v.findViewById(R.id.name)); viewName.setText(itemTitle.replace("/", " • ").trim()); + viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); ImageView icon = (ImageView) v.findViewById(R.id.icon); icon.setVisibility(View.GONE); //icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_polygom_dark)); - viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); GPXTrackAnalysis analysis = null; if (currentlyRecordingTrack) { @@ -809,9 +827,19 @@ public class GpxUiHelper { } TextView descr = ((TextView) v.findViewById(R.id.description)); - descr.setVisibility(View.GONE); + if (descr != null) { + descr.setVisibility(View.GONE); + } - v.findViewById(R.id.check_item).setVisibility(View.GONE); + View checkbox = v.findViewById(R.id.check_item); + if (checkbox != null) { + checkbox.setVisibility(View.GONE); + } + } + + private static GpxDataItem getDataItem(OsmandApplication app, GPXInfo info) { + return app.getGpxDbHelper().getItem( + new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), info.getFileName())); } @TargetApi(Build.VERSION_CODES.KITKAT) @@ -884,6 +912,17 @@ public class GpxUiHelper { return list; } + @Nullable + public static GPXInfo getGpxInfoByFileName(@NonNull OsmandApplication app, @NonNull String fileName) { + final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); + List infoList = getSortedGPXFilesInfo(dir, null, false); + for (GPXInfo info : infoList) { + if (Algorithms.objectEquals(info.fileName, fileName)) { + return info; + } + } + return null; + } public static List getSortedGPXFilesInfo(File dir, final List selectedGpxList, boolean absolutePath) { final List list = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java index 693227f434..e2fe995b4b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java @@ -16,6 +16,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static net.osmand.data.PointDescription.POINT_TYPE_GPX_FILE; + public class SearchHistoryHelper { private static final int HISTORY_LIMIT = 1500; @@ -40,6 +42,10 @@ public class SearchHistoryHelper { return instance; } + public void addGpxFileToHistory(String fileName) { + addNewItemToHistory(0, 0, new PointDescription(POINT_TYPE_GPX_FILE, fileName)); + } + public void addNewItemToHistory(double latitude, double longitude, PointDescription pointDescription) { addNewItemToHistory(new HistoryEntry(latitude, longitude, pointDescription)); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 9badea394e..a9ddd6bcc3 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -90,6 +90,7 @@ import net.osmand.plus.poi.RearrangePoiFiltersFragment; import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI; import net.osmand.plus.search.listitems.QuickSearchButtonListItem; +import net.osmand.plus.search.listitems.QuickSearchGpxTrackListItem; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchMoreListItem; @@ -117,6 +118,7 @@ import java.util.List; import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_LOCATION_KEY; import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_QUERY_KEY; +import static net.osmand.search.core.ObjectType.GPX_TRACK; import static net.osmand.search.core.ObjectType.POI_TYPE; import static net.osmand.search.core.ObjectType.SEARCH_STARTED; import static net.osmand.search.core.SearchCoreFactory.SEARCH_AMENITY_TYPE_PRIORITY; @@ -1232,7 +1234,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (res != null) { List rows = new ArrayList<>(); for (SearchResult sr : res.getCurrentSearchResults()) { - rows.add(new QuickSearchListItem(app, sr)); + addListItem(rows, sr); } rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark, app.getString(R.string.search_online_address), new OnClickListener() { @@ -1499,7 +1501,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC int limit = 15; for (SearchResult sr : res.getCurrentSearchResults()) { if (limit > 0) { - rows.add(new QuickSearchListItem(app, sr)); + addListItem(rows, sr); } limit--; } @@ -1539,7 +1541,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List rows = new ArrayList<>(); if (res != null) { for (SearchResult sr : res.getCurrentSearchResults()) { - rows.add(new QuickSearchListItem(app, sr)); + addListItem(rows, sr); } } historySearchFragment.updateListAdapter(rows, false); @@ -1550,6 +1552,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } } + private void addListItem(List rows, SearchResult sr) { + if (sr.objectType == GPX_TRACK) { + rows.add(new QuickSearchGpxTrackListItem(app, sr)); + } else { + rows.add(new QuickSearchListItem(app, sr)); + } + } + private void restoreSearch() { if (addressSearch) { startAddressSearch(); @@ -2051,7 +2061,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List rows = new ArrayList<>(); if (res != null && res.getCurrentSearchResults().size() > 0) { for (final SearchResult sr : res.getCurrentSearchResults()) { - rows.add(new QuickSearchListItem(app, sr)); + addListItem(rows, sr); } updateSendEmptySearchBottomBar(false); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 1213f550c1..2fd06c4f6e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -23,6 +23,8 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.poi.NominatimPoiFilter; @@ -457,6 +459,14 @@ public class QuickSearchHelper implements ResourceListener { sr.objectType = ObjectType.POI_TYPE; publish = true; } + } else if (pd.isGpxFile()) { + GPXInfo gpxInfo = GpxUiHelper.getGpxInfoByFileName(app, pd.getName()); + if (gpxInfo != null) { + sr.localeName = gpxInfo.getFileName(); + sr.object = gpxInfo; + sr.objectType = ObjectType.GPX_TRACK; + publish = true; + } } else { sr.localeName = pd.getName(); sr.object = point; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index e7016a34ae..f1332a18e5 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -30,6 +30,8 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; +import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.search.listitems.QuickSearchBannerListItem; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; @@ -225,6 +227,8 @@ public class QuickSearchListAdapter extends ArrayAdapter { return bindTopShadowItem(convertView); } else if (type == QuickSearchListItemType.BOTTOM_SHADOW) { return bindBottomShadowItem(convertView); + } else if (type == QuickSearchListItemType.GPX_TRACK) { + view = bindGpxTrackItem(position, convertView, listItem); } else { view = bindSearchResultItem(position, convertView, listItem); } @@ -395,6 +399,17 @@ public class QuickSearchListAdapter extends ArrayAdapter { return getLinearLayout(convertView, R.layout.list_shadow_footer); } + private LinearLayout bindGpxTrackItem(int position, + @Nullable View convertView, + @NonNull QuickSearchListItem listItem) { + LinearLayout view = getLinearLayout(convertView, R.layout.search_gpx_list_item); + SearchResult sr = listItem.getSearchResult(); + GPXInfo gpxInfo = (GPXInfo) sr.object; + setupCheckBox(position, view, listItem); + GpxUiHelper.updateGpxInfoView(app, view, sr.localeName, listItem.getIcon(), gpxInfo); + return view; + } + private LinearLayout bindSearchResultItem(int position, @Nullable View convertView, @NonNull QuickSearchListItem listItem) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index f667595650..b0522989b9 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -11,6 +11,7 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import net.osmand.GPXUtilities; +import net.osmand.IndexConstants; import net.osmand.data.Amenity; import net.osmand.data.City; import net.osmand.data.FavouritePoint; @@ -23,6 +24,8 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.OsmAndListFragment; +import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; +import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; import net.osmand.plus.search.listitems.QuickSearchBottomShadowListItem; @@ -30,10 +33,12 @@ import net.osmand.plus.search.listitems.QuickSearchButtonListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItemType; import net.osmand.plus.search.listitems.QuickSearchTopShadowListItem; +import net.osmand.plus.track.TrackMenuFragment; import net.osmand.search.core.ObjectType; import net.osmand.search.core.SearchResult; import net.osmand.util.Algorithms; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -104,6 +109,11 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { } dialogFragment.completeQueryWithObject(sr); } + } else if (item.getType() == QuickSearchListItemType.GPX_TRACK) { + SearchResult sr = item.getSearchResult(); + if (sr.objectType == ObjectType.GPX_TRACK) { + showTrackMenuFragment((GPXInfo) sr.object); + } } } } @@ -292,6 +302,17 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { } } + private void showTrackMenuFragment(GPXInfo gpxInfo) { + OsmandApplication app = getMyApplication(); + MapActivity mapActivity = getMapActivity(); + String fileName = gpxInfo.getFileName(); + SearchHistoryHelper.getInstance(app).addGpxFileToHistory(fileName); + File file = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), fileName); + String path = file.getAbsolutePath(); + TrackMenuFragment.showInstance(mapActivity, path, false, null, null); + dialogFragment.dismiss(); + } + public MapActivity getMapActivity() { return (MapActivity) getActivity(); } diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchGpxTrackListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchGpxTrackListItem.java new file mode 100644 index 0000000000..35eb6c2a69 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchGpxTrackListItem.java @@ -0,0 +1,16 @@ +package net.osmand.plus.search.listitems; + +import net.osmand.plus.OsmandApplication; +import net.osmand.search.core.SearchResult; + +public class QuickSearchGpxTrackListItem extends QuickSearchListItem { + + public QuickSearchGpxTrackListItem(OsmandApplication app, SearchResult searchResult) { + super(app, searchResult); + } + + @Override + public QuickSearchListItemType getType() { + return QuickSearchListItemType.GPX_TRACK; + } +} diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java index 204c31de88..d1ffab835c 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java @@ -382,6 +382,8 @@ public class QuickSearchListItem { case WPT: WptPt wpt = (WptPt) searchResult.object; return PointImageDrawable.getFromWpt(app, wpt.getColor(), false, wpt); + case GPX_TRACK: + return getIcon(app, R.drawable.ic_action_polygom_dark); case UNKNOWN_NAME_FILTER: break; } diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java index 3c6dcf4527..db0ebf5f9a 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java @@ -2,6 +2,7 @@ package net.osmand.plus.search.listitems; public enum QuickSearchListItemType { SEARCH_RESULT, + GPX_TRACK, HEADER, BUTTON, SEARCH_MORE,