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 10a8c2ae84..f34fc008f5 100644
--- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
+++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
@@ -27,6 +27,8 @@ 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.GpxUiHelper.GPXInfo;
+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 +583,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 +686,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 +732,13 @@ 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, "");
+ GPXInfo gpxInfo = GpxUiHelper.getGpxInfoByFileName(app, fileName);
+ SearchHistoryHelper.getInstance(app).addNewItemToHistory(gpxInfo);
+ }
return sf;
}
@@ -749,18 +764,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/activities/search/SearchHistoryFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java
index 536ef96541..9cb508141e 100644
--- a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java
@@ -303,9 +303,9 @@ 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 {
iconId = R.drawable.ic_action_street_name;
}
return iconId;
diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java
index c2f3d831b8..1d49394ea0 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,53 @@ 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(final @NonNull OsmandApplication app,
+ final @NonNull View v,
+ final @NonNull String itemTitle,
+ final @Nullable Drawable iconDrawable,
+ final @NonNull GPXInfo info) {
+ GpxDataItem item = getDataItem(app, info, new GpxDataItemCallback() {
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ @Override
+ public void onGpxDataItemReady(GpxDataItem item) {
+ updateGpxInfoView(app, v, itemTitle, iconDrawable, info, item);
+ }
+ });
+ if (item != null) {
+ updateGpxInfoView(app, v, itemTitle, iconDrawable, info, item);
+ }
+ }
+
+ private static void updateGpxInfoView(@NonNull OsmandApplication app,
+ @NonNull View v,
+ @NonNull String itemTitle,
+ @Nullable Drawable iconDrawable,
+ @NonNull GPXInfo info,
+ @NonNull GpxDataItem dataItem) {
+ 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 +848,23 @@ 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(@NonNull OsmandApplication app,
+ @NonNull GPXInfo info,
+ @Nullable GpxDataItemCallback callback) {
+ File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
+ String fileName = info.getFileName();
+ File file = new File(dir, fileName);
+ return app.getGpxDbHelper().getItem(file, callback);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@@ -884,6 +937,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.getFileName(), 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..b71b83316f 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java
@@ -6,6 +6,7 @@ import net.osmand.osm.AbstractPoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
+import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.util.Algorithms;
@@ -16,6 +17,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;
@@ -53,6 +56,10 @@ public class SearchHistoryHelper {
context.getPoiFilters().markHistory(filter.getFilterId(), true);
}
+ public void addNewItemToHistory(GPXInfo gpxInfo) {
+ addNewItemToHistory(new HistoryEntry(0, 0, createPointDescription(gpxInfo)));
+ }
+
public List getHistoryEntries(boolean onlyPoints) {
if (loadedEntries == null) {
checkLoadedEntries();
@@ -75,6 +82,10 @@ public class SearchHistoryHelper {
return new PointDescription(PointDescription.POINT_TYPE_CUSTOM_POI_FILTER, filter.getFilterId());
}
+ private PointDescription createPointDescription(GPXInfo gpxInfo) {
+ return new PointDescription(PointDescription.POINT_TYPE_GPX_FILE, gpxInfo.getFileName());
+ }
+
public void remove(Object item) {
PointDescription pd = null;
if (item instanceof HistoryEntry) {
@@ -83,6 +94,8 @@ public class SearchHistoryHelper {
pd = createPointDescription((AbstractPoiType) item);
} else if (item instanceof PoiUIFilter) {
pd = createPointDescription((PoiUIFilter) item);
+ } else if (item instanceof GPXInfo) {
+ pd = createPointDescription((GPXInfo) item);
}
if (pd != null) {
remove(pd);
diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java
index 9badea394e..22b75072ec 100644
--- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java
@@ -513,7 +513,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
List historyEntries = new ArrayList();
List selectedItems = historySearchFragment.getListAdapter().getSelectedItems();
for (QuickSearchListItem searchListItem : selectedItems) {
- Object object = searchListItem.getSearchResult().object;
+ Object object = searchListItem.getSearchResult().object;;
if (object instanceof HistoryEntry) {
historyEntries.add((HistoryEntry) object);
}
diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java
index 1213f550c1..2cf4226e12 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,15 @@ 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 = point;
+ sr.objectType = ObjectType.GPX_TRACK;
+ sr.relatedObject = gpxInfo;
+ 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 9251e555b0..c9a3d1d5e9 100644
--- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java
@@ -10,12 +10,10 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
@@ -32,8 +30,9 @@ 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.search.listitems.QuickSearchFreeBannerListItem;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.search.listitems.QuickSearchHeaderListItem;
import net.osmand.plus.search.listitems.QuickSearchListItem;
@@ -41,7 +40,9 @@ import net.osmand.plus.search.listitems.QuickSearchListItemType;
import net.osmand.plus.search.listitems.QuickSearchMoreListItem;
import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem;
import net.osmand.search.SearchUICore;
+import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchPhrase;
+import net.osmand.search.core.SearchResult;
import net.osmand.search.core.SearchWord;
import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser;
@@ -209,143 +210,326 @@ public class QuickSearchListAdapter extends ArrayAdapter {
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
final QuickSearchListItem listItem = getItem(position);
QuickSearchListItemType type = listItem.getType();
+
LinearLayout view;
if (type == QuickSearchListItemType.BANNER) {
- final QuickSearchBannerListItem banner = (QuickSearchBannerListItem) listItem;
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.search_banner_list_item, null);
- } else {
- view = (LinearLayout) convertView;
- }
-
- ((TextView) view.findViewById(R.id.empty_search_description)).setText(R.string.nothing_found_descr);
-
- SearchUICore searchUICore = app.getSearchUICore().getCore();
- SearchPhrase searchPhrase = searchUICore.getPhrase();
-
- String textTitle;
- int minimalSearchRadius = searchUICore.getMinimalSearchRadius(searchPhrase);
- if (searchUICore.isSearchMoreAvailable(searchPhrase) && minimalSearchRadius != Integer.MAX_VALUE) {
- double rd = OsmAndFormatter.calculateRoundedDist(minimalSearchRadius, app);
- textTitle = app.getString(R.string.nothing_found_in_radius) + " "
- + OsmAndFormatter.getFormattedDistance((float) rd, app, false);
- } else {
- textTitle = app.getString(R.string.search_nothing_found);
- }
- ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
-
- ViewGroup buttonContainer = view.findViewById(R.id.buttons_container);
- if (buttonContainer != null) {
- buttonContainer.removeAllViews();
- for (ButtonItem button : banner.getButtonItems()) {
- View v = inflater.inflate(R.layout.search_banner_button_list_item, null);
- TextView title = v.findViewById(R.id.title);
- title.setText(button.getTitle());
- ImageView icon = v.findViewById(R.id.icon);
- if (button.getIconId() != INVALID_ID) {
- icon.setImageResource(button.getIconId());
- icon.setVisibility(View.VISIBLE);
- } else {
- icon.setVisibility(View.GONE);
- }
- v.setOnClickListener(button.getListener());
- buttonContainer.addView(v);
- }
- }
+ view = bindBannerItem(convertView, listItem);
} else if (type == QuickSearchListItemType.FREE_VERSION_BANNER) {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(
- R.layout.read_wikipedia_ofline_banner, null);
- } else {
- view = (LinearLayout) convertView;
- }
-
- View btnGet = view.findViewById(R.id.btn_get);
- if (btnGet != null) {
- btnGet.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ChoosePlanDialogFragment.showWikipediaInstance(
- activity.getSupportFragmentManager());
- }
- });
- }
+ view = bindFreeVersionBannerItem(convertView);
} else if (type == QuickSearchListItemType.SEARCH_MORE) {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.search_more_list_item, null);
- } else {
- view = (LinearLayout) convertView;
- }
-
- if (listItem.getSpannableName() != null) {
- ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
- } else {
- ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
- }
-
- final QuickSearchMoreListItem searchMoreItem = (QuickSearchMoreListItem) listItem;
- int emptyDescId = searchMoreItem.isSearchMoreAvailable() ? R.string.nothing_found_descr : R.string.modify_the_search_query;
- ((TextView) view.findViewById(R.id.empty_search_description)).setText(emptyDescId);
-
- boolean emptySearchVisible = searchMoreItem.isEmptySearch() && !searchMoreItem.isInterruptedSearch();
- boolean moreDividerVisible = emptySearchVisible && searchMoreItem.isSearchMoreAvailable();
- view.findViewById(R.id.empty_search).setVisibility(emptySearchVisible ? View.VISIBLE : View.GONE);
- view.findViewById(R.id.more_divider).setVisibility(moreDividerVisible ? View.VISIBLE : View.GONE);
- SearchUICore searchUICore = app.getSearchUICore().getCore();
- SearchPhrase searchPhrase = searchUICore.getPhrase();
-
- String textTitle;
- int minimalSearchRadius = searchUICore.getMinimalSearchRadius(searchPhrase);
- if (searchUICore.isSearchMoreAvailable(searchPhrase) && minimalSearchRadius != Integer.MAX_VALUE) {
- double rd = OsmAndFormatter.calculateRoundedDist(minimalSearchRadius, app);
- textTitle = app.getString(R.string.nothing_found_in_radius) + " "
- + OsmAndFormatter.getFormattedDistance((float) rd, app, false);
- } else {
- textTitle = app.getString(R.string.search_nothing_found);
- }
- ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
- View primaryButton = view.findViewById(R.id.primary_button);
-
- ((TextView) view.findViewById(R.id.title)).setText(getIncreaseSearchButtonTitle(app, searchPhrase));
-
- primaryButton.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE);
- primaryButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- ((QuickSearchMoreListItem) listItem).onPrimaryButtonClick();
- }
- });
-
- View secondaryButton = view.findViewById(R.id.secondary_button);
- secondaryButton.setVisibility(searchMoreItem.isSecondaryButtonVisible() ?
- View.VISIBLE : View.GONE);
- secondaryButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- searchMoreItem.onSecondaryButtonClick();
- }
- });
+ view = bindSearchMoreItem(convertView, listItem);
} else if (type == QuickSearchListItemType.BUTTON) {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.search_custom_list_item, null);
- } else {
- view = (LinearLayout) convertView;
- }
- ((ImageView) view.findViewById(R.id.imageView)).setImageDrawable(listItem.getIcon());
- if (listItem.getSpannableName() != null) {
- ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
- } else {
- ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
- }
+ view = bindButtonItem(convertView, listItem);
} else if (type == QuickSearchListItemType.SELECT_ALL) {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.select_all_list_item, null);
- } else {
- view = (LinearLayout) convertView;
+ view = bindSelectAllItem(position, convertView);
+ } else if (type == QuickSearchListItemType.HEADER) {
+ view = bindHeaderItem(convertView, listItem);
+ } else if (type == QuickSearchListItemType.TOP_SHADOW) {
+ return bindTopShadowItem(convertView);
+ } else if (type == QuickSearchListItemType.BOTTOM_SHADOW) {
+ return bindBottomShadowItem(convertView);
+ } else {
+ view = bindSearchResultItem(position, convertView, listItem);
+ }
+
+ setupBackground(view);
+ setupDivider(position, view, listItem);
+ ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant);
+ return view;
+ }
+
+ private LinearLayout bindBannerItem(@Nullable View convertView,
+ @NonNull QuickSearchListItem listItem) {
+ QuickSearchBannerListItem banner = (QuickSearchBannerListItem) listItem;
+ LinearLayout view = getLinearLayout(convertView, R.layout.search_banner_list_item);
+ ((TextView) view.findViewById(R.id.empty_search_description)).setText(R.string.nothing_found_descr);
+
+ SearchUICore searchUICore = app.getSearchUICore().getCore();
+ SearchPhrase searchPhrase = searchUICore.getPhrase();
+
+ String textTitle;
+ int minimalSearchRadius = searchUICore.getMinimalSearchRadius(searchPhrase);
+ if (searchUICore.isSearchMoreAvailable(searchPhrase) && minimalSearchRadius != Integer.MAX_VALUE) {
+ double rd = OsmAndFormatter.calculateRoundedDist(minimalSearchRadius, app);
+ textTitle = app.getString(R.string.nothing_found_in_radius) + " "
+ + OsmAndFormatter.getFormattedDistance((float) rd, app, false);
+ } else {
+ textTitle = app.getString(R.string.search_nothing_found);
+ }
+ ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
+
+ ViewGroup buttonContainer = view.findViewById(R.id.buttons_container);
+ if (buttonContainer != null) {
+ buttonContainer.removeAllViews();
+ for (ButtonItem button : banner.getButtonItems()) {
+ View v = inflater.inflate(R.layout.search_banner_button_list_item, null);
+ TextView title = v.findViewById(R.id.title);
+ title.setText(button.getTitle());
+ ImageView icon = v.findViewById(R.id.icon);
+ if (button.getIconId() != INVALID_ID) {
+ icon.setImageResource(button.getIconId());
+ icon.setVisibility(View.VISIBLE);
+ } else {
+ icon.setVisibility(View.GONE);
+ }
+ v.setOnClickListener(button.getListener());
+ buttonContainer.addView(v);
}
- final CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
+ }
+ return view;
+ }
+
+ private LinearLayout bindFreeVersionBannerItem(@Nullable View convertView) {
+ LinearLayout view = getLinearLayout(convertView, R.layout.read_wikipedia_ofline_banner);
+ View btnGet = view.findViewById(R.id.btn_get);
+ if (btnGet != null) {
+ btnGet.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ChoosePlanDialogFragment.showWikipediaInstance(
+ activity.getSupportFragmentManager());
+ }
+ });
+ }
+ return view;
+ }
+
+ private LinearLayout bindSearchMoreItem(@Nullable View convertView,
+ @NonNull final QuickSearchListItem listItem) {
+ LinearLayout view = getLinearLayout(convertView, R.layout.search_more_list_item);
+
+ if (listItem.getSpannableName() != null) {
+ ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
+ } else {
+ ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
+ }
+
+ final QuickSearchMoreListItem searchMoreItem = (QuickSearchMoreListItem) listItem;
+ int emptyDescId = searchMoreItem.isSearchMoreAvailable() ? R.string.nothing_found_descr : R.string.modify_the_search_query;
+ ((TextView) view.findViewById(R.id.empty_search_description)).setText(emptyDescId);
+
+ boolean emptySearchVisible = searchMoreItem.isEmptySearch() && !searchMoreItem.isInterruptedSearch();
+ boolean moreDividerVisible = emptySearchVisible && searchMoreItem.isSearchMoreAvailable();
+ view.findViewById(R.id.empty_search).setVisibility(emptySearchVisible ? View.VISIBLE : View.GONE);
+ view.findViewById(R.id.more_divider).setVisibility(moreDividerVisible ? View.VISIBLE : View.GONE);
+ SearchUICore searchUICore = app.getSearchUICore().getCore();
+ SearchPhrase searchPhrase = searchUICore.getPhrase();
+
+ String textTitle;
+ int minimalSearchRadius = searchUICore.getMinimalSearchRadius(searchPhrase);
+ if (searchUICore.isSearchMoreAvailable(searchPhrase) && minimalSearchRadius != Integer.MAX_VALUE) {
+ double rd = OsmAndFormatter.calculateRoundedDist(minimalSearchRadius, app);
+ textTitle = app.getString(R.string.nothing_found_in_radius) + " "
+ + OsmAndFormatter.getFormattedDistance((float) rd, app, false);
+ } else {
+ textTitle = app.getString(R.string.search_nothing_found);
+ }
+ ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
+ View primaryButton = view.findViewById(R.id.primary_button);
+
+ ((TextView) view.findViewById(R.id.title)).setText(getIncreaseSearchButtonTitle(app, searchPhrase));
+
+ primaryButton.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE);
+ primaryButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ ((QuickSearchMoreListItem) listItem).onPrimaryButtonClick();
+ }
+ });
+
+ View secondaryButton = view.findViewById(R.id.secondary_button);
+ secondaryButton.setVisibility(searchMoreItem.isSecondaryButtonVisible() ?
+ View.VISIBLE : View.GONE);
+ secondaryButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ searchMoreItem.onSecondaryButtonClick();
+ }
+ });
+ return view;
+ }
+
+ private LinearLayout bindButtonItem(@Nullable View convertView,
+ @NonNull QuickSearchListItem listItem) {
+ LinearLayout view = getLinearLayout(convertView, R.layout.search_custom_list_item);
+ ((ImageView) view.findViewById(R.id.imageView)).setImageDrawable(listItem.getIcon());
+ if (listItem.getSpannableName() != null) {
+ ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
+ } else {
+ ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
+ }
+ return view;
+ }
+
+ private LinearLayout bindSelectAllItem(final int position,
+ @Nullable View convertView) {
+ LinearLayout view = getLinearLayout(convertView, R.layout.select_all_list_item);
+ final CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
+ ch.setVisibility(View.VISIBLE);
+ ch.setChecked(selectAll);
+ ch.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ toggleCheckbox(position, ch);
+ }
+ });
+ return view;
+ }
+
+ private LinearLayout bindHeaderItem(@Nullable View convertView,
+ @NonNull QuickSearchListItem listItem) {
+ LinearLayout view = getLinearLayout(convertView, R.layout.search_header_list_item);
+ view.findViewById(R.id.top_divider)
+ .setVisibility(((QuickSearchHeaderListItem)listItem).isShowTopDivider() ? View.VISIBLE : View.GONE);
+ if (listItem.getSpannableName() != null) {
+ ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
+ } else {
+ ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
+ }
+ return view;
+ }
+
+ private LinearLayout bindTopShadowItem(@Nullable View convertView) {
+ return getLinearLayout(convertView, R.layout.list_shadow_header);
+ }
+
+ private LinearLayout bindBottomShadowItem(@Nullable View convertView) {
+ return getLinearLayout(convertView, R.layout.list_shadow_footer);
+ }
+
+ private LinearLayout bindSearchResultItem(int position,
+ @Nullable View convertView,
+ @NonNull QuickSearchListItem listItem) {
+ SearchResult sr = listItem.getSearchResult();
+ if (sr != null && sr.objectType == ObjectType.GPX_TRACK) {
+ 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();
+ setupCheckBox(position, view, listItem);
+ GpxUiHelper.updateGpxInfoView(app, view, sr.localeName, listItem.getIcon(), gpxInfo);
+ return view;
+ }
+
+ private LinearLayout bindSearchResult(int position,
+ @Nullable View convertView,
+ @NonNull QuickSearchListItem listItem) {
+ LinearLayout view = getLinearLayout(convertView, R.layout.search_list_item);
+ setupCheckBox(position, view, listItem);
+
+ ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
+ TextView title = (TextView) view.findViewById(R.id.title);
+ TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
+
+ imageView.setImageDrawable(listItem.getIcon());
+ String name = listItem.getName();
+ if (listItem.getSpannableName() != null) {
+ title.setText(listItem.getSpannableName());
+ } else {
+ title.setText(name);
+ }
+
+ String desc = listItem.getTypeName();
+ Object searchResultObject = listItem.getSearchResult().object;
+ if (searchResultObject instanceof AbstractPoiType) {
+ AbstractPoiType abstractPoiType = (AbstractPoiType) searchResultObject;
+ String synonyms[] = abstractPoiType.getSynonyms().split(";");
+ QuickSearchHelper searchHelper = app.getSearchUICore();
+ SearchUICore searchUICore = searchHelper.getCore();
+ String searchPhrase = searchUICore.getPhrase().getText(true);
+ SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase,
+ CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
+
+ if (!searchPhrase.isEmpty() && !nm.matches(abstractPoiType.getTranslation())) {
+ if (nm.matches(abstractPoiType.getEnTranslation())) {
+ desc = listItem.getTypeName() + " (" + abstractPoiType.getEnTranslation() + ")";
+ } else {
+ for (String syn : synonyms) {
+ if (nm.matches(syn)) {
+ desc = listItem.getTypeName() + " (" + syn + ")";
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ boolean hasDesc = false;
+ if (!Algorithms.isEmpty(desc) && !desc.equals(name)) {
+ subtitle.setText(desc);
+ subtitle.setVisibility(View.VISIBLE);
+ hasDesc = true;
+ } else {
+ subtitle.setVisibility(View.GONE);
+ }
+
+ Drawable typeIcon = listItem.getTypeIcon();
+ ImageView group = (ImageView) view.findViewById(R.id.type_name_icon);
+ if (typeIcon != null && hasDesc) {
+ group.setImageDrawable(typeIcon);
+ group.setVisibility(View.VISIBLE);
+ } else {
+ group.setVisibility(View.GONE);
+ }
+
+ LinearLayout timeLayout = (LinearLayout) view.findViewById(R.id.time_layout);
+ TextView timeText = (TextView) view.findViewById(R.id.time);
+ ImageView timeIcon = (ImageView) view.findViewById(R.id.time_icon);
+ if (listItem.getSearchResult().object instanceof Amenity
+ && ((Amenity) listItem.getSearchResult().object).getOpeningHours() != null) {
+ Amenity amenity = (Amenity) listItem.getSearchResult().object;
+ OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
+ if (rs != null && rs.getInfo() != null) {
+ int colorOpen = R.color.ctx_menu_amenity_opened_text_color;
+ int colorClosed = R.color.ctx_menu_amenity_closed_text_color;
+ SpannableString openHours = MenuController.getSpannableOpeningHours(
+ rs.getInfo(),
+ ContextCompat.getColor(app, colorOpen),
+ ContextCompat.getColor(app, colorClosed));
+ int colorId = rs.isOpenedForTime(Calendar.getInstance()) ? colorOpen : colorClosed;
+ timeLayout.setVisibility(View.VISIBLE);
+ timeIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_opening_hour_16, colorId));
+ timeText.setText(openHours);
+ } else {
+ timeLayout.setVisibility(View.GONE);
+ }
+ } else {
+ timeLayout.setVisibility(View.GONE);
+ }
+
+ updateCompassVisibility(view, listItem);
+
+ return view;
+ }
+
+ private LinearLayout getLinearLayout(@Nullable View convertView, int layoutId) {
+ 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) {
+ final CheckBox ch = (CheckBox) rootView.findViewById(R.id.toggle_item);
+ if (selectionMode) {
ch.setVisibility(View.VISIBLE);
- ch.setChecked(selectAll);
+ ch.setChecked(selectedItems.contains(listItem));
ch.setOnClickListener(new View.OnClickListener() {
@Override
@@ -353,139 +537,21 @@ public class QuickSearchListAdapter extends ArrayAdapter {
toggleCheckbox(position, ch);
}
});
- } else if (type == QuickSearchListItemType.HEADER) {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.search_header_list_item, null);
- } else {
- view = (LinearLayout) convertView;
- }
- view.findViewById(R.id.top_divider)
- .setVisibility(((QuickSearchHeaderListItem)listItem).isShowTopDivider() ? View.VISIBLE : View.GONE);
- if (listItem.getSpannableName() != null) {
- ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
- } else {
- ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
- }
- } else if (type == QuickSearchListItemType.TOP_SHADOW) {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.list_shadow_header, null);
- } else {
- view = (LinearLayout) convertView;
- }
- return view;
- } else if (type == QuickSearchListItemType.BOTTOM_SHADOW) {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.list_shadow_footer, null);
- } else {
- view = (LinearLayout) convertView;
- }
- return view;
} else {
- if (convertView == null) {
- view = (LinearLayout) inflater.inflate(R.layout.search_list_item, null);
- } else {
- view = (LinearLayout) convertView;
- }
-
- final CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
- if (selectionMode) {
- ch.setVisibility(View.VISIBLE);
- ch.setChecked(selectedItems.contains(listItem));
- ch.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- toggleCheckbox(position, ch);
- }
- });
- } else {
- ch.setVisibility(View.GONE);
- }
-
- ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
- TextView title = (TextView) view.findViewById(R.id.title);
- TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
-
- imageView.setImageDrawable(listItem.getIcon());
- String name = listItem.getName();
- if (listItem.getSpannableName() != null) {
- title.setText(listItem.getSpannableName());
- } else {
- title.setText(name);
- }
-
- String desc = listItem.getTypeName();
- Object searchResultObject = listItem.getSearchResult().object;
- if (searchResultObject instanceof AbstractPoiType) {
- AbstractPoiType abstractPoiType = (AbstractPoiType) searchResultObject;
- String synonyms[] = abstractPoiType.getSynonyms().split(";");
- QuickSearchHelper searchHelper = app.getSearchUICore();
- SearchUICore searchUICore = searchHelper.getCore();
- String searchPhrase = searchUICore.getPhrase().getText(true);
- SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase,
- CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
-
- if (!searchPhrase.isEmpty() && !nm.matches(abstractPoiType.getTranslation())) {
- if (nm.matches(abstractPoiType.getEnTranslation())) {
- desc = listItem.getTypeName() + " (" + abstractPoiType.getEnTranslation() + ")";
- } else {
- for (String syn : synonyms) {
- if (nm.matches(syn)) {
- desc = listItem.getTypeName() + " (" + syn + ")";
- break;
- }
- }
- }
- }
- }
-
- boolean hasDesc = false;
- if (!Algorithms.isEmpty(desc) && !desc.equals(name)) {
- subtitle.setText(desc);
- subtitle.setVisibility(View.VISIBLE);
- hasDesc = true;
- } else {
- subtitle.setVisibility(View.GONE);
- }
-
- Drawable typeIcon = listItem.getTypeIcon();
- ImageView group = (ImageView) view.findViewById(R.id.type_name_icon);
- if (typeIcon != null && hasDesc) {
- group.setImageDrawable(typeIcon);
- group.setVisibility(View.VISIBLE);
- } else {
- group.setVisibility(View.GONE);
- }
-
- LinearLayout timeLayout = (LinearLayout) view.findViewById(R.id.time_layout);
- TextView timeText = (TextView) view.findViewById(R.id.time);
- ImageView timeIcon = (ImageView) view.findViewById(R.id.time_icon);
- if (listItem.getSearchResult().object instanceof Amenity
- && ((Amenity) listItem.getSearchResult().object).getOpeningHours() != null) {
- Amenity amenity = (Amenity) listItem.getSearchResult().object;
- OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
- if (rs != null && rs.getInfo() != null) {
- int colorOpen = R.color.ctx_menu_amenity_opened_text_color;
- int colorClosed = R.color.ctx_menu_amenity_closed_text_color;
- SpannableString openHours = MenuController.getSpannableOpeningHours(
- rs.getInfo(),
- ContextCompat.getColor(app, colorOpen),
- ContextCompat.getColor(app, colorClosed));
- int colorId = rs.isOpenedForTime(Calendar.getInstance()) ? colorOpen : colorClosed;
- timeLayout.setVisibility(View.VISIBLE);
- timeIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_opening_hour_16, colorId));
- timeText.setText(openHours);
- } else {
- timeLayout.setVisibility(View.GONE);
- }
- } else {
- timeLayout.setVisibility(View.GONE);
- }
-
- updateCompassVisibility(view, listItem);
+ ch.setVisibility(View.GONE);
}
- view.setBackgroundColor(app.getResources().getColor(
- app.getSettings().isLightContent() ? R.color.list_background_color_light : R.color.list_background_color_dark));
+ }
+
+ private void setupBackground(View view) {
+ int bgColorResId = isNightMode() ?
+ R.color.list_background_color_dark :
+ R.color.list_background_color_light;
+ view.setBackgroundColor(app.getResources().getColor(bgColorResId));
+ }
+
+ private void setupDivider(final int position,
+ @NonNull View view,
+ @NonNull QuickSearchListItem listItem) {
View divider = view.findViewById(R.id.divider);
if (divider != null) {
if (position == getCount() - 1 || getItem(position + 1).getType() == QuickSearchListItemType.HEADER
@@ -494,7 +560,7 @@ public class QuickSearchListAdapter extends ArrayAdapter {
} else {
divider.setVisibility(View.VISIBLE);
if (getItem(position + 1).getType() == QuickSearchListItemType.SEARCH_MORE
- || type == QuickSearchListItemType.SELECT_ALL) {
+ || listItem.getType() == QuickSearchListItemType.SELECT_ALL) {
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp1);
p.setMargins(0, 0, 0 ,0);
divider.setLayoutParams(p);
@@ -505,8 +571,6 @@ public class QuickSearchListAdapter extends ArrayAdapter {
}
}
}
- ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant);
- return view;
}
public static String getIncreaseSearchButtonTitle(OsmandApplication app, SearchPhrase searchPhrase) {
@@ -576,4 +640,8 @@ public class QuickSearchListAdapter extends ArrayAdapter {
LatLon toloc = listItem.getSearchResult().location;
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, toloc);
}
+
+ private boolean isNightMode() {
+ return !app.getSettings().isLightContent();
+ }
}
diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java
index f667595650..410f011154 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;
@@ -95,7 +100,8 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|| sr.objectType == ObjectType.FAVORITE
|| sr.objectType == ObjectType.RECENT_OBJ
|| sr.objectType == ObjectType.WPT
- || sr.objectType == ObjectType.STREET_INTERSECTION) {
+ || sr.objectType == ObjectType.STREET_INTERSECTION
+ || sr.objectType == ObjectType.GPX_TRACK) {
showResult(sr);
} else {
@@ -165,7 +171,9 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
public void showResult(SearchResult searchResult) {
showResult = false;
- if (searchResult.location != null) {
+ if (searchResult.objectType == ObjectType.GPX_TRACK) {
+ showTrackMenuFragment((GPXInfo) searchResult.relatedObject);
+ } else if (searchResult.location != null) {
OsmandApplication app = getMyApplication();
String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
@@ -292,6 +300,16 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
}
}
+ private void showTrackMenuFragment(GPXInfo gpxInfo) {
+ OsmandApplication app = getMyApplication();
+ MapActivity mapActivity = getMapActivity();
+ SearchHistoryHelper.getInstance(app).addNewItemToHistory(gpxInfo);
+ File file = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), gpxInfo.getFileName());
+ String path = file.getAbsolutePath();
+ TrackMenuFragment.showInstance(mapActivity, path, false, null, QuickSearchDialogFragment.TAG);
+ dialogFragment.dismiss();
+ }
+
public MapActivity getMapActivity() {
return (MapActivity) getActivity();
}
diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java
index 204c31de88..56b0b7a572 100644
--- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java
+++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java
@@ -359,6 +359,8 @@ public class QuickSearchListItem {
} else {
return icon;
}
+ case GPX_TRACK:
+ return getIcon(app, R.drawable.ic_action_polygom_dark);
case LOCATION:
return getIcon(app, R.drawable.ic_action_world_globe);
case FAVORITE:
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
index c674ea82ab..357ea3ba8a 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
@@ -59,6 +59,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.base.ContextMenuFragment;
import net.osmand.plus.base.ContextMenuScrollFragment;
@@ -81,6 +82,7 @@ import net.osmand.plus.myplaces.TrackActivityFragmentAdapter;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
+import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
@@ -270,6 +272,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
if (contextMenu.isActive() && contextMenu.getPointDescription() != null
&& contextMenu.getPointDescription().isGpxPoint()) {
contextMenu.show();
+ } else if (Algorithms.objectEquals(returnScreenName, QuickSearchDialogFragment.TAG)) {
+ mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
} else {
mapActivity.launchPrevActivityIntent();
}