Add visible GPX to history - refactoring
This commit is contained in:
parent
a4e7edc6bd
commit
8ceab0c5c3
8 changed files with 61 additions and 21 deletions
|
@ -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.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.enums.MetricsConstants;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
|
@ -735,7 +736,8 @@ public class GpxSelectionHelper {
|
|||
String path = gpx.path;
|
||||
String rootGpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath() + '/';
|
||||
String fileName = path.replace(rootGpxDir, "");
|
||||
SearchHistoryHelper.getInstance(app).addGpxFileToHistory(fileName);
|
||||
GPXInfo gpxInfo = GpxUiHelper.getGpxInfoByFileName(app, fileName);
|
||||
SearchHistoryHelper.getInstance(app).addNewItemToHistory(gpxInfo);
|
||||
}
|
||||
return sf;
|
||||
}
|
||||
|
|
|
@ -750,12 +750,33 @@ public class GpxUiHelper {
|
|||
gpxDbHelper.updateShowStartFinish(item, showStartFinish);
|
||||
}
|
||||
|
||||
public static void updateGpxInfoView(OsmandApplication app,
|
||||
View v,
|
||||
String itemTitle,
|
||||
Drawable iconDrawable,
|
||||
GPXInfo info) {
|
||||
GpxDataItem dataItem = getDataItem(app, info);
|
||||
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);
|
||||
|
@ -837,9 +858,13 @@ public class GpxUiHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static GpxDataItem getDataItem(OsmandApplication app, GPXInfo info) {
|
||||
return app.getGpxDbHelper().getItem(
|
||||
new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), info.getFileName()));
|
||||
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)
|
||||
|
@ -917,7 +942,7 @@ public class GpxUiHelper {
|
|||
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||
List<GPXInfo> infoList = getSortedGPXFilesInfo(dir, null, false);
|
||||
for (GPXInfo info : infoList) {
|
||||
if (Algorithms.objectEquals(info.fileName, fileName)) {
|
||||
if (Algorithms.objectEquals(info.getFileName(), fileName)) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -42,10 +43,6 @@ 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));
|
||||
}
|
||||
|
@ -59,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<HistoryEntry> getHistoryEntries(boolean onlyPoints) {
|
||||
if (loadedEntries == null) {
|
||||
checkLoadedEntries();
|
||||
|
@ -81,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) {
|
||||
|
@ -89,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);
|
||||
|
|
|
@ -515,7 +515,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
List<HistoryEntry> historyEntries = new ArrayList<HistoryEntry>();
|
||||
List<QuickSearchListItem> selectedItems = historySearchFragment.getListAdapter().getSelectedItems();
|
||||
for (QuickSearchListItem searchListItem : selectedItems) {
|
||||
Object object = searchListItem.getSearchResult().object;
|
||||
SearchResult sr = searchListItem.getSearchResult();
|
||||
Object object = sr.objectType == GPX_TRACK ? sr.relatedObject : sr.object;
|
||||
if (object instanceof HistoryEntry) {
|
||||
historyEntries.add((HistoryEntry) object);
|
||||
}
|
||||
|
|
|
@ -465,6 +465,7 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
sr.localeName = gpxInfo.getFileName();
|
||||
sr.object = gpxInfo;
|
||||
sr.objectType = ObjectType.GPX_TRACK;
|
||||
sr.relatedObject = point;
|
||||
publish = true;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -579,7 +579,8 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
|
|||
selectedItems.clear();
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
QuickSearchListItemType t = getItem(i).getType();
|
||||
if (t == QuickSearchListItemType.SEARCH_RESULT) {
|
||||
if (t == QuickSearchListItemType.SEARCH_RESULT
|
||||
|| t == QuickSearchListItemType.GPX_TRACK) {
|
||||
selectedItems.add(getItem(i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -305,11 +305,10 @@ 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);
|
||||
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, null);
|
||||
TrackMenuFragment.showInstance(mapActivity, path, false, null, QuickSearchDialogFragment.TAG);
|
||||
dialogFragment.dismiss();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -82,6 +83,7 @@ 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.routing.RouteProvider;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
|
||||
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue