add dynamic update for charts
This commit is contained in:
parent
2277d6c4ea
commit
4038f430c5
5 changed files with 190 additions and 94 deletions
|
@ -49,6 +49,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
|
|||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
|
||||
import net.osmand.plus.myplaces.GPXItemPagerAdapter;
|
||||
import net.osmand.plus.myplaces.GPXTabItemType;
|
||||
import net.osmand.plus.myplaces.SegmentActionsListener;
|
||||
import net.osmand.plus.myplaces.SegmentGPXAdapter;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
|
@ -69,18 +70,19 @@ import java.util.List;
|
|||
import static net.osmand.AndroidUtils.getSecondaryTextColorId;
|
||||
import static net.osmand.AndroidUtils.setPadding;
|
||||
import static net.osmand.plus.UiUtilities.CompoundButtonType.GLOBAL;
|
||||
import static net.osmand.plus.track.GpxBlockStatisticsBuilder.INIT_BLOCKS_ALTITUDE;
|
||||
import static net.osmand.plus.track.GpxBlockStatisticsBuilder.INIT_BLOCKS_GENERAL;
|
||||
import static net.osmand.plus.track.GpxBlockStatisticsBuilder.INIT_BLOCKS_SPEED;
|
||||
import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_ALTITUDE;
|
||||
import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_GENERAL;
|
||||
import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_SPEED;
|
||||
|
||||
public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment implements SegmentActionsListener {
|
||||
|
||||
public static final String TAG = TripRecordingBottomSheet.class.getSimpleName();
|
||||
private static final Log LOG = PlatformUtil.getLog(TripRecordingBottomSheet.class);
|
||||
public static final String UPDATE_TRACK_ICON = "update_track_icon";
|
||||
public static final String UPDATE_DYNAMIC_ITEMS = "update_dynamic_items";
|
||||
private static final int GPS_UPDATE_INTERVAL = 1000;
|
||||
private static final String[] INIT_BLOCKS_KEYS =
|
||||
new String[]{INIT_BLOCKS_GENERAL, INIT_BLOCKS_ALTITUDE, INIT_BLOCKS_SPEED};
|
||||
public static final GPXTabItemType[] INIT_TAB_ITEMS =
|
||||
new GPXTabItemType[]{GPX_TAB_ITEM_GENERAL, GPX_TAB_ITEM_ALTITUDE, GPX_TAB_ITEM_SPEED};
|
||||
|
||||
private OsmandApplication app;
|
||||
private OsmandSettings settings;
|
||||
|
@ -89,16 +91,18 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
|
|||
|
||||
private View statusContainer;
|
||||
private AppCompatImageView trackAppearanceIcon;
|
||||
private LinearLayout segmentsContainer;
|
||||
|
||||
private TrackDisplayHelper displayHelper;
|
||||
private TrackChartPoints trackChartPoints;
|
||||
private GPXItemPagerAdapter graphsAdapter;
|
||||
private int graphTabPosition = 0;
|
||||
private ViewGroup segmentsTabs;
|
||||
|
||||
private GpxBlockStatisticsBuilder blockStatisticsBuilder;
|
||||
private SelectedGpxFile selectedGpxFile;
|
||||
private final Handler handler = new Handler();
|
||||
private Runnable updatingGPS;
|
||||
private Runnable updatingGraph;
|
||||
|
||||
private GPXFile getGPXFile() {
|
||||
return selectedGpxFile.getGpxFile();
|
||||
|
@ -151,14 +155,15 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
|
|||
}
|
||||
});
|
||||
|
||||
segmentsContainer = itemView.findViewById(R.id.segments_container);
|
||||
createSegmentsTabs(segmentsContainer);
|
||||
setupDisplayHelper();
|
||||
segmentsTabs = itemView.findViewById(R.id.segments_container);
|
||||
createSegmentsTabs(segmentsTabs);
|
||||
|
||||
RecyclerView statBlocks = itemView.findViewById(R.id.block_statistics);
|
||||
blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile, nightMode);
|
||||
blockStatisticsBuilder.setBlocksView(statBlocks);
|
||||
blockStatisticsBuilder.setBlocksClickable(false);
|
||||
blockStatisticsBuilder.setInitBlocksKey(INIT_BLOCKS_GENERAL);
|
||||
blockStatisticsBuilder.setTabItem(GPX_TAB_ITEM_GENERAL);
|
||||
blockStatisticsBuilder.initStatBlocks(null,
|
||||
ContextCompat.getColor(app, getActiveTextColorId(nightMode)));
|
||||
|
||||
|
@ -220,6 +225,7 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
|
|||
super.onResume();
|
||||
blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded();
|
||||
runUpdatingGPS();
|
||||
runUpdatingGraph();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints);
|
||||
|
@ -231,25 +237,28 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
|
|||
super.onPause();
|
||||
blockStatisticsBuilder.stopUpdatingStatBlocks();
|
||||
stopUpdatingGPS();
|
||||
stopUpdatingGraph();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
public void show(String... keys) {
|
||||
Dialog dialog = getDialog();
|
||||
if (dialog != null) {
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void show(String... keys) {
|
||||
show();
|
||||
for (String key : keys) {
|
||||
if (key.equals(UPDATE_TRACK_ICON)) {
|
||||
updateTrackIcon(app, trackAppearanceIcon);
|
||||
}
|
||||
if (key.equals(UPDATE_DYNAMIC_ITEMS)) {
|
||||
blockStatisticsBuilder.stopUpdatingStatBlocks();
|
||||
blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded();
|
||||
stopUpdatingGraph();
|
||||
runUpdatingGraph();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,26 +285,37 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
|
|||
handler.post(updatingGPS);
|
||||
}
|
||||
|
||||
private void recreateStatBlocks(String initBlocksKey) {
|
||||
blockStatisticsBuilder.stopUpdatingStatBlocks();
|
||||
blockStatisticsBuilder.setInitBlocksKey(initBlocksKey);
|
||||
blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded();
|
||||
public void stopUpdatingGraph() {
|
||||
handler.removeCallbacks(updatingGraph);
|
||||
}
|
||||
|
||||
public void runUpdatingGraph() {
|
||||
updatingGraph = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get();
|
||||
graphsAdapter.setGpxItem(GpxUiHelper.makeGpxDisplayItem(app, displayHelper.getGpx()));
|
||||
graphsAdapter.fetchTabTypesIfNeeded(INIT_TAB_ITEMS);
|
||||
graphsAdapter.updateGraph(graphTabPosition);
|
||||
AndroidUiHelper.updateVisibility(segmentsTabs, graphsAdapter.isVisible());
|
||||
handler.postDelayed(this, Math.max(GPS_UPDATE_INTERVAL, interval));
|
||||
}
|
||||
};
|
||||
handler.post(updatingGraph);
|
||||
}
|
||||
|
||||
private void setupDisplayHelper() {
|
||||
displayHelper = new TrackDisplayHelper(app);
|
||||
GPXFile gpxFile = getGPXFile();
|
||||
if (!selectedGpxFile.isShowCurrentTrack()) {
|
||||
File file = new File(getGPXFile().path);
|
||||
File file = new File(gpxFile.path);
|
||||
displayHelper.setFile(file);
|
||||
displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file));
|
||||
}
|
||||
displayHelper.setGpx(getGPXFile());
|
||||
displayHelper.setGpx(gpxFile);
|
||||
}
|
||||
|
||||
private void createSegmentsTabs(ViewGroup viewGroup) {
|
||||
viewGroup.removeAllViews();
|
||||
setupDisplayHelper();
|
||||
|
||||
View segmentView = SegmentGPXAdapter.createGpxTabsView(displayHelper, viewGroup, this, nightMode);
|
||||
AndroidUiHelper.setVisibility(View.GONE, segmentView.findViewById(R.id.list_item_divider));
|
||||
WrapContentHeightViewPager pager = segmentView.findViewById(R.id.pager);
|
||||
|
@ -303,17 +323,19 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
|
|||
tabLayout.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(int position) {
|
||||
recreateStatBlocks(INIT_BLOCKS_KEYS[position]);
|
||||
graphTabPosition = position;
|
||||
blockStatisticsBuilder.setTabItem(INIT_TAB_ITEMS[graphTabPosition]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(int position) {
|
||||
recreateStatBlocks(INIT_BLOCKS_KEYS[position]);
|
||||
graphTabPosition = position;
|
||||
blockStatisticsBuilder.setTabItem(INIT_TAB_ITEMS[graphTabPosition]);
|
||||
}
|
||||
});
|
||||
|
||||
graphsAdapter = new GPXItemPagerAdapter(app, GpxUiHelper.makeGpxDisplayItem(app,
|
||||
displayHelper.getGpx()), displayHelper, nightMode, this, true);
|
||||
graphsAdapter = new GPXItemPagerAdapter(app, GpxUiHelper.makeGpxDisplayItem(app, displayHelper.getGpx()),
|
||||
displayHelper, nightMode, this, true);
|
||||
|
||||
pager.setAdapter(graphsAdapter);
|
||||
tabLayout.setViewPager(pager);
|
||||
|
|
|
@ -18,6 +18,7 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
||||
import static net.osmand.plus.monitoring.TripRecordingOptionsBottomSheet.ACTION_CLEAR_DATA;
|
||||
|
||||
public class TripRecordingClearDataBottomSheet extends MenuBottomSheetDialogFragment implements TripRecordingBottomSheet.DismissTargetFragment {
|
||||
|
||||
|
@ -110,6 +111,9 @@ 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) {
|
||||
((TripRecordingOptionsBottomSheet) target).dismiss();
|
||||
}
|
||||
|
|
|
@ -34,11 +34,13 @@ import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
|||
import net.osmand.util.Algorithms;
|
||||
|
||||
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
||||
import static net.osmand.plus.monitoring.TripRecordingBottomSheet.UPDATE_DYNAMIC_ITEMS;
|
||||
|
||||
public class TripRecordingOptionsBottomSheet extends MenuBottomSheetDialogFragment implements TripRecordingBottomSheet.DismissTargetFragment {
|
||||
|
||||
public static final String TAG = TripRecordingOptionsBottomSheet.class.getSimpleName();
|
||||
public static final String ACTION_STOP_AND_DISMISS = "action_stop_and_discard";
|
||||
public static final String ACTION_CLEAR_DATA = "action_clear_data";
|
||||
private static final int SAVE_UPDATE_INTERVAL = 1000;
|
||||
|
||||
private OsmandApplication app;
|
||||
|
@ -283,12 +285,22 @@ public class TripRecordingOptionsBottomSheet extends MenuBottomSheetDialogFragme
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean isCleared() {
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
return args.getBoolean(ACTION_CLEAR_DATA);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissTarget() {
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof TripRecordingBottomSheet) {
|
||||
if (isDiscard()) {
|
||||
((TripRecordingBottomSheet) target).dismiss();
|
||||
} else if (isCleared()) {
|
||||
((TripRecordingBottomSheet) target).show(UPDATE_DYNAMIC_ITEMS);
|
||||
} else {
|
||||
((TripRecordingBottomSheet) target).show();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ import net.osmand.plus.views.controls.WrapContentHeightViewPager.ViewAtPositionI
|
|||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -62,10 +64,13 @@ import static net.osmand.plus.helpers.GpxUiHelper.LineGraphType.ALTITUDE;
|
|||
import static net.osmand.plus.helpers.GpxUiHelper.LineGraphType.SLOPE;
|
||||
import static net.osmand.plus.helpers.GpxUiHelper.LineGraphType.SPEED;
|
||||
import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_ALTITUDE;
|
||||
import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_GENERAL;
|
||||
import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_SPEED;
|
||||
|
||||
public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvider, ViewAtPositionInterface {
|
||||
|
||||
private static final int CHART_LABEL_COUNT = 4;
|
||||
|
||||
private OsmandApplication app;
|
||||
private UiUtilities iconsCache;
|
||||
private TrackDisplayHelper displayHelper;
|
||||
|
@ -83,6 +88,10 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
|
|||
private boolean nightMode;
|
||||
private boolean onlyGraphs;
|
||||
|
||||
public void setGpxItem(GpxDisplayItem gpxItem) {
|
||||
this.gpxItem = gpxItem;
|
||||
}
|
||||
|
||||
public GPXItemPagerAdapter(@NonNull OsmandApplication app,
|
||||
@NonNull GpxDisplayItem gpxItem,
|
||||
@NonNull TrackDisplayHelper displayHelper,
|
||||
|
@ -117,12 +126,17 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
|
|||
private List<ILineDataSet> getDataSets(LineChart chart, GPXTabItemType tabType,
|
||||
LineGraphType firstType, LineGraphType secondType) {
|
||||
List<ILineDataSet> dataSets = dataSetsMap.get(tabType);
|
||||
if (dataSets == null && chart != null) {
|
||||
if (gpxItem != null) {
|
||||
GPXTrackAnalysis analysis = gpxItem.analysis;
|
||||
GpxDataItem gpxDataItem = displayHelper.getGpxDataItem();
|
||||
boolean calcWithoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments();
|
||||
dataSets = GpxUiHelper.getDataSets(chart, app, analysis, firstType, secondType, calcWithoutGaps);
|
||||
dataSetsMap.put(tabType, dataSets);
|
||||
if (chart != null) {
|
||||
dataSets = GpxUiHelper.getDataSets(chart, app, analysis, firstType, secondType, calcWithoutGaps);
|
||||
if (dataSets != null) {
|
||||
dataSetsMap.remove(tabType);
|
||||
}
|
||||
dataSetsMap.put(tabType, dataSets);
|
||||
}
|
||||
}
|
||||
return dataSets;
|
||||
}
|
||||
|
@ -247,7 +261,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
|
|||
private void setupSpeedTab(View view, LineChart chart, GPXTrackAnalysis analysis, GPXFile gpxFile, int position) {
|
||||
if (analysis != null && analysis.isSpeedSpecified()) {
|
||||
if (analysis.hasSpeedData) {
|
||||
GpxUiHelper.setupGPXChart(app, chart, 4);
|
||||
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
|
||||
chart.setData(new LineData(getDataSets(chart, GPX_TAB_ITEM_SPEED, SPEED, null)));
|
||||
updateChart(chart);
|
||||
chart.setVisibility(View.VISIBLE);
|
||||
|
@ -319,7 +333,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
|
|||
private void setupAltitudeTab(View view, LineChart chart, GPXTrackAnalysis analysis, GPXFile gpxFile, int position) {
|
||||
if (analysis != null) {
|
||||
if (analysis.hasElevationData) {
|
||||
GpxUiHelper.setupGPXChart(app, chart, 4);
|
||||
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
|
||||
chart.setData(new LineData(getDataSets(chart, GPX_TAB_ITEM_ALTITUDE, ALTITUDE, SLOPE)));
|
||||
updateChart(chart);
|
||||
chart.setVisibility(View.VISIBLE);
|
||||
|
@ -386,7 +400,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
|
|||
private void setupGeneralTab(View view, LineChart chart, GPXTrackAnalysis analysis, GPXFile gpxFile, int position) {
|
||||
if (analysis != null) {
|
||||
if (analysis.hasElevationData || analysis.hasSpeedData) {
|
||||
GpxUiHelper.setupGPXChart(app, chart, 4);
|
||||
GpxUiHelper.setupGPXChart(app, chart, CHART_LABEL_COUNT);
|
||||
chart.setData(new LineData(getDataSets(chart, GPXTabItemType.GPX_TAB_ITEM_GENERAL, ALTITUDE, SPEED)));
|
||||
updateChart(chart);
|
||||
chart.setVisibility(View.VISIBLE);
|
||||
|
@ -685,17 +699,65 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
|
|||
|
||||
void updateChart(LineChart chart) {
|
||||
if (chart != null && !chart.isEmpty()) {
|
||||
if (gpxItem.chartMatrix != null) {
|
||||
chart.getViewPortHandler().refresh(new Matrix(gpxItem.chartMatrix), chart, true);
|
||||
}
|
||||
if (gpxItem.chartHighlightPos != -1) {
|
||||
chart.highlightValue(gpxItem.chartHighlightPos, 0);
|
||||
if (gpxItem != null) {
|
||||
if (gpxItem.chartMatrix != null) {
|
||||
chart.getViewPortHandler().refresh(new Matrix(gpxItem.chartMatrix), chart, true);
|
||||
}
|
||||
if (gpxItem.chartHighlightPos != -1) {
|
||||
chart.highlightValue(gpxItem.chartHighlightPos, 0);
|
||||
}
|
||||
} else {
|
||||
chart.highlightValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
for (int i = 0; i < views.size(); i++) {
|
||||
if (views.get(i).findViewById(R.id.chart).getVisibility() == View.VISIBLE) {
|
||||
if (tabTypes[i] == GPX_TAB_ITEM_GENERAL && (gpxItem == null || gpxItem.analysis == null)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateGraph(int position) {
|
||||
LineGraphType firstType = tabTypes[position] == GPX_TAB_ITEM_SPEED ? SPEED : ALTITUDE;
|
||||
LineGraphType secondType = null;
|
||||
if (tabTypes[position] == GPX_TAB_ITEM_ALTITUDE) {
|
||||
secondType = SLOPE;
|
||||
} else if (tabTypes[position] == GPX_TAB_ITEM_GENERAL) {
|
||||
secondType = SPEED;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public void fetchTabTypesIfNeeded(GPXTabItemType[] tabTypes) {
|
||||
if (!ArrayUtils.isEquals(this.tabTypes, tabTypes)) {
|
||||
fetchTabTypes();
|
||||
for (int i = 0; i < this.tabTypes.length; i++) {
|
||||
updateGraph(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TrkSegment getTrkSegment() {
|
||||
for (Track track : gpxItem.group.getGpx().tracks) {
|
||||
if (!track.generalTrack && !gpxItem.isGeneralTrack() || track.generalTrack && gpxItem.isGeneralTrack()) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
||||
import net.osmand.plus.myplaces.GPXTabItemType;
|
||||
import net.osmand.plus.myplaces.SegmentActionsListener;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -49,10 +50,6 @@ public class GpxBlockStatisticsBuilder {
|
|||
|
||||
private static final Log LOG = PlatformUtil.getLog(GpxBlockStatisticsBuilder.class);
|
||||
private static final int BLOCKS_UPDATE_INTERVAL = 1000;
|
||||
public static final String INIT_BLOCKS_BASE = "init_blocks_base";
|
||||
public static final String INIT_BLOCKS_GENERAL = "init_blocks_general";
|
||||
public static final String INIT_BLOCKS_ALTITUDE = "init_blocks_altitude";
|
||||
public static final String INIT_BLOCKS_SPEED = "init_blocks_speed";
|
||||
|
||||
private final OsmandApplication app;
|
||||
private final boolean nightMode;
|
||||
|
@ -64,7 +61,7 @@ public class GpxBlockStatisticsBuilder {
|
|||
private BlockStatisticsAdapter adapter;
|
||||
private final List<StatBlock> items = new ArrayList<>();
|
||||
private boolean blocksClickable = true;
|
||||
private String initBlocksKey = INIT_BLOCKS_BASE;
|
||||
private GPXTabItemType tabItem = null;
|
||||
|
||||
private final Handler handler = new Handler();
|
||||
private Runnable updatingItems;
|
||||
|
@ -88,8 +85,8 @@ public class GpxBlockStatisticsBuilder {
|
|||
this.blocksView = blocksView;
|
||||
}
|
||||
|
||||
public void setInitBlocksKey(String initBlocksKey) {
|
||||
this.initBlocksKey = initBlocksKey;
|
||||
public void setTabItem(GPXTabItemType tabItem) {
|
||||
this.tabItem = tabItem;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -154,55 +151,54 @@ public class GpxBlockStatisticsBuilder {
|
|||
}
|
||||
items.clear();
|
||||
if (analysis != null) {
|
||||
switch (initBlocksKey) {
|
||||
case INIT_BLOCKS_GENERAL: {
|
||||
float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
||||
Date start = new Date(analysis.startTime);
|
||||
Date end = new Date(analysis.endTime);
|
||||
prepareDataDistance(totalDistance);
|
||||
prepareDataTimeSpan(timeSpan);
|
||||
prepareDataStartTime(start);
|
||||
prepareDataEndTime(end);
|
||||
break;
|
||||
}
|
||||
case INIT_BLOCKS_ALTITUDE: {
|
||||
String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app);
|
||||
String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app);
|
||||
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
|
||||
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
|
||||
prepareDataAverageAltitude();
|
||||
prepareDataAltitudeRange(min, max);
|
||||
prepareDataAscent(asc);
|
||||
prepareDataDescent(desc);
|
||||
break;
|
||||
}
|
||||
case INIT_BLOCKS_SPEED: {
|
||||
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
|
||||
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
|
||||
long timeMoving = withoutGaps ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
|
||||
float totalDistanceMoving = withoutGaps ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
|
||||
prepareDataAverageSpeed(avg);
|
||||
prepareDataMaximumSpeed(max);
|
||||
prepareDataTimeMoving(timeMoving);
|
||||
prepareDataDistanceCorrected(totalDistanceMoving);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case INIT_BLOCKS_BASE: {
|
||||
float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
|
||||
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
|
||||
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
|
||||
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
|
||||
float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
||||
prepareDataDistance(totalDistance);
|
||||
prepareDataAscent(asc);
|
||||
prepareDataDescent(desc);
|
||||
prepareDataAverageSpeed(avg);
|
||||
prepareDataMaximumSpeed(max);
|
||||
prepareDataTimeSpan(timeSpan);
|
||||
break;
|
||||
if (tabItem == null) {
|
||||
float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
|
||||
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
|
||||
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
|
||||
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
|
||||
float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
||||
prepareDataDistance(totalDistance);
|
||||
prepareDataAscent(asc);
|
||||
prepareDataDescent(desc);
|
||||
prepareDataAverageSpeed(avg);
|
||||
prepareDataMaximumSpeed(max);
|
||||
prepareDataTimeSpan(timeSpan);
|
||||
} else {
|
||||
switch (tabItem) {
|
||||
case GPX_TAB_ITEM_GENERAL: {
|
||||
float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
||||
Date start = new Date(analysis.startTime);
|
||||
Date end = new Date(analysis.endTime);
|
||||
prepareDataDistance(totalDistance);
|
||||
prepareDataTimeSpan(timeSpan);
|
||||
prepareDataStartTime(start);
|
||||
prepareDataEndTime(end);
|
||||
break;
|
||||
}
|
||||
case GPX_TAB_ITEM_ALTITUDE: {
|
||||
String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app);
|
||||
String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app);
|
||||
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
|
||||
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
|
||||
prepareDataAverageAltitude();
|
||||
prepareDataAltitudeRange(min, max);
|
||||
prepareDataAscent(asc);
|
||||
prepareDataDescent(desc);
|
||||
break;
|
||||
}
|
||||
case GPX_TAB_ITEM_SPEED: {
|
||||
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
|
||||
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
|
||||
long timeMoving = withoutGaps ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
|
||||
float totalDistanceMoving = withoutGaps ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
|
||||
prepareDataAverageSpeed(avg);
|
||||
prepareDataMaximumSpeed(max);
|
||||
prepareDataTimeMoving(timeMoving);
|
||||
prepareDataDistanceCorrected(totalDistanceMoving);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue