fix dynamic updating graphs;

some fixes;
This commit is contained in:
Skalii 2021-03-27 22:51:59 +02:00
parent b114d4956e
commit 7048f8c52d
3 changed files with 139 additions and 94 deletions

View file

@ -48,7 +48,6 @@ import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.myplaces.GPXItemPagerAdapter; import net.osmand.plus.myplaces.GPXItemPagerAdapter;
import net.osmand.plus.myplaces.GPXTabItemType; import net.osmand.plus.myplaces.GPXTabItemType;
@ -94,7 +93,6 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
private View statusContainer; private View statusContainer;
private AppCompatImageView trackAppearanceIcon; private AppCompatImageView trackAppearanceIcon;
private TrackDisplayHelper displayHelper;
private TrackChartPoints trackChartPoints; private TrackChartPoints trackChartPoints;
private GPXItemPagerAdapter graphsAdapter; private GPXItemPagerAdapter graphsAdapter;
private int graphTabPosition = 0; private int graphTabPosition = 0;
@ -157,7 +155,6 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
} }
}); });
setupDisplayHelper();
segmentsTabs = itemView.findViewById(R.id.segments_container); segmentsTabs = itemView.findViewById(R.id.segments_container);
createSegmentsTabs(segmentsTabs); createSegmentsTabs(segmentsTabs);
@ -186,8 +183,10 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
boolean wasTrackMonitored = !wasTrackMonitored(); boolean wasTrackMonitored = !wasTrackMonitored();
if (!wasTrackMonitored) { if (!wasTrackMonitored) {
blockStatisticsBuilder.stopUpdatingStatBlocks(); blockStatisticsBuilder.stopUpdatingStatBlocks();
stopUpdatingGraph();
} else { } else {
blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded(); blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded();
runUpdatingGraph();
} }
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored); settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored);
updateStatus(); updateStatus();
@ -256,10 +255,8 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
updateTrackIcon(app, trackAppearanceIcon); updateTrackIcon(app, trackAppearanceIcon);
} }
if (key.equals(UPDATE_DYNAMIC_ITEMS)) { if (key.equals(UPDATE_DYNAMIC_ITEMS)) {
blockStatisticsBuilder.stopUpdatingStatBlocks(); blockStatisticsBuilder.restartUpdatingStatBlocks();
blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded(); restartUpdatingGraph();
stopUpdatingGraph();
runUpdatingGraph();
} }
} }
} }
@ -271,11 +268,11 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
} }
} }
public void stopUpdatingGPS() { private void stopUpdatingGPS() {
handler.removeCallbacks(updatingGPS); handler.removeCallbacks(updatingGPS);
} }
public void runUpdatingGPS() { private void runUpdatingGPS() {
updatingGPS = new Runnable() { updatingGPS = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -287,38 +284,30 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
handler.post(updatingGPS); handler.post(updatingGPS);
} }
public void stopUpdatingGraph() { private void stopUpdatingGraph() {
handler.removeCallbacks(updatingGraph); handler.removeCallbacks(updatingGraph);
} }
public void runUpdatingGraph() { private void runUpdatingGraph() {
updatingGraph = new Runnable() { updatingGraph = new Runnable() {
@Override @Override
public void run() { public void run() {
int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get();
graphsAdapter.setGpxItem(GpxUiHelper.makeGpxDisplayItem(app, displayHelper.getGpx()));
graphsAdapter.fetchTabTypesIfNeeded(INIT_TAB_ITEMS);
graphsAdapter.updateGraph(graphTabPosition); graphsAdapter.updateGraph(graphTabPosition);
AndroidUiHelper.updateVisibility(segmentsTabs, graphsAdapter.isVisible()); AndroidUiHelper.updateVisibility(segmentsTabs, graphsAdapter.isTabsVisible());
handler.postDelayed(this, Math.max(GPS_UPDATE_INTERVAL, interval)); handler.postDelayed(this, Math.max(GPS_UPDATE_INTERVAL, interval));
} }
}; };
handler.post(updatingGraph); handler.post(updatingGraph);
} }
private void setupDisplayHelper() { private void restartUpdatingGraph() {
displayHelper = new TrackDisplayHelper(app); stopUpdatingGraph();
GPXFile gpxFile = getGPXFile(); runUpdatingGraph();
if (!selectedGpxFile.isShowCurrentTrack()) {
File file = new File(gpxFile.path);
displayHelper.setFile(file);
displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file));
}
displayHelper.setGpx(gpxFile);
} }
private void createSegmentsTabs(ViewGroup viewGroup) { private void createSegmentsTabs(ViewGroup viewGroup) {
View segmentView = SegmentGPXAdapter.createGpxTabsView(displayHelper, viewGroup, this, nightMode); View segmentView = SegmentGPXAdapter.createGpxTabsView(null, viewGroup, this, nightMode);
AndroidUiHelper.setVisibility(View.GONE, segmentView.findViewById(R.id.list_item_divider)); AndroidUiHelper.setVisibility(View.GONE, segmentView.findViewById(R.id.list_item_divider));
WrapContentHeightViewPager pager = segmentView.findViewById(R.id.pager); WrapContentHeightViewPager pager = segmentView.findViewById(R.id.pager);
PagerSlidingTabStrip tabLayout = segmentView.findViewById(R.id.sliding_tabs); PagerSlidingTabStrip tabLayout = segmentView.findViewById(R.id.sliding_tabs);
@ -330,6 +319,7 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
public void onTabSelected(int position) { public void onTabSelected(int position) {
graphTabPosition = position; graphTabPosition = position;
blockStatisticsBuilder.setTabItem(INIT_TAB_ITEMS[graphTabPosition]); blockStatisticsBuilder.setTabItem(INIT_TAB_ITEMS[graphTabPosition]);
blockStatisticsBuilder.restartUpdatingStatBlocks();
} }
@Override @Override
@ -339,8 +329,7 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
} }
}); });
graphsAdapter = new GPXItemPagerAdapter(app, GpxUiHelper.makeGpxDisplayItem(app, displayHelper.getGpx()), graphsAdapter = new GPXItemPagerAdapter(app, nightMode, this, true, true);
displayHelper, nightMode, this, true);
graphsAdapter.setChartHMargin(getResources().getDimensionPixelSize(R.dimen.content_padding)); graphsAdapter.setChartHMargin(getResources().getDimensionPixelSize(R.dimen.content_padding));
pager.setAdapter(graphsAdapter); pager.setAdapter(graphsAdapter);
@ -618,11 +607,23 @@ 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 @Override
public void onPointSelected(TrkSegment segment, double lat, double lon) { public void onPointSelected(TrkSegment segment, double lat, double lon) {
if (trackChartPoints == null) { if (trackChartPoints == null) {
trackChartPoints = new TrackChartPoints(); trackChartPoints = new TrackChartPoints();
trackChartPoints.setGpx(displayHelper.getGpx()); trackChartPoints.setGpx(getDisplayHelper().getGpx());
} }
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {

View file

@ -39,7 +39,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.CustomRadioButtonType; import net.osmand.plus.UiUtilities.CustomRadioButtonType;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType;
@ -52,8 +51,7 @@ import net.osmand.plus.views.controls.WrapContentHeightViewPager.ViewAtPositionI
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.lang3.ArrayUtils; import java.io.File;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -82,6 +80,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
private WptPt selectedWpt; private WptPt selectedWpt;
private TrkSegment segment; private TrkSegment segment;
private GpxDisplayItem gpxItem; private GpxDisplayItem gpxItem;
private GPXTrackAnalysis analysis;
private GPXTabItemType[] tabTypes; private GPXTabItemType[] tabTypes;
private SparseArray<View> views = new SparseArray<>(); private SparseArray<View> views = new SparseArray<>();
@ -90,14 +89,45 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
private boolean chartClicked; private boolean chartClicked;
private boolean nightMode; private boolean nightMode;
private boolean onlyGraphs; private boolean onlyGraphs;
private boolean recordingTrack = false;
private int chartHMargin = 0; private int chartHMargin = 0;
public void setChartHMargin(int chartHMargin) { public void setChartHMargin(int chartHMargin) {
this.chartHMargin = chartHMargin; this.chartHMargin = chartHMargin;
} }
public void setGpxItem(GpxDisplayItem gpxItem) { private SelectedGpxFile getCurrentTrack() {
this.gpxItem = gpxItem; return app.getSavingTrackHelper().getCurrentTrack();
}
private GPXFile getGpxFile() {
return recordingTrack ? getCurrentTrack().getGpxFile() : displayHelper.getGpx();
}
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, public GPXItemPagerAdapter(@NonNull OsmandApplication app,
@ -114,17 +144,39 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
this.actionsListener = actionsListener; this.actionsListener = actionsListener;
this.onlyGraphs = onlyGraphs; this.onlyGraphs = onlyGraphs;
iconsCache = app.getUIUtilities(); iconsCache = app.getUIUtilities();
updateAnalysis();
fetchTabTypes(); fetchTabTypes();
} }
private void updateAnalysis() {
analysis = null;
if (recordingTrack) {
GPXFile currentGpx = getCurrentTrack().getGpxFile();
if (!currentGpx.isEmpty()) {
analysis = currentGpx.getAnalysis(0);
}
gpxItem = GpxUiHelper.makeGpxDisplayItem(app, currentGpx);
} else {
if (gpxItem != null) {
analysis = gpxItem.analysis;
}
}
}
private void fetchTabTypes() { private void fetchTabTypes() {
List<GPXTabItemType> tabTypeList = new ArrayList<>(); List<GPXTabItemType> tabTypeList = new ArrayList<>();
tabTypeList.add(GPXTabItemType.GPX_TAB_ITEM_GENERAL); if (recordingTrack) {
if (gpxItem != null && gpxItem.analysis != null) { if (analysis != null && (analysis.hasElevationData || analysis.hasSpeedData)) {
if (gpxItem.analysis.hasElevationData) { tabTypeList.add(GPXTabItemType.GPX_TAB_ITEM_GENERAL);
}
} else {
tabTypeList.add(GPXTabItemType.GPX_TAB_ITEM_GENERAL);
}
if (analysis != null) {
if (analysis.hasElevationData) {
tabTypeList.add(GPX_TAB_ITEM_ALTITUDE); tabTypeList.add(GPX_TAB_ITEM_ALTITUDE);
} }
if (gpxItem.analysis.isSpeedSpecified()) { if (analysis.isSpeedSpecified()) {
tabTypeList.add(GPX_TAB_ITEM_SPEED); tabTypeList.add(GPX_TAB_ITEM_SPEED);
} }
} }
@ -134,17 +186,12 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
private List<ILineDataSet> getDataSets(LineChart chart, GPXTabItemType tabType, private List<ILineDataSet> getDataSets(LineChart chart, GPXTabItemType tabType,
LineGraphType firstType, LineGraphType secondType) { LineGraphType firstType, LineGraphType secondType) {
List<ILineDataSet> dataSets = dataSetsMap.get(tabType); List<ILineDataSet> dataSets = dataSetsMap.get(tabType);
GPXTrackAnalysis analysis = null;
boolean withoutGaps = true; boolean withoutGaps = true;
SavingTrackHelper helper = app.getSavingTrackHelper(); if (recordingTrack) {
if (displayHelper.getGpx().equals(helper.getCurrentGpx())) { GPXFile currentGpx = getGpxFile();
SelectedGpxFile selectedGpxFile = helper.getCurrentTrack(); withoutGaps = !getCurrentTrack().isJoinSegments()
GPXFile currentGpx = selectedGpxFile.getGpxFile();
analysis = currentGpx.getAnalysis(0);
withoutGaps = !selectedGpxFile.isJoinSegments()
&& (Algorithms.isEmpty(currentGpx.tracks) || currentGpx.tracks.get(0).generalTrack); && (Algorithms.isEmpty(currentGpx.tracks) || currentGpx.tracks.get(0).generalTrack);
} else if (gpxItem != null) { } else if (gpxItem != null) {
analysis = gpxItem.analysis;
GpxDataItem gpxDataItem = displayHelper.getGpxDataItem(); GpxDataItem gpxDataItem = displayHelper.getGpxDataItem();
withoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments(); withoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments();
} }
@ -231,20 +278,17 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
LineChart chart = view.findViewById(R.id.chart); LineChart chart = view.findViewById(R.id.chart);
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) chart.getLayoutParams(); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) chart.getLayoutParams();
AndroidUtils.setMargins(lp, chartHMargin, lp.topMargin, chartHMargin, lp.bottomMargin); AndroidUtils.setMargins(lp, chartHMargin, lp.topMargin, chartHMargin, lp.bottomMargin);
GPXFile gpxFile = displayHelper.getGpx(); if (analysis != null) {
if (gpxFile != null && gpxItem != null) {
GPXTrackAnalysis analysis = gpxItem.analysis;
setupChart(view, chart); setupChart(view, chart);
switch (tabType) { switch (tabType) {
case GPX_TAB_ITEM_GENERAL: case GPX_TAB_ITEM_GENERAL:
setupGeneralTab(view, chart, analysis, gpxFile, position); setupGeneralTab(view, chart, position);
break; break;
case GPX_TAB_ITEM_ALTITUDE: case GPX_TAB_ITEM_ALTITUDE:
setupAltitudeTab(view, chart, analysis, gpxFile, position); setupAltitudeTab(view, chart, position);
break; break;
case GPX_TAB_ITEM_SPEED: case GPX_TAB_ITEM_SPEED:
setupSpeedTab(view, chart, analysis, gpxFile, position); setupSpeedTab(view, chart, position);
break; break;
} }
} }
@ -277,7 +321,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
return view; return view;
} }
private void setupSpeedTab(View view, LineChart chart, GPXTrackAnalysis analysis, GPXFile gpxFile, int position) { private void setupSpeedTab(View view, LineChart chart, int position) {
if (analysis != null && analysis.isSpeedSpecified()) { if (analysis != null && analysis.isSpeedSpecified()) {
if (analysis.hasSpeedData) { if (analysis.hasSpeedData) {
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT); GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
@ -349,7 +393,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
}); });
} }
private void setupAltitudeTab(View view, LineChart chart, GPXTrackAnalysis analysis, GPXFile gpxFile, int position) { private void setupAltitudeTab(View view, LineChart chart, int position) {
if (analysis != null) { if (analysis != null) {
if (analysis.hasElevationData) { if (analysis.hasElevationData) {
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT); GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
@ -416,7 +460,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
} }
} }
private void setupGeneralTab(View view, LineChart chart, GPXTrackAnalysis analysis, GPXFile gpxFile, int position) { private void setupGeneralTab(View view, LineChart chart, int position) {
if (analysis != null) { if (analysis != null) {
if (analysis.hasElevationData || analysis.hasSpeedData) { if (analysis.hasElevationData || analysis.hasSpeedData) {
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT); GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
@ -657,10 +701,12 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
@Override @Override
public void tabStylesUpdated(View tabsContainer, int currentPosition) { public void tabStylesUpdated(View tabsContainer, int currentPosition) {
ViewGroup.MarginLayoutParams params = (MarginLayoutParams) tabsContainer.getLayoutParams(); if (getCount() > 0) {
params.height = app.getResources().getDimensionPixelSize(!onlyGraphs ? R.dimen.dialog_button_height : R.dimen.context_menu_buttons_bottom_height); ViewGroup.MarginLayoutParams params = (MarginLayoutParams) tabsContainer.getLayoutParams();
tabsContainer.setLayoutParams(params); params.height = app.getResources().getDimensionPixelSize(!onlyGraphs ? R.dimen.dialog_button_height : R.dimen.context_menu_buttons_bottom_height);
UiUtilities.updateCustomRadioButtons(app, tabsContainer, nightMode, getCustomRadioButtonType(currentPosition)); tabsContainer.setLayoutParams(params);
UiUtilities.updateCustomRadioButtons(app, tabsContainer, nightMode, getCustomRadioButtonType(currentPosition));
}
} }
private CustomRadioButtonType getCustomRadioButtonType(int index) { private CustomRadioButtonType getCustomRadioButtonType(int index) {
@ -692,7 +738,6 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
void updateJoinGapsInfo(View view, int position) { void updateJoinGapsInfo(View view, int position) {
if (view != null) { if (view != null) {
GPXTrackAnalysis analysis = gpxItem.analysis;
GPXTabItemType tabType = tabTypes[position]; GPXTabItemType tabType = tabTypes[position];
boolean visible = gpxItem.isGeneralTrack() && analysis != null && tabType.equals(GPXTabItemType.GPX_TAB_ITEM_GENERAL); boolean visible = gpxItem.isGeneralTrack() && analysis != null && tabType.equals(GPXTabItemType.GPX_TAB_ITEM_GENERAL);
AndroidUiHelper.updateVisibility(view.findViewById(R.id.gpx_join_gaps_container), visible); AndroidUiHelper.updateVisibility(view.findViewById(R.id.gpx_join_gaps_container), visible);
@ -731,50 +776,44 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
} }
} }
public boolean isVisible() { public boolean isTabsVisible() {
for (int i = 0; i < views.size(); i++) { if (getCount() > 0 && views.size() > 0) {
if (views.get(i).findViewById(R.id.chart).getVisibility() == View.VISIBLE) { for (int i = 0; i < getCount(); i++) {
if (tabTypes[i] == GPX_TAB_ITEM_GENERAL && (gpxItem == null || gpxItem.analysis == null)) { LineChart lc = getViewAtPosition(i).findViewById(R.id.chart);
return false; if (!lc.isEmpty() && !getGpxFile().isEmpty()) {
return true;
} }
return true;
} }
} }
return false; return false;
} }
public void updateGraph(int position) { public void updateGraph(int position) {
LineGraphType firstType = tabTypes[position] == GPX_TAB_ITEM_SPEED ? SPEED : ALTITUDE; updateAnalysis();
LineGraphType secondType = null; fetchTabTypes();
if (tabTypes[position] == GPX_TAB_ITEM_ALTITUDE) { if (getCount() > 0 && views.size() > 0) {
secondType = SLOPE; LineGraphType firstType = tabTypes[position] == GPX_TAB_ITEM_SPEED ? SPEED : ALTITUDE;
} else if (tabTypes[position] == GPX_TAB_ITEM_GENERAL) { LineGraphType secondType = null;
secondType = SPEED; if (tabTypes[position] == GPX_TAB_ITEM_ALTITUDE) {
} secondType = SLOPE;
} else if (tabTypes[position] == GPX_TAB_ITEM_GENERAL) {
LineChart chart = getViewAtPosition(position).findViewById(R.id.chart); secondType = SPEED;
List<ILineDataSet> dataSets = getDataSets(chart, tabTypes[position], firstType, secondType);
boolean isEmptyDataSets = Algorithms.isEmpty(dataSets);
AndroidUiHelper.updateVisibility(chart, !isEmptyDataSets);
chart.clear();
if (!isEmptyDataSets) {
chart.setData(new LineData(dataSets));
}
if (chart.getAxisRight().getLabelCount() != CHART_LABEL_COUNT
|| chart.getAxisLeft().getLabelCount() != CHART_LABEL_COUNT) {
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
}
updateChart(chart);
notifyDataSetChanged();
}
public void fetchTabTypesIfNeeded(GPXTabItemType[] tabTypes) {
if (!ArrayUtils.isEquals(this.tabTypes, tabTypes)) {
fetchTabTypes();
for (int i = 0; i < this.tabTypes.length; i++) {
updateGraph(i);
} }
LineChart chart = getViewAtPosition(position).findViewById(R.id.chart);
List<ILineDataSet> dataSets = getDataSets(chart, tabTypes[position], firstType, secondType);
boolean isEmptyDataSets = Algorithms.isEmpty(dataSets);
AndroidUiHelper.updateVisibility(chart, !isEmptyDataSets);
chart.clear();
if (!isEmptyDataSets) {
chart.setData(new LineData(dataSets));
}
if (chart.getAxisRight().getLabelCount() != CHART_LABEL_COUNT
|| chart.getAxisLeft().getLabelCount() != CHART_LABEL_COUNT) {
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
}
updateChart(chart);
} }
notifyDataSetChanged();
} }
private TrkSegment getTrkSegment() { private TrkSegment getTrkSegment() {

View file

@ -131,6 +131,11 @@ public class GpxBlockStatisticsBuilder {
} }
} }
public void restartUpdatingStatBlocks() {
stopUpdatingStatBlocks();
runUpdatingStatBlocksIfNeeded();
}
public void initItems() { public void initItems() {
GPXFile gpxFile = getGPXFile(); GPXFile gpxFile = getGPXFile();
if (app == null || gpxFile == null) { if (app == null || gpxFile == null) {