Make GPX track search result like other search results

This commit is contained in:
nazar-kutz 2021-03-02 18:06:25 +02:00
parent 8ceab0c5c3
commit d942a4f683
9 changed files with 41 additions and 58 deletions

View file

@ -8,7 +8,7 @@ public enum ObjectType {
// LOCATION // LOCATION
LOCATION(true), PARTIAL_LOCATION(false), LOCATION(true), PARTIAL_LOCATION(false),
// UI OBJECTS // 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
ONLINE_SEARCH(true), ONLINE_SEARCH(true),

View file

@ -303,9 +303,11 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
iconId = R.drawable.ic_type_audio; iconId = R.drawable.ic_type_audio;
} else if (pd.isVideoNote()) { } else if (pd.isVideoNote()) {
iconId = R.drawable.ic_type_video; iconId = R.drawable.ic_type_video;
}else if (pd.isPhotoNote()) { } else if (pd.isPhotoNote()) {
iconId = R.drawable.ic_type_img; 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; iconId = R.drawable.ic_action_street_name;
} }
return iconId; return iconId;

View file

@ -90,7 +90,6 @@ import net.osmand.plus.poi.RearrangePoiFiltersFragment;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI; import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI;
import net.osmand.plus.search.listitems.QuickSearchButtonListItem; 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.QuickSearchHeaderListItem;
import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItem;
import net.osmand.plus.search.listitems.QuickSearchMoreListItem; 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_LOCATION_KEY;
import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_QUERY_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.POI_TYPE;
import static net.osmand.search.core.ObjectType.SEARCH_STARTED; import static net.osmand.search.core.ObjectType.SEARCH_STARTED;
import static net.osmand.search.core.SearchCoreFactory.SEARCH_AMENITY_TYPE_PRIORITY; import static net.osmand.search.core.SearchCoreFactory.SEARCH_AMENITY_TYPE_PRIORITY;
@ -516,7 +514,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
List<QuickSearchListItem> selectedItems = historySearchFragment.getListAdapter().getSelectedItems(); List<QuickSearchListItem> selectedItems = historySearchFragment.getListAdapter().getSelectedItems();
for (QuickSearchListItem searchListItem : selectedItems) { for (QuickSearchListItem searchListItem : selectedItems) {
SearchResult sr = searchListItem.getSearchResult(); SearchResult sr = searchListItem.getSearchResult();
Object object = sr.objectType == GPX_TRACK ? sr.relatedObject : sr.object; Object object = sr.object;
if (object instanceof HistoryEntry) { if (object instanceof HistoryEntry) {
historyEntries.add((HistoryEntry) object); historyEntries.add((HistoryEntry) object);
} }
@ -1235,7 +1233,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (res != null) { if (res != null) {
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
for (SearchResult sr : res.getCurrentSearchResults()) { 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, rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark,
app.getString(R.string.search_online_address), new OnClickListener() { app.getString(R.string.search_online_address), new OnClickListener() {
@ -1502,7 +1500,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
int limit = 15; int limit = 15;
for (SearchResult sr : res.getCurrentSearchResults()) { for (SearchResult sr : res.getCurrentSearchResults()) {
if (limit > 0) { if (limit > 0) {
addListItem(rows, sr); rows.add(new QuickSearchListItem(app, sr));
} }
limit--; limit--;
} }
@ -1542,7 +1540,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
if (res != null) { if (res != null) {
for (SearchResult sr : res.getCurrentSearchResults()) { for (SearchResult sr : res.getCurrentSearchResults()) {
addListItem(rows, sr); rows.add(new QuickSearchListItem(app, sr));
} }
} }
historySearchFragment.updateListAdapter(rows, false); historySearchFragment.updateListAdapter(rows, false);
@ -1553,14 +1551,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
} }
private void addListItem(List<QuickSearchListItem> rows, SearchResult sr) {
if (sr.objectType == GPX_TRACK) {
rows.add(new QuickSearchGpxTrackListItem(app, sr));
} else {
rows.add(new QuickSearchListItem(app, sr));
}
}
private void restoreSearch() { private void restoreSearch() {
if (addressSearch) { if (addressSearch) {
startAddressSearch(); startAddressSearch();
@ -2062,7 +2052,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
if (res != null && res.getCurrentSearchResults().size() > 0) { if (res != null && res.getCurrentSearchResults().size() > 0) {
for (final SearchResult sr : res.getCurrentSearchResults()) { for (final SearchResult sr : res.getCurrentSearchResults()) {
addListItem(rows, sr); rows.add(new QuickSearchListItem(app, sr));
} }
updateSendEmptySearchBottomBar(false); updateSendEmptySearchBottomBar(false);
} }

View file

@ -463,9 +463,9 @@ public class QuickSearchHelper implements ResourceListener {
GPXInfo gpxInfo = GpxUiHelper.getGpxInfoByFileName(app, pd.getName()); GPXInfo gpxInfo = GpxUiHelper.getGpxInfoByFileName(app, pd.getName());
if (gpxInfo != null) { if (gpxInfo != null) {
sr.localeName = gpxInfo.getFileName(); sr.localeName = gpxInfo.getFileName();
sr.object = gpxInfo; sr.object = point;
sr.objectType = ObjectType.GPX_TRACK; sr.objectType = ObjectType.RECENT_OBJ;
sr.relatedObject = point; sr.relatedObject = gpxInfo;
publish = true; publish = true;
} }
} else { } else {

View file

@ -227,8 +227,6 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
return bindTopShadowItem(convertView); return bindTopShadowItem(convertView);
} else if (type == QuickSearchListItemType.BOTTOM_SHADOW) { } else if (type == QuickSearchListItemType.BOTTOM_SHADOW) {
return bindBottomShadowItem(convertView); return bindBottomShadowItem(convertView);
} else if (type == QuickSearchListItemType.GPX_TRACK) {
view = bindGpxTrackItem(position, convertView, listItem);
} else { } else {
view = bindSearchResultItem(position, convertView, listItem); view = bindSearchResultItem(position, convertView, listItem);
} }
@ -399,20 +397,31 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
return getLinearLayout(convertView, R.layout.list_shadow_footer); return getLinearLayout(convertView, R.layout.list_shadow_footer);
} }
private LinearLayout bindGpxTrackItem(int position, private LinearLayout bindSearchResultItem(int position,
@Nullable View convertView, @Nullable View convertView,
@NonNull QuickSearchListItem listItem) { @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); LinearLayout view = getLinearLayout(convertView, R.layout.search_gpx_list_item);
SearchResult sr = listItem.getSearchResult(); SearchResult sr = listItem.getSearchResult();
GPXInfo gpxInfo = (GPXInfo) sr.object;
setupCheckBox(position, view, listItem); setupCheckBox(position, view, listItem);
GpxUiHelper.updateGpxInfoView(app, view, sr.localeName, listItem.getIcon(), gpxInfo); GpxUiHelper.updateGpxInfoView(app, view, sr.localeName, listItem.getIcon(), gpxInfo);
return view; return view;
} }
private LinearLayout bindSearchResultItem(int position, private LinearLayout bindSearchResult(int position,
@Nullable View convertView, @Nullable View convertView,
@NonNull QuickSearchListItem listItem) { @NonNull QuickSearchListItem listItem) {
LinearLayout view = getLinearLayout(convertView, R.layout.search_list_item); LinearLayout view = getLinearLayout(convertView, R.layout.search_list_item);
setupCheckBox(position, view, listItem); setupCheckBox(position, view, listItem);
@ -502,12 +511,17 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
} }
private LinearLayout getLinearLayout(@Nullable View convertView, int layoutId) { private LinearLayout getLinearLayout(@Nullable View convertView, int layoutId) {
if (convertView == null) { if (convertView == null || isLayoutIdChanged(convertView, layoutId)) {
convertView = inflater.inflate(layoutId, null); convertView = inflater.inflate(layoutId, null);
convertView.setTag(layoutId);
} }
return (LinearLayout) convertView; return (LinearLayout) convertView;
} }
private boolean isLayoutIdChanged(@NonNull View view, int layoutId) {
return !Algorithms.objectEquals(view.getTag(), layoutId);
}
private void setupCheckBox(final int position, private void setupCheckBox(final int position,
@NonNull View rootView, @NonNull View rootView,
@NonNull QuickSearchListItem listItem) { @NonNull QuickSearchListItem listItem) {
@ -579,8 +593,7 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
selectedItems.clear(); selectedItems.clear();
for (int i = 0; i < getCount(); i++) { for (int i = 0; i < getCount(); i++) {
QuickSearchListItemType t = getItem(i).getType(); QuickSearchListItemType t = getItem(i).getType();
if (t == QuickSearchListItemType.SEARCH_RESULT if (t == QuickSearchListItemType.SEARCH_RESULT) {
|| t == QuickSearchListItemType.GPX_TRACK) {
selectedItems.add(getItem(i)); selectedItems.add(getItem(i));
} }
} }

View file

@ -109,11 +109,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
} }
dialogFragment.completeQueryWithObject(sr); 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) { public void showResult(SearchResult searchResult) {
showResult = false; showResult = false;
if (searchResult.location != null) { if (searchResult.relatedObject instanceof GPXInfo) {
showTrackMenuFragment((GPXInfo) searchResult.relatedObject);
} else if (searchResult.location != null) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
String lang = searchResult.requiredSearchPhrase.getSettings().getLang(); String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate(); boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();

View file

@ -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;
}
}

View file

@ -382,8 +382,6 @@ public class QuickSearchListItem {
case WPT: case WPT:
WptPt wpt = (WptPt) searchResult.object; WptPt wpt = (WptPt) searchResult.object;
return PointImageDrawable.getFromWpt(app, wpt.getColor(), false, wpt); return PointImageDrawable.getFromWpt(app, wpt.getColor(), false, wpt);
case GPX_TRACK:
return getIcon(app, R.drawable.ic_action_polygom_dark);
case UNKNOWN_NAME_FILTER: case UNKNOWN_NAME_FILTER:
break; break;
} }

View file

@ -2,7 +2,6 @@ package net.osmand.plus.search.listitems;
public enum QuickSearchListItemType { public enum QuickSearchListItemType {
SEARCH_RESULT, SEARCH_RESULT,
GPX_TRACK,
HEADER, HEADER,
BUTTON, BUTTON,
SEARCH_MORE, SEARCH_MORE,