From d942a4f683cb6fe5d90a8d5b167d4be5d64d0dd9 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Tue, 2 Mar 2021 18:06:25 +0200 Subject: [PATCH] Make GPX track search result like other search results --- .../net/osmand/search/core/ObjectType.java | 2 +- .../search/SearchHistoryFragment.java | 6 ++- .../search/QuickSearchDialogFragment.java | 20 +++------- .../osmand/plus/search/QuickSearchHelper.java | 6 +-- .../plus/search/QuickSearchListAdapter.java | 37 +++++++++++++------ .../plus/search/QuickSearchListFragment.java | 9 ++--- .../QuickSearchGpxTrackListItem.java | 16 -------- .../search/listitems/QuickSearchListItem.java | 2 - .../listitems/QuickSearchListItemType.java | 1 - 9 files changed, 41 insertions(+), 58 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchGpxTrackListItem.java 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 df81a9ce18..c14d5cff07 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), GPX_TRACK(false), + FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true), // ONLINE SEARCH ONLINE_SEARCH(true), diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java index 536ef96541..234f9ec1af 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java @@ -303,9 +303,11 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA iconId = R.drawable.ic_type_audio; } else if (pd.isVideoNote()) { iconId = R.drawable.ic_type_video; - }else if (pd.isPhotoNote()) { + } else if (pd.isPhotoNote()) { iconId = R.drawable.ic_type_img; - } else { + } else if (pd.isGpxFile()) { + iconId = R.drawable.ic_action_polygom_dark; + } else { iconId = R.drawable.ic_action_street_name; } return iconId; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index c53d0c9b4c..463db3a6f7 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -90,7 +90,6 @@ 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; @@ -118,7 +117,6 @@ 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; @@ -516,7 +514,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List selectedItems = historySearchFragment.getListAdapter().getSelectedItems(); for (QuickSearchListItem searchListItem : selectedItems) { SearchResult sr = searchListItem.getSearchResult(); - Object object = sr.objectType == GPX_TRACK ? sr.relatedObject : sr.object; + Object object = sr.object; if (object instanceof HistoryEntry) { historyEntries.add((HistoryEntry) object); } @@ -1235,7 +1233,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (res != null) { List rows = new ArrayList<>(); for (SearchResult sr : res.getCurrentSearchResults()) { - addListItem(rows, sr); + rows.add(new QuickSearchListItem(app, sr)); } rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark, app.getString(R.string.search_online_address), new OnClickListener() { @@ -1502,7 +1500,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC int limit = 15; for (SearchResult sr : res.getCurrentSearchResults()) { if (limit > 0) { - addListItem(rows, sr); + rows.add(new QuickSearchListItem(app, sr)); } limit--; } @@ -1542,7 +1540,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List rows = new ArrayList<>(); if (res != null) { for (SearchResult sr : res.getCurrentSearchResults()) { - addListItem(rows, sr); + rows.add(new QuickSearchListItem(app, sr)); } } historySearchFragment.updateListAdapter(rows, false); @@ -1553,14 +1551,6 @@ 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(); @@ -2062,7 +2052,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()) { - addListItem(rows, sr); + rows.add(new QuickSearchListItem(app, sr)); } updateSendEmptySearchBottomBar(false); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 060fc01338..7a47446fa6 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -463,9 +463,9 @@ public class QuickSearchHelper implements ResourceListener { GPXInfo gpxInfo = GpxUiHelper.getGpxInfoByFileName(app, pd.getName()); if (gpxInfo != null) { sr.localeName = gpxInfo.getFileName(); - sr.object = gpxInfo; - sr.objectType = ObjectType.GPX_TRACK; - sr.relatedObject = point; + sr.object = point; + sr.objectType = ObjectType.RECENT_OBJ; + sr.relatedObject = gpxInfo; publish = true; } } else { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index f7c028f186..64593b5492 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -227,8 +227,6 @@ 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); } @@ -399,20 +397,31 @@ public class QuickSearchListAdapter extends ArrayAdapter { return getLinearLayout(convertView, R.layout.list_shadow_footer); } - private LinearLayout bindGpxTrackItem(int position, - @Nullable View convertView, - @NonNull QuickSearchListItem listItem) { + private LinearLayout bindSearchResultItem(int position, + @Nullable View convertView, + @NonNull QuickSearchListItem listItem) { + SearchResult sr = listItem.getSearchResult(); + if (sr != null && sr.relatedObject instanceof GPXInfo) { + return bindGpxTrack(position, convertView, listItem, (GPXInfo) sr.relatedObject); + } else { + return bindSearchResult(position, convertView, listItem); + } + } + + private LinearLayout bindGpxTrack(int position, + @Nullable View convertView, + @NonNull QuickSearchListItem listItem, + @NonNull GPXInfo gpxInfo) { 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) { + private LinearLayout bindSearchResult(int position, + @Nullable View convertView, + @NonNull QuickSearchListItem listItem) { LinearLayout view = getLinearLayout(convertView, R.layout.search_list_item); setupCheckBox(position, view, listItem); @@ -502,12 +511,17 @@ public class QuickSearchListAdapter extends ArrayAdapter { } private LinearLayout getLinearLayout(@Nullable View convertView, int layoutId) { - if (convertView == null) { + if (convertView == null || isLayoutIdChanged(convertView, layoutId)) { convertView = inflater.inflate(layoutId, null); + convertView.setTag(layoutId); } return (LinearLayout) convertView; } + private boolean isLayoutIdChanged(@NonNull View view, int layoutId) { + return !Algorithms.objectEquals(view.getTag(), layoutId); + } + private void setupCheckBox(final int position, @NonNull View rootView, @NonNull QuickSearchListItem listItem) { @@ -579,8 +593,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { selectedItems.clear(); for (int i = 0; i < getCount(); i++) { QuickSearchListItemType t = getItem(i).getType(); - if (t == QuickSearchListItemType.SEARCH_RESULT - || t == QuickSearchListItemType.GPX_TRACK) { + if (t == QuickSearchListItemType.SEARCH_RESULT) { selectedItems.add(getItem(i)); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index e371a334d1..c9635e7dac 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -109,11 +109,6 @@ 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); - } } } } @@ -175,7 +170,9 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { public void showResult(SearchResult searchResult) { showResult = false; - if (searchResult.location != null) { + if (searchResult.relatedObject instanceof GPXInfo) { + showTrackMenuFragment((GPXInfo) searchResult.relatedObject); + } else if (searchResult.location != null) { OsmandApplication app = getMyApplication(); String lang = searchResult.requiredSearchPhrase.getSettings().getLang(); boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate(); diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchGpxTrackListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchGpxTrackListItem.java deleted file mode 100644 index 35eb6c2a69..0000000000 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchGpxTrackListItem.java +++ /dev/null @@ -1,16 +0,0 @@ -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 d1ffab835c..204c31de88 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java @@ -382,8 +382,6 @@ 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 db0ebf5f9a..3c6dcf4527 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java @@ -2,7 +2,6 @@ package net.osmand.plus.search.listitems; public enum QuickSearchListItemType { SEARCH_RESULT, - GPX_TRACK, HEADER, BUTTON, SEARCH_MORE,