Merge pull request #7956 from osmandapp/fix_7501

Fix #7501
This commit is contained in:
max-klaus 2019-11-20 14:43:49 +03:00 committed by GitHub
commit 3d7fc6b108
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 67 additions and 38 deletions

View file

@ -1238,7 +1238,7 @@ public class OsmandAidlApi {
@Override @Override
protected void onPostExecute(GPXFile gpx) { protected void onPostExecute(GPXFile gpx) {
if (gpx.error == null) { if (gpx.error == null) {
selectedGpx.setGpxFile(gpx); selectedGpx.setGpxFile(gpx, app);
refreshMap(); refreshMap();
} }
} }
@ -1417,7 +1417,7 @@ public class OsmandAidlApi {
} }
long modifiedTime = gpxFile.modifiedTime; long modifiedTime = gpxFile.modifiedTime;
long fileSize = new File(gpxFile.path).length(); long fileSize = new File(gpxFile.path).length();
files.add(new ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetails(selectedGpxFile.getTrackAnalysis()))); files.add(new ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetails(selectedGpxFile.getTrackAnalysis(app))));
} }
} }
return true; return true;
@ -1435,7 +1435,7 @@ public class OsmandAidlApi {
} }
long modifiedTime = gpxFile.modifiedTime; long modifiedTime = gpxFile.modifiedTime;
long fileSize = new File(gpxFile.path).length(); long fileSize = new File(gpxFile.path).length();
files.add(new net.osmand.aidlapi.gpx.ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetailsV2(selectedGpxFile.getTrackAnalysis()))); files.add(new net.osmand.aidlapi.gpx.ASelectedGpxFile(path, modifiedTime, fileSize, createGpxFileDetailsV2(selectedGpxFile.getTrackAnalysis(app))));
} }
} }
return true; return true;

View file

@ -151,10 +151,13 @@ public class GpxSelectionHelper {
return null; return null;
} }
public void processSplit() { public static boolean processSplit(OsmandApplication app) {
if (app == null || app.isApplicationInitializing()) {
return false;
}
List<GpxDataItem> items = app.getGpxDbHelper().getSplitItems(); List<GpxDataItem> items = app.getGpxDbHelper().getSplitItems();
for (GpxDataItem dataItem : items) { for (GpxDataItem dataItem : items) {
SelectedGpxFile selectedGpxFile = getSelectedFileByPath(dataItem.getFile().getAbsolutePath()); SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(dataItem.getFile().getAbsolutePath());
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) { if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
GPXFile gpxFile = selectedGpxFile.getGpxFile(); GPXFile gpxFile = selectedGpxFile.getGpxFile();
List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
@ -162,20 +165,21 @@ public class GpxSelectionHelper {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.noSplit(app); model.noSplit(app);
} }
selectedGpxFile.setDisplayGroups(groups); selectedGpxFile.setDisplayGroups(groups, app);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.splitByDistance(app, dataItem.getSplitInterval()); model.splitByDistance(app, dataItem.getSplitInterval());
} }
selectedGpxFile.setDisplayGroups(groups); selectedGpxFile.setDisplayGroups(groups, app);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) { } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.splitByTime(app, (int) dataItem.getSplitInterval()); model.splitByTime(app, (int) dataItem.getSplitInterval());
} }
selectedGpxFile.setDisplayGroups(groups); selectedGpxFile.setDisplayGroups(groups, app);
} }
} }
} }
return true;
} }
private String getString(int resId, Object... formatArgs) { private String getString(int resId, Object... formatArgs) {
@ -508,6 +512,7 @@ public class GpxSelectionHelper {
} else { } else {
selectGpxFile(gpx, true, false, true, selectedByUser, false); selectGpxFile(gpx, true, false, true, selectedByUser, false);
} }
gpx.addGeneralTrack();
} else if (obj.has(CURRENT_TRACK)) { } else if (obj.has(CURRENT_TRACK)) {
SelectedGpxFile file = savingTrackHelper.getCurrentTrack(); SelectedGpxFile file = savingTrackHelper.getCurrentTrack();
file.selectedByUser = selectedByUser; file.selectedByUser = selectedByUser;
@ -516,7 +521,6 @@ public class GpxSelectionHelper {
selectedGPXFiles = newSelectedGPXFiles; selectedGPXFiles = newSelectedGPXFiles;
} }
} }
processSplit();
if (save) { if (save) {
saveCurrentSelections(); saveCurrentSelections();
} }
@ -589,7 +593,7 @@ public class GpxSelectionHelper {
if (dataItem != null && dataItem.getColor() != 0) { if (dataItem != null && dataItem.getColor() != 0) {
gpx.setColor(dataItem.getColor()); gpx.setColor(dataItem.getColor());
} }
sf.setGpxFile(gpx); sf.setGpxFile(gpx, app);
sf.notShowNavigationDialog = notShowNavigationDialog; sf.notShowNavigationDialog = notShowNavigationDialog;
sf.selectedByUser = selectedByUser; sf.selectedByUser = selectedByUser;
} }
@ -606,6 +610,9 @@ public class GpxSelectionHelper {
if (syncGroup) { if (syncGroup) {
syncGpxWithMarkers(gpx); syncGpxWithMarkers(gpx);
} }
if (sf != null) {
sf.splitProcessed = false;
}
return sf; return sf;
} }
@ -667,36 +674,38 @@ public class GpxSelectionHelper {
private int color; private int color;
private GPXTrackAnalysis trackAnalysis; private GPXTrackAnalysis trackAnalysis;
private long modifiedTime = -1; private long modifiedTime = -1;
private boolean splitProcessed = false;
private List<TrkSegment> processedPointsToDisplay = new ArrayList<>(); private List<TrkSegment> processedPointsToDisplay = new ArrayList<>();
private boolean routePoints; private boolean routePoints;
private List<GpxDisplayGroup> displayGroups; private List<GpxDisplayGroup> displayGroups;
public void setGpxFile(GPXFile gpxFile) { public void setGpxFile(GPXFile gpxFile, OsmandApplication app) {
this.gpxFile = gpxFile; this.gpxFile = gpxFile;
if (gpxFile.tracks.size() > 0) { if (gpxFile.tracks.size() > 0) {
this.color = gpxFile.tracks.get(0).getColor(0); this.color = gpxFile.tracks.get(0).getColor(0);
} }
processPoints(); processPoints(app);
} }
public GPXTrackAnalysis getTrackAnalysis() { public GPXTrackAnalysis getTrackAnalysis(OsmandApplication app) {
if (modifiedTime != gpxFile.modifiedTime) { if (modifiedTime != gpxFile.modifiedTime) {
update(); update(app);
} }
return trackAnalysis; return trackAnalysis;
} }
private void update() { private void update(OsmandApplication app) {
modifiedTime = gpxFile.modifiedTime; modifiedTime = gpxFile.modifiedTime;
trackAnalysis = gpxFile.getAnalysis( trackAnalysis = gpxFile.getAnalysis(
Algorithms.isEmpty(gpxFile.path) ? System.currentTimeMillis() : Algorithms.isEmpty(gpxFile.path) ? System.currentTimeMillis() :
new File(gpxFile.path).lastModified()); new File(gpxFile.path).lastModified());
displayGroups = null; displayGroups = null;
splitProcessed = GpxSelectionHelper.processSplit(app);
} }
public void processPoints() { public void processPoints(OsmandApplication app) {
update(); update(app);
this.processedPointsToDisplay = gpxFile.proccessPoints(); this.processedPointsToDisplay = gpxFile.proccessPoints();
if (this.processedPointsToDisplay.isEmpty()) { if (this.processedPointsToDisplay.isEmpty()) {
this.processedPointsToDisplay = gpxFile.processRoutePoints(); this.processedPointsToDisplay = gpxFile.processRoutePoints();
@ -737,16 +746,16 @@ public class GpxSelectionHelper {
return color; return color;
} }
public List<GpxDisplayGroup> getDisplayGroups() { public List<GpxDisplayGroup> getDisplayGroups(OsmandApplication app) {
if (modifiedTime != gpxFile.modifiedTime) { if (modifiedTime != gpxFile.modifiedTime || !splitProcessed) {
update(); update(app);
} }
return displayGroups; return displayGroups;
} }
public void setDisplayGroups(List<GpxDisplayGroup> displayGroups) { public void setDisplayGroups(List<GpxDisplayGroup> displayGroups, OsmandApplication app) {
if (modifiedTime != gpxFile.modifiedTime) { if (modifiedTime != gpxFile.modifiedTime) {
update(); update(app);
} }
this.displayGroups = displayGroups; this.displayGroups = displayGroups;
} }

View file

@ -78,7 +78,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
this.currentTrack.setShowCurrentTrack(true); this.currentTrack.setShowCurrentTrack(true);
GPXFile gx = new GPXFile(Version.getFullVersion(ctx)); GPXFile gx = new GPXFile(Version.getFullVersion(ctx));
gx.showCurrentTrack = true; gx.showCurrentTrack = true;
this.currentTrack.setGpxFile(gx); this.currentTrack.setGpxFile(gx, ctx);
prepareCurrentTrackForRecording(); prepareCurrentTrackForRecording();
updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", " updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", "
@ -482,7 +482,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
lt.points.add(pt); lt.points.add(pt);
} }
if (segmentAdded) { if (segmentAdded) {
currentTrack.processPoints(); currentTrack.processPoints(ctx);
} }
currentTrack.getModifiableGpxFile().modifiedTime = time; currentTrack.getModifiableGpxFile().modifiedTime = time;
} }
@ -629,7 +629,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile()); ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile());
currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks); currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks);
} }
currentTrack.processPoints(); currentTrack.processPoints(ctx);
prepareCurrentTrackForRecording(); prepareCurrentTrackForRecording();
GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis()); GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis());
distance = analysis.totalDistance; distance = analysis.totalDistance;

View file

@ -189,8 +189,8 @@ public class TrackActivity extends TabActivity {
} }
if (file != null) { if (file != null) {
SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(gpxFile.path); SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(gpxFile.path);
if (sf != null && file != null && sf.getDisplayGroups() != null) { if (sf != null && file != null && sf.getDisplayGroups(app) != null) {
displayGroups = sf.getDisplayGroups(); displayGroups = sf.getDisplayGroups(app);
} }
} }
} }
@ -479,7 +479,7 @@ public class TrackActivity extends TabActivity {
} else { } else {
final SelectedGpxFile selectedGpx = helper.getSelectedFileByPath(result.path); final SelectedGpxFile selectedGpx = helper.getSelectedFileByPath(result.path);
if (selectedGpx != null && result.error == null) { if (selectedGpx != null && result.error == null) {
selectedGpx.setGpxFile(result); selectedGpx.setGpxFile(result, app);
} }
} }
} }

View file

@ -796,7 +796,7 @@ public class GpxUiHelper {
GPXTrackAnalysis analysis = null; GPXTrackAnalysis analysis = null;
if (currentlyRecordingTrack) { if (currentlyRecordingTrack) {
analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(); analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(app);
} else if (dataItem != null) { } else if (dataItem != null) {
analysis = dataItem.getAnalysis(); analysis = dataItem.getAnalysis();
} }
@ -1025,6 +1025,8 @@ public class GpxUiHelper {
GPXFile res = GPXUtilities.loadGPXFile(f); GPXFile res = GPXUtilities.loadGPXFile(f);
if (res.error != null && !Algorithms.isEmpty(res.error.getMessage())) { if (res.error != null && !Algorithms.isEmpty(res.error.getMessage())) {
w += res.error.getMessage() + "\n"; w += res.error.getMessage() + "\n";
} else {
res.addGeneralTrack();
} }
result[k++] = res; result[k++] = res;
} }

View file

@ -1349,7 +1349,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
SelectedGpxFile sf = activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false); SelectedGpxFile sf = activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
if (sf != null) { if (sf != null) {
if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) { if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
sf.processPoints(); sf.processPoints(getMyApplication());
} }
} }
} }

View file

@ -1867,9 +1867,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
SelectedGpxFile sgpx = getSelectedGpxFile(gpxInfo, app); SelectedGpxFile sgpx = getSelectedGpxFile(gpxInfo, app);
GPXTrackAnalysis analysis = null; GPXTrackAnalysis analysis = null;
if (sgpx != null) { if (sgpx != null) {
analysis = sgpx.getTrackAnalysis(); analysis = sgpx.getTrackAnalysis(app);
} else if (gpxInfo.currentlyRecordingTrack) { } else if (gpxInfo.currentlyRecordingTrack) {
analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(); analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(app);
} else if (gpxInfo.file != null) { } else if (gpxInfo.file != null) {
GpxDataItemCallback analyserCallback = null; GpxDataItemCallback analyserCallback = null;
if (callback != null) { if (callback != null) {

View file

@ -695,7 +695,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
if (mSelectedGpxFile != null) { if (mSelectedGpxFile != null) {
List<GpxDisplayGroup> groups = getDisplayGroups(); List<GpxDisplayGroup> groups = getDisplayGroups();
mSelectedGpxFile.setDisplayGroups(groups); mSelectedGpxFile.setDisplayGroups(groups, app);
} }
updateContent(); updateContent();
} }

View file

@ -720,6 +720,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
private void updateSplitIntervalView(View view) { private void updateSplitIntervalView(View view) {
final TextView text = (TextView) view.findViewById(R.id.split_interval_text); final TextView text = (TextView) view.findViewById(R.id.split_interval_text);
selectedSplitInterval = getSelectedSplitInterval();
if (selectedSplitInterval == 0) { if (selectedSplitInterval == 0) {
text.setText(app.getString(R.string.shared_string_none)); text.setText(app.getString(R.string.shared_string_none));
} else { } else {
@ -727,6 +728,23 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
} }
} }
private int getSelectedSplitInterval() {
if (getGpxDataItem() == null) {
return 0;
}
int splitType = getGpxDataItem().getSplitType();
double splitInterval = getGpxDataItem().getSplitInterval();
int position = 0;
if (splitType == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
position = distanceSplit.indexOf(splitInterval);
} else if (splitType == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
position = timeSplit.indexOf((int) splitInterval);
}
return position > 0 ? position : 0;
}
private void updateColorView(View colorView) { private void updateColorView(View colorView) {
final ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage); final ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage);
int color = getGpxDataItem() != null ? getGpxDataItem().getColor() : 0; int color = getGpxDataItem() != null ? getGpxDataItem().getColor() : 0;
@ -1008,7 +1026,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
} }
if (selectedGpx != null) { if (selectedGpx != null) {
List<GpxDisplayGroup> groups = fragment.getDisplayGroups(); List<GpxDisplayGroup> groups = fragment.getDisplayGroups();
selectedGpx.setDisplayGroups(groups); selectedGpx.setDisplayGroups(groups, app);
} }
/* /*
if (fragment.isVisible()) { if (fragment.isVisible()) {

View file

@ -206,7 +206,7 @@ public class TrackBitmapDrawer {
sf = app.getSavingTrackHelper().getCurrentTrack(); sf = app.getSavingTrackHelper().getCurrentTrack();
} else { } else {
sf = new GpxSelectionHelper.SelectedGpxFile(); sf = new GpxSelectionHelper.SelectedGpxFile();
sf.setGpxFile(gpxFile); sf.setGpxFile(gpxFile, app);
} }
Bitmap bmp = mapBitmap.copy(mapBitmap.getConfig(), true); Bitmap bmp = mapBitmap.copy(mapBitmap.getConfig(), true);
Canvas canvas = new Canvas(bmp); Canvas canvas = new Canvas(bmp);

View file

@ -1294,8 +1294,8 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
if (selectedGpx != null) { if (selectedGpx != null) {
List<GpxDisplayGroup> groups = fragment.getDisplayGroups(); List<GpxDisplayGroup> groups = fragment.getDisplayGroups();
if (groups != null) { if (groups != null) {
selectedGpx.setDisplayGroups(groups); selectedGpx.setDisplayGroups(groups, app);
selectedGpx.processPoints(); selectedGpx.processPoints(app);
} }
} }
fragment.updateContent(); fragment.updateContent();

View file

@ -289,7 +289,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
if (tileBox.getZoom() >= startZoom) { if (tileBox.getZoom() >= startZoom) {
// request to load // request to load
for (SelectedGpxFile g : selectedGPXFiles) { for (SelectedGpxFile g : selectedGPXFiles) {
List<GpxDisplayGroup> groups = g.getDisplayGroups(); List<GpxDisplayGroup> groups = g.getDisplayGroups(view.getApplication());
if (groups != null && !groups.isEmpty()) { if (groups != null && !groups.isEmpty()) {
int color = g.getGpxFile().getColor(0); int color = g.getGpxFile().getColor(0);
if (color == 0) { if (color == 0) {