Improve join segments functionality
This commit is contained in:
parent
418cb67b5b
commit
b04844f159
12 changed files with 136 additions and 86 deletions
|
@ -287,17 +287,17 @@ public class GPXUtilities {
|
|||
public Object renderer;
|
||||
|
||||
|
||||
public List<GPXTrackAnalysis> splitByDistance(double meters, boolean joinGaps) {
|
||||
return split(getDistanceMetric(), getTimeSplit(), meters, joinGaps);
|
||||
public List<GPXTrackAnalysis> splitByDistance(double meters, boolean joinSegments) {
|
||||
return split(getDistanceMetric(), getTimeSplit(), meters, joinSegments);
|
||||
}
|
||||
|
||||
public List<GPXTrackAnalysis> splitByTime(int seconds, boolean joinGaps) {
|
||||
return split(getTimeSplit(), getDistanceMetric(), seconds, joinGaps);
|
||||
public List<GPXTrackAnalysis> splitByTime(int seconds, boolean joinSegments) {
|
||||
return split(getTimeSplit(), getDistanceMetric(), seconds, joinSegments);
|
||||
}
|
||||
|
||||
private List<GPXTrackAnalysis> split(SplitMetric metric, SplitMetric secondaryMetric, double metricLimit, boolean joinGaps) {
|
||||
private List<GPXTrackAnalysis> split(SplitMetric metric, SplitMetric secondaryMetric, double metricLimit, boolean joinSegments) {
|
||||
List<SplitSegment> splitSegments = new ArrayList<>();
|
||||
splitSegment(metric, secondaryMetric, metricLimit, splitSegments, this, joinGaps);
|
||||
splitSegment(metric, secondaryMetric, metricLimit, splitSegments, this, joinSegments);
|
||||
return convert(splitSegments);
|
||||
}
|
||||
|
||||
|
@ -852,8 +852,8 @@ public class GPXUtilities {
|
|||
}
|
||||
|
||||
private static void splitSegment(SplitMetric metric, SplitMetric secondaryMetric,
|
||||
double metricLimit, List<SplitSegment> splitSegments,
|
||||
TrkSegment segment, boolean joinGaps) {
|
||||
double metricLimit, List<SplitSegment> splitSegments,
|
||||
TrkSegment segment, boolean joinSegments) {
|
||||
double currentMetricEnd = metricLimit;
|
||||
double secondaryMetricEnd = 0;
|
||||
SplitSegment sp = new SplitSegment(segment, 0, 0);
|
||||
|
@ -863,7 +863,7 @@ public class GPXUtilities {
|
|||
WptPt point = segment.points.get(k);
|
||||
if (k > 0) {
|
||||
double currentSegment = 0;
|
||||
if (!(segment.generalSegment && joinGaps && point.firstPoint)) {
|
||||
if (!(segment.generalSegment && joinSegments && point.firstPoint)) {
|
||||
currentSegment = metric.metric(prev, point);
|
||||
secondaryMetricEnd += secondaryMetric.metric(prev, point);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
android:gravity="center_vertical"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:text="@string/gpx_join_gaps"
|
||||
android:text="@string/join_segments"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular" />
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
android:gravity="center_vertical"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:text="@string/gpx_join_gaps"
|
||||
android:text="@string/join_segments"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular" />
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
android:gravity="center_vertical"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:text="@string/gpx_join_gaps"
|
||||
android:text="@string/join_segments"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular" />
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="join_segments">Join segments</string>
|
||||
<string name="download_map_dialog">Download map dialog</string>
|
||||
<string name="dialogs_and_notifications_title">Dialogs and notifications</string>
|
||||
<string name="dialogs_and_notifications_descr">Control popups, dialogs and notifications that OsmAnd show during usage.</string>
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
public class GPXDatabase {
|
||||
|
||||
private static final String DB_NAME = "gpx_database";
|
||||
private static final int DB_VERSION = 9;
|
||||
private static final int DB_VERSION = 10;
|
||||
private static final String GPX_TABLE_NAME = "gpxTable";
|
||||
private static final String GPX_COL_NAME = "fileName";
|
||||
private static final String GPX_COL_DIR = "fileDir";
|
||||
|
@ -54,6 +54,8 @@ public class GPXDatabase {
|
|||
|
||||
private static final String GPX_COL_SHOW_AS_MARKERS = "showAsMarkers";
|
||||
|
||||
private static final String GPX_COL_JOIN_SEGMENTS = "joinSegments";
|
||||
|
||||
public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1;
|
||||
public static final int GPX_SPLIT_TYPE_DISTANCE = 1;
|
||||
public static final int GPX_SPLIT_TYPE_TIME = 2;
|
||||
|
@ -86,7 +88,8 @@ public class GPXDatabase {
|
|||
GPX_COL_SPLIT_INTERVAL + " double, " +
|
||||
GPX_COL_API_IMPORTED + " int, " + // 1 = true, 0 = false
|
||||
GPX_COL_WPT_CATEGORY_NAMES + " TEXT, " +
|
||||
GPX_COL_SHOW_AS_MARKERS + " int);"; // 1 = true, 0 = false
|
||||
GPX_COL_SHOW_AS_MARKERS + " int, " + // 1 = true, 0 = false
|
||||
GPX_COL_JOIN_SEGMENTS + " int);"; // 1 = true, 0 = false
|
||||
|
||||
private static final String GPX_TABLE_SELECT = "SELECT " +
|
||||
GPX_COL_NAME + ", " +
|
||||
|
@ -113,7 +116,8 @@ public class GPXDatabase {
|
|||
GPX_COL_SPLIT_INTERVAL + ", " +
|
||||
GPX_COL_API_IMPORTED + ", " +
|
||||
GPX_COL_WPT_CATEGORY_NAMES + ", " +
|
||||
GPX_COL_SHOW_AS_MARKERS +
|
||||
GPX_COL_SHOW_AS_MARKERS + ", " +
|
||||
GPX_COL_JOIN_SEGMENTS +
|
||||
" FROM " + GPX_TABLE_NAME;
|
||||
|
||||
private static final String GPX_TABLE_UPDATE_ANALYSIS = "UPDATE " +
|
||||
|
@ -148,6 +152,7 @@ public class GPXDatabase {
|
|||
private double splitInterval;
|
||||
private boolean apiImported;
|
||||
private boolean showAsMarkers;
|
||||
private boolean joinSegments;
|
||||
|
||||
public GpxDataItem(File file, GPXTrackAnalysis analysis) {
|
||||
this.file = file;
|
||||
|
@ -200,6 +205,14 @@ public class GPXDatabase {
|
|||
this.showAsMarkers = showAsMarkers;
|
||||
}
|
||||
|
||||
public boolean isJoinSegments() {
|
||||
return joinSegments;
|
||||
}
|
||||
|
||||
public void setJoinSegments(boolean joinSegments) {
|
||||
this.joinSegments = joinSegments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return file != null ? file.hashCode() : 0;
|
||||
|
@ -322,6 +335,12 @@ public class GPXDatabase {
|
|||
" SET " + GPX_COL_SHOW_AS_MARKERS + " = ? " +
|
||||
"WHERE " + GPX_COL_SHOW_AS_MARKERS + " IS NULL", new Object[]{0});
|
||||
}
|
||||
if (oldVersion < 10) {
|
||||
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_JOIN_SEGMENTS + " int");
|
||||
db.execSQL("UPDATE " + GPX_TABLE_NAME +
|
||||
" SET " + GPX_COL_JOIN_SEGMENTS + " = ? " +
|
||||
"WHERE " + GPX_COL_JOIN_SEGMENTS + " IS NULL", new Object[]{0});
|
||||
}
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS " + GPX_INDEX_NAME_DIR + " ON " + GPX_TABLE_NAME + " (" + GPX_COL_NAME + ", " + GPX_COL_DIR + ");");
|
||||
}
|
||||
|
||||
|
@ -404,6 +423,25 @@ public class GPXDatabase {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean updateJoinSegments(GpxDataItem item, boolean joinSegments) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
String fileName = getFileName(item.file);
|
||||
String fileDir = getFileDir(item.file);
|
||||
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " +
|
||||
GPX_COL_JOIN_SEGMENTS + " = ? " +
|
||||
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
|
||||
new Object[]{joinSegments ? 1 : 0, fileName, fileDir});
|
||||
item.setJoinSegments(joinSegments);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateSplit(@NonNull GpxDataItem item, int splitType, double splitInterval) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null){
|
||||
|
@ -480,12 +518,12 @@ public class GPXDatabase {
|
|||
}
|
||||
if (a != null) {
|
||||
db.execSQL(
|
||||
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{ fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime,
|
||||
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[] {fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime,
|
||||
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
|
||||
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
|
||||
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0,
|
||||
Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0});
|
||||
Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0});
|
||||
} else {
|
||||
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" +
|
||||
GPX_COL_NAME + ", " +
|
||||
|
@ -495,9 +533,10 @@ public class GPXDatabase {
|
|||
GPX_COL_SPLIT_TYPE + ", " +
|
||||
GPX_COL_SPLIT_INTERVAL + ", " +
|
||||
GPX_COL_API_IMPORTED + ", " +
|
||||
GPX_COL_SHOW_AS_MARKERS +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0});
|
||||
GPX_COL_SHOW_AS_MARKERS + ", " +
|
||||
GPX_COL_JOIN_SEGMENTS +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -575,6 +614,7 @@ public class GPXDatabase {
|
|||
boolean apiImported = query.getInt(22) == 1;
|
||||
String wptCategoryNames = query.getString(23);
|
||||
boolean showAsMarkers = query.getInt(24) == 1;
|
||||
boolean joinSegments = query.getInt(25) == 1;
|
||||
|
||||
GPXTrackAnalysis a = new GPXTrackAnalysis();
|
||||
a.totalDistance = totalDistance;
|
||||
|
@ -615,6 +655,7 @@ public class GPXDatabase {
|
|||
item.splitInterval = splitInterval;
|
||||
item.apiImported = apiImported;
|
||||
item.showAsMarkers = showAsMarkers;
|
||||
item.joinSegments = joinSegments;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,12 @@ public class GpxDbHelper {
|
|||
return res;
|
||||
}
|
||||
|
||||
public boolean updateJoinSegments(@NonNull GpxDataItem item, boolean joinSegments) {
|
||||
boolean res = db.updateJoinSegments(item, joinSegments);
|
||||
putToCache(item);
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean remove(File file) {
|
||||
boolean res = db.remove(file);
|
||||
itemsCache.remove(file);
|
||||
|
|
|
@ -64,7 +64,7 @@ public class GpxSelectionHelper {
|
|||
public void clearAllGpxFilesToShow(boolean backupSelection) {
|
||||
selectedGpxFilesBackUp.clear();
|
||||
if (backupSelection) {
|
||||
for (SelectedGpxFile s : selectedGPXFiles) {
|
||||
for(SelectedGpxFile s : selectedGPXFiles) {
|
||||
selectedGpxFilesBackUp.put(s.gpxFile, s.modifiedTime);
|
||||
}
|
||||
}
|
||||
|
@ -169,12 +169,12 @@ public class GpxSelectionHelper {
|
|||
selectedGpxFile.setDisplayGroups(groups, app);
|
||||
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
|
||||
for (GpxDisplayGroup model : groups) {
|
||||
model.splitByDistance(app, dataItem.getSplitInterval());
|
||||
model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments());
|
||||
}
|
||||
selectedGpxFile.setDisplayGroups(groups, app);
|
||||
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
|
||||
for (GpxDisplayGroup model : groups) {
|
||||
model.splitByTime(app, (int) dataItem.getSplitInterval());
|
||||
model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments());
|
||||
}
|
||||
selectedGpxFile.setDisplayGroups(groups, app);
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ public class GpxSelectionHelper {
|
|||
processGroupTrack(app, group, false);
|
||||
}
|
||||
|
||||
private static void processGroupTrack(@NonNull OsmandApplication app, @NonNull GpxDisplayGroup group, boolean joinGaps) {
|
||||
private static void processGroupTrack(@NonNull OsmandApplication app, @NonNull GpxDisplayGroup group, boolean joinSegments) {
|
||||
if (group.track == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -338,10 +338,10 @@ public class GpxSelectionHelper {
|
|||
GPXTrackAnalysis[] as;
|
||||
boolean split = true;
|
||||
if (group.splitDistance > 0) {
|
||||
List<GPXTrackAnalysis> trackSegments = r.splitByDistance(group.splitDistance, joinGaps);
|
||||
List<GPXTrackAnalysis> trackSegments = r.splitByDistance(group.splitDistance, joinSegments);
|
||||
as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]);
|
||||
} else if (group.splitTime > 0) {
|
||||
List<GPXTrackAnalysis> trackSegments = r.splitByTime(group.splitTime, joinGaps);
|
||||
List<GPXTrackAnalysis> trackSegments = r.splitByTime(group.splitTime, joinSegments);
|
||||
as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]);
|
||||
} else {
|
||||
split = false;
|
||||
|
@ -512,7 +512,7 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
if (gpx.error != null) {
|
||||
save = true;
|
||||
} else if (obj.has(BACKUP)) {
|
||||
} else if(obj.has(BACKUP)) {
|
||||
selectedGpxFilesBackUp.put(gpx, gpx.modifiedTime);
|
||||
} else {
|
||||
selectGpxFile(gpx, true, false, true, selectedByUser, false);
|
||||
|
@ -561,7 +561,7 @@ public class GpxSelectionHelper {
|
|||
if (s != null) {
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
if (Algorithms.isEmpty(s.getKey().path)) {
|
||||
if(Algorithms.isEmpty(s.getKey().path)) {
|
||||
obj.put(CURRENT_TRACK, true);
|
||||
} else {
|
||||
obj.put(FILE, s.getKey().path);
|
||||
|
@ -873,26 +873,18 @@ public class GpxSelectionHelper {
|
|||
processGroupTrack(app, this);
|
||||
}
|
||||
|
||||
public void splitByDistance(OsmandApplication app, double meters) {
|
||||
splitByDistance(app, meters, false);
|
||||
}
|
||||
|
||||
public void splitByDistance(OsmandApplication app, double meters, boolean joinGaps) {
|
||||
public void splitByDistance(OsmandApplication app, double meters, boolean joinSegments) {
|
||||
list.clear();
|
||||
splitDistance = meters;
|
||||
splitTime = -1;
|
||||
processGroupTrack(app, this, joinGaps);
|
||||
processGroupTrack(app, this, joinSegments);
|
||||
}
|
||||
|
||||
public void splitByTime(OsmandApplication app, int seconds) {
|
||||
splitByTime(app, seconds, false);
|
||||
}
|
||||
|
||||
public void splitByTime(OsmandApplication app, int seconds, boolean joinGaps) {
|
||||
public void splitByTime(OsmandApplication app, int seconds, boolean joinSegments) {
|
||||
list.clear();
|
||||
splitDistance = -1;
|
||||
splitTime = seconds;
|
||||
processGroupTrack(app, this, joinGaps);
|
||||
processGroupTrack(app, this, joinSegments);
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
|
|
|
@ -410,6 +410,17 @@ public class TrackActivity extends TabActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean setJoinSegments(boolean joinSegments) {
|
||||
if (gpxDataItem != null) {
|
||||
return app.getGpxDbHelper().updateJoinSegments(gpxDataItem, joinSegments);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isJoinSegments() {
|
||||
return gpxDataItem != null && gpxDataItem.isJoinSegments();
|
||||
}
|
||||
|
||||
private static class GPXFileLoaderTask extends AsyncTask<Void, Void, GPXFile> {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
|
|
@ -73,7 +73,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
private Rect minMaxSpeedTextBounds;
|
||||
private ListView listView;
|
||||
private ProgressBar progressBar;
|
||||
private boolean joinGapsEnabled;
|
||||
private boolean joinSegments;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -192,10 +192,6 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
super.onDestroyView();
|
||||
}
|
||||
|
||||
public void setJoinGapsEnabled(boolean joinGapsEnabled) {
|
||||
this.joinGapsEnabled = joinGapsEnabled;
|
||||
}
|
||||
|
||||
public void setGpxItem(GpxDisplayItem gpxItem) {
|
||||
this.gpxItem = gpxItem;
|
||||
}
|
||||
|
@ -204,6 +200,10 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
this.trkSegment = trkSegment;
|
||||
}
|
||||
|
||||
public void setJoinSegments(boolean joinSegments) {
|
||||
this.joinSegments = joinSegments;
|
||||
}
|
||||
|
||||
private void updateHeader() {
|
||||
final View splitIntervalView = headerView.findViewById(R.id.split_interval_view);
|
||||
|
||||
|
@ -423,19 +423,6 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
return splitSegments;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GpxDisplayItem getOverviewSegment() {
|
||||
TrackActivity trackActivity = getTrackActivity();
|
||||
GpxDisplayItem overviewSegment = null;
|
||||
if (trackActivity != null) {
|
||||
List<GpxDisplayGroup> result = trackActivity.getGpxFile(false);
|
||||
if (result.size() > 0 && result.get(0).getModifiableList().size() > 0) {
|
||||
overviewSegment = result.get(0).getModifiableList().get(0);
|
||||
}
|
||||
}
|
||||
return overviewSegment;
|
||||
}
|
||||
|
||||
protected boolean hasFilterType(GpxDisplayItemType filterType) {
|
||||
for (GpxDisplayItemType type : filterTypes) {
|
||||
if (type == filterType) {
|
||||
|
@ -542,7 +529,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
TextView distanceOrTimeSpanText = (TextView) convertView.findViewById(R.id.distance_or_time_span_text);
|
||||
if (position == 0) {
|
||||
distanceOrTimeSpanImageView.setImageDrawable(ic.getIcon(R.drawable.ic_action_track_16, app.getSettings().isLightContent() ? R.color.gpx_split_segment_icon_color : 0));
|
||||
float totalDistance = joinGapsEnabled && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
float totalDistance = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
distanceOrTimeSpanValue.setText(OsmAndFormatter.getFormattedDistance(totalDistance, app));
|
||||
distanceOrTimeSpanText.setText(app.getString(R.string.distance));
|
||||
} else {
|
||||
|
@ -751,9 +738,9 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
if (selectedSplitInterval == 0) {
|
||||
model.noSplit(app);
|
||||
} else if (distanceSplit.get(selectedSplitInterval) > 0) {
|
||||
model.splitByDistance(app, distanceSplit.get(selectedSplitInterval), joinGapsEnabled);
|
||||
model.splitByDistance(app, distanceSplit.get(selectedSplitInterval), joinSegments);
|
||||
} else if (timeSplit.get(selectedSplitInterval) > 0) {
|
||||
model.splitByTime(app, timeSplit.get(selectedSplitInterval), joinGapsEnabled);
|
||||
model.splitByTime(app, timeSplit.get(selectedSplitInterval), joinSegments);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -761,13 +748,13 @@ public class SplitSegmentDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(@NonNull TrackActivity trackActivity, @NonNull GpxDisplayItem gpxItem, GPXUtilities.TrkSegment trkSegment, boolean joinGapsEnabled) {
|
||||
public static boolean showInstance(@NonNull TrackActivity trackActivity, @NonNull GpxDisplayItem gpxItem, GPXUtilities.TrkSegment trkSegment) {
|
||||
try {
|
||||
SplitSegmentDialogFragment fragment = new SplitSegmentDialogFragment();
|
||||
fragment.setGpxItem(gpxItem);
|
||||
fragment.setTrkSegment(trkSegment);
|
||||
fragment.setJoinGapsEnabled(joinGapsEnabled);
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.setJoinSegments(trackActivity.isJoinSegments());
|
||||
fragment.show(trackActivity.getSupportFragmentManager(), TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
|
|
|
@ -992,6 +992,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
|
|||
private List<Double> distanceSplit;
|
||||
private TIntArrayList timeSplit;
|
||||
private int selectedSplitInterval;
|
||||
private boolean joinSegments;
|
||||
|
||||
SplitTrackAsyncTask(@NonNull TrackActivity activity,
|
||||
@NonNull TrackActivityFragmentAdapter fragmentAdapter,
|
||||
|
@ -1006,6 +1007,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
|
|||
selectedSplitInterval = fragmentAdapter.selectedSplitInterval;
|
||||
distanceSplit = fragmentAdapter.distanceSplit;
|
||||
timeSplit = fragmentAdapter.timeSplit;
|
||||
joinSegments = activity.isJoinSegments();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1042,9 +1044,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
|
|||
if (selectedSplitInterval == 0) {
|
||||
model.noSplit(app);
|
||||
} else if (distanceSplit.get(selectedSplitInterval) > 0) {
|
||||
model.splitByDistance(app, distanceSplit.get(selectedSplitInterval));
|
||||
model.splitByDistance(app, distanceSplit.get(selectedSplitInterval), joinSegments);
|
||||
} else if (timeSplit.get(selectedSplitInterval) > 0) {
|
||||
model.splitByTime(app, timeSplit.get(selectedSplitInterval));
|
||||
model.splitByTime(app, timeSplit.get(selectedSplitInterval), joinSegments);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -93,7 +93,6 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
|
||||
private boolean updateEnable;
|
||||
private boolean chartClicked;
|
||||
private boolean joinGapsEnabled;
|
||||
|
||||
private IconPopupMenu generalPopupMenu;
|
||||
private IconPopupMenu altitudePopupMenu;
|
||||
|
@ -719,10 +718,13 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
view.findViewById(R.id.gpx_join_gaps_container).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
joinGapsEnabled = !joinGapsEnabled;
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
View view = getViewAtPosition(i);
|
||||
updateJoinGapsInfo(view, i);
|
||||
TrackActivity activity = getTrackActivity();
|
||||
if (activity != null && activity.setJoinSegments(!activity.isJoinSegments())) {
|
||||
updateSplitView();
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
View view = getViewAtPosition(i);
|
||||
updateJoinGapsInfo(view, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -856,10 +858,13 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
view.findViewById(R.id.gpx_join_gaps_container).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
joinGapsEnabled = !joinGapsEnabled;
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
View view = getViewAtPosition(i);
|
||||
updateJoinGapsInfo(view, i);
|
||||
TrackActivity activity = getTrackActivity();
|
||||
if (activity != null && activity.setJoinSegments(!activity.isJoinSegments())) {
|
||||
updateSplitView();
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
View view = getViewAtPosition(i);
|
||||
updateJoinGapsInfo(view, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -962,10 +967,13 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
view.findViewById(R.id.gpx_join_gaps_container).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
joinGapsEnabled = !joinGapsEnabled;
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
View view = getViewAtPosition(i);
|
||||
updateJoinGapsInfo(view, i);
|
||||
TrackActivity activity = getTrackActivity();
|
||||
if (activity != null && activity.setJoinSegments(!activity.isJoinSegments())) {
|
||||
updateSplitView();
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
View view = getViewAtPosition(i);
|
||||
updateJoinGapsInfo(view, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1138,22 +1146,24 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
}
|
||||
|
||||
void updateJoinGapsInfo(View view, int position) {
|
||||
if (view != null) {
|
||||
TrackActivity activity = getTrackActivity();
|
||||
if (view != null && activity != null) {
|
||||
GPXTrackAnalysis analysis = gpxItem.analysis;
|
||||
GPXTabItemType tabType = tabTypes[position];
|
||||
boolean visible = gpxItem.isGeneralTrack() && analysis != null && tabType.equals(GPXTabItemType.GPX_TAB_ITEM_GENERAL);
|
||||
AndroidUiHelper.updateVisibility(view.findViewById(R.id.gpx_join_gaps_container), visible);
|
||||
((SwitchCompat) view.findViewById(R.id.gpx_join_gaps_switch)).setChecked(joinGapsEnabled);
|
||||
boolean joinSegments = activity.isJoinSegments();
|
||||
((SwitchCompat) view.findViewById(R.id.gpx_join_gaps_switch)).setChecked(joinSegments);
|
||||
if (analysis != null) {
|
||||
if (tabType.equals(GPXTabItemType.GPX_TAB_ITEM_GENERAL)) {
|
||||
float totalDistance = joinGapsEnabled && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
float timeSpan = joinGapsEnabled && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
||||
float totalDistance = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
float timeSpan = joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
||||
|
||||
((TextView) view.findViewById(R.id.distance_text)).setText(OsmAndFormatter.getFormattedDistance(totalDistance, app));
|
||||
((TextView) view.findViewById(R.id.duration_text)).setText(Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()));
|
||||
} else if (tabType.equals(GPXTabItemType.GPX_TAB_ITEM_SPEED)) {
|
||||
long timeMoving = joinGapsEnabled && gpxItem.isGeneralTrack() ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
|
||||
float totalDistanceMoving = joinGapsEnabled && gpxItem.isGeneralTrack() ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
|
||||
long timeMoving = joinSegments && gpxItem.isGeneralTrack() ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
|
||||
float totalDistanceMoving = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
|
||||
|
||||
((TextView) view.findViewById(R.id.time_moving_text)).setText(Algorithms.formatDuration((int) (timeMoving / 1000), app.accessibilityEnabled()));
|
||||
((TextView) view.findViewById(R.id.distance_text)).setText(OsmAndFormatter.getFormattedDistance(totalDistanceMoving, app));
|
||||
|
@ -1249,7 +1259,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
private void openSplitIntervalScreen() {
|
||||
TrackActivity activity = getTrackActivity();
|
||||
if (activity != null) {
|
||||
SplitSegmentDialogFragment.showInstance(activity, gpxItem, getTrkSegment(), joinGapsEnabled);
|
||||
SplitSegmentDialogFragment.showInstance(activity, gpxItem, getTrkSegment());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue