From 07280935c06428b3301c61f6474b868cb4b30715 Mon Sep 17 00:00:00 2001 From: Skalii Date: Mon, 29 Mar 2021 19:18:56 +0300 Subject: [PATCH] some fixes --- .../monitoring/TripRecordingBottomSheet.java | 16 +-- .../TripRecordingClearDataBottomSheet.java | 11 +- .../TripRecordingDiscardBottomSheet.java | 13 ++- .../TripRecordingOptionsBottomSheet.java | 11 +- .../plus/myplaces/GPXItemPagerAdapter.java | 100 ++++++++---------- 5 files changed, 70 insertions(+), 81 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java index aa2a5b6cb6..d4b3115f39 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java @@ -329,7 +329,7 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl } }); - graphsAdapter = new GPXItemPagerAdapter(app, nightMode, this, true, true); + graphsAdapter = new GPXItemPagerAdapter(app, null, null, nightMode, this, true); graphsAdapter.setChartHMargin(getResources().getDimensionPixelSize(R.dimen.content_padding)); pager.setAdapter(graphsAdapter); @@ -607,23 +607,11 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl } } - private TrackDisplayHelper getDisplayHelper() { - TrackDisplayHelper displayHelper = new TrackDisplayHelper(app); - GPXFile gpxFile = getGPXFile(); - if (!selectedGpxFile.isShowCurrentTrack()) { - File file = new File(gpxFile.path); - displayHelper.setFile(file); - displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file)); - } - displayHelper.setGpx(gpxFile); - return displayHelper; - } - @Override public void onPointSelected(TrkSegment segment, double lat, double lon) { if (trackChartPoints == null) { trackChartPoints = new TrackChartPoints(); - trackChartPoints.setGpx(getDisplayHelper().getGpx()); + trackChartPoints.setGpx(getGPXFile()); } MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomSheet.java index cf09a2e7f0..aeb33abf93 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomSheet.java @@ -112,10 +112,15 @@ public class TripRecordingClearDataBottomSheet extends MenuBottomSheetDialogFrag @Override public void dismissTarget() { Fragment target = getTargetFragment(); - Bundle args = new Bundle(); - args.putBoolean(ACTION_CLEAR_DATA, true); - target.setArguments(args); if (target instanceof TripRecordingOptionsBottomSheet) { + Bundle args = target.getArguments(); + if (args != null) { + args.putBoolean(ACTION_CLEAR_DATA, true); + } else { + args = new Bundle(); + args.putBoolean(ACTION_CLEAR_DATA, true); + target.setArguments(args); + } ((TripRecordingOptionsBottomSheet) target).dismiss(); } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomSheet.java index 1136980b51..6739187152 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomSheet.java @@ -68,10 +68,15 @@ public class TripRecordingDiscardBottomSheet extends MenuBottomSheetDialogFragme dismiss(); Fragment target = getTargetFragment(); - if (target != null) { - Bundle args = new Bundle(); - args.putBoolean(ACTION_STOP_AND_DISMISS, true); - target.setArguments(args); + if (target instanceof TripRecordingOptionsBottomSheet) { + Bundle args = target.getArguments(); + if (args != null) { + args.putBoolean(ACTION_STOP_AND_DISMISS, true); + } else { + args = new Bundle(); + args.putBoolean(ACTION_STOP_AND_DISMISS, true); + target.setArguments(args); + } } dismissTarget(); } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomSheet.java index f72de8a640..6004adb74a 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomSheet.java @@ -259,9 +259,14 @@ public class TripRecordingOptionsBottomSheet extends MenuBottomSheetDialogFragme if (mapActivity != null && plugin != null) { stopUpdatingTimeTrackSaved(); plugin.saveCurrentTrack(null, mapActivity, false, true); - Bundle args = new Bundle(); - args.putBoolean(ACTION_STOP_AND_DISMISS, true); - setArguments(args); + Bundle args = getArguments(); + if (args != null) { + args.putBoolean(ACTION_STOP_AND_DISMISS, true); + } else { + args = new Bundle(); + args.putBoolean(ACTION_STOP_AND_DISMISS, true); + setArguments(args); + } dismiss(); dismissTarget(); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java index cea3454fbc..2df66263e4 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java @@ -12,6 +12,7 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.viewpager.widget.PagerAdapter; @@ -89,50 +90,19 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid private boolean chartClicked; private boolean nightMode; private boolean onlyGraphs; - private boolean recordingTrack = false; private int chartHMargin = 0; public void setChartHMargin(int chartHMargin) { this.chartHMargin = chartHMargin; } - private SelectedGpxFile getCurrentTrack() { - return app.getSavingTrackHelper().getCurrentTrack(); - } - - private GPXFile getGpxFile() { - return recordingTrack ? getCurrentTrack().getGpxFile() : displayHelper.getGpx(); + private boolean isShowCurrentTrack() { + return displayHelper.getGpx() != null && displayHelper.getGpx().showCurrentTrack; } public GPXItemPagerAdapter(@NonNull OsmandApplication app, - boolean nightMode, - @NonNull SegmentActionsListener actionsListener, - boolean onlyGraphs, - boolean recordingTrack) { - super(); - this.app = app; - this.nightMode = nightMode; - this.actionsListener = actionsListener; - this.onlyGraphs = onlyGraphs; - this.recordingTrack = recordingTrack; - iconsCache = app.getUIUtilities(); - - displayHelper = new TrackDisplayHelper(app); - GPXFile gpxFile = getGpxFile(); - if (!getCurrentTrack().isShowCurrentTrack()) { - File file = new File(gpxFile.path); - displayHelper.setFile(file); - displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file)); - } - displayHelper.setGpx(gpxFile); - - updateAnalysis(); - fetchTabTypes(); - } - - public GPXItemPagerAdapter(@NonNull OsmandApplication app, - @NonNull GpxDisplayItem gpxItem, - @NonNull TrackDisplayHelper displayHelper, + @Nullable GpxDisplayItem gpxItem, + @Nullable TrackDisplayHelper displayHelper, boolean nightMode, @NonNull SegmentActionsListener actionsListener, boolean onlyGraphs) { @@ -140,22 +110,36 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid this.app = app; this.gpxItem = gpxItem; this.nightMode = nightMode; - this.displayHelper = displayHelper; this.actionsListener = actionsListener; this.onlyGraphs = onlyGraphs; iconsCache = app.getUIUtilities(); + + if (displayHelper == null) { + this.displayHelper = new TrackDisplayHelper(app); + SelectedGpxFile currentTrack = app.getSavingTrackHelper().getCurrentTrack(); + GPXFile gpxFile = currentTrack.getGpxFile(); + if (currentTrack.isShowCurrentTrack()) { + File file = new File(gpxFile.path); + this.displayHelper.setFile(file); + this.displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file)); + } + this.displayHelper.setGpx(gpxFile); + } else { + this.displayHelper = displayHelper; + } + updateAnalysis(); fetchTabTypes(); } private void updateAnalysis() { analysis = null; - if (recordingTrack) { - GPXFile currentGpx = getCurrentTrack().getGpxFile(); - if (!currentGpx.isEmpty()) { - analysis = currentGpx.getAnalysis(0); + if (isShowCurrentTrack()) { + GPXFile gpxFile = displayHelper.getGpx(); + if (gpxFile != null && !gpxFile.isEmpty()) { + analysis = gpxFile.getAnalysis(0); + gpxItem = GpxUiHelper.makeGpxDisplayItem(app, gpxFile); } - gpxItem = GpxUiHelper.makeGpxDisplayItem(app, currentGpx); } else { if (gpxItem != null) { analysis = gpxItem.analysis; @@ -165,7 +149,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid private void fetchTabTypes() { List tabTypeList = new ArrayList<>(); - if (recordingTrack) { + if (isShowCurrentTrack()) { if (analysis != null && (analysis.hasElevationData || analysis.hasSpeedData)) { tabTypeList.add(GPXTabItemType.GPX_TAB_ITEM_GENERAL); } @@ -187,17 +171,17 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid LineGraphType firstType, LineGraphType secondType) { List dataSets = dataSetsMap.get(tabType); boolean withoutGaps = true; - if (recordingTrack) { - GPXFile currentGpx = getGpxFile(); - withoutGaps = !getCurrentTrack().isJoinSegments() - && (Algorithms.isEmpty(currentGpx.tracks) || currentGpx.tracks.get(0).generalTrack); + if (isShowCurrentTrack()) { + GPXFile gpxFile = displayHelper.getGpx(); + withoutGaps = !app.getSavingTrackHelper().getCurrentTrack().isJoinSegments() && gpxFile != null + && (Algorithms.isEmpty(gpxFile.tracks) || gpxFile.tracks.get(0).generalTrack); } else if (gpxItem != null) { GpxDataItem gpxDataItem = displayHelper.getGpxDataItem(); withoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments(); } if (chart != null && analysis != null) { dataSets = GpxUiHelper.getDataSets(chart, app, analysis, firstType, secondType, withoutGaps); - if (dataSets != null) { + if (!Algorithms.isEmpty(dataSets)) { dataSetsMap.remove(tabType); } dataSetsMap.put(tabType, dataSets); @@ -212,7 +196,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid if (ds != null && ds.size() > 0) { for (GPXUtilities.Track t : gpxItem.group.getGpx().tracks) { for (TrkSegment s : t.segments) { - if (s.points.size() > 0 && s.points.get(0).equals(gpxItem.analysis.locationStart)) { + if (s.points.size() > 0 && s.points.get(0).equals(analysis.locationStart)) { segment = s; break; } @@ -236,7 +220,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) { float time = pos * 1000; for (WptPt p : segment.points) { - if (p.time - gpxItem.analysis.startTime >= time) { + if (p.time - analysis.startTime >= time) { wpt = p; break; } @@ -739,20 +723,21 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid void updateJoinGapsInfo(View view, int position) { if (view != null) { 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); + boolean generalTrack = gpxItem.isGeneralTrack(); boolean joinSegments = displayHelper.isJoinSegments(); + boolean visible = generalTrack && 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(joinSegments); if (analysis != null) { if (tabType.equals(GPXTabItemType.GPX_TAB_ITEM_GENERAL)) { - float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; - float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan; + float totalDistance = !joinSegments && generalTrack ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; + float timeSpan = !joinSegments && generalTrack ? 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(GPX_TAB_ITEM_SPEED)) { - long timeMoving = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeMovingWithoutGaps : analysis.timeMoving; - float totalDistanceMoving = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving; + long timeMoving = !joinSegments && generalTrack ? analysis.timeMovingWithoutGaps : analysis.timeMoving; + float totalDistanceMoving = !joinSegments && generalTrack ? 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)); @@ -777,10 +762,11 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid } public boolean isTabsVisible() { - if (getCount() > 0 && views.size() > 0) { + GPXFile gpxFile = displayHelper.getGpx(); + if (gpxFile != null && getCount() > 0 && views.size() > 0) { for (int i = 0; i < getCount(); i++) { LineChart lc = getViewAtPosition(i).findViewById(R.id.chart); - if (!lc.isEmpty() && !getGpxFile().isEmpty()) { + if (!lc.isEmpty() && !gpxFile.isEmpty()) { return true; } }