StatisticsRecordedFragment does not need to check null for track/trackStatistics. Fixes
@@ -152,10 +152,10 @@ public class StatisticsRecordedFragment extends Fragment {
getActivity().runOnUiThread(() -> {
if (isResumed()) {
Track track = contentProviderUtils.getTrack(trackId);
- trackStatistics = track != null ? track.getTrackStatistics() : null;
+ trackStatistics = track.getTrackStatistics();
sensorStatistics = contentProviderUtils.getSensorStats(trackId);
- String newCategory = track != null ? track.getCategory() : "";
+ String newCategory = track.getCategory();
if (!category.equals(newCategory)) {
category = newCategory;
sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, getString(R.string.stats_rate_key));
@@ -169,21 +169,16 @@ public class StatisticsRecordedFragment extends Fragment {
}
}
- private void loadTrackDescription(Track track) {
- if (track == null) {
- return;
- }
+ private void loadTrackDescription(@NonNull Track track) {
viewBinding.statsNameValue.setText(track.getName());
viewBinding.statsDescriptionValue.setText(track.getDescription());
- if (track.getTrackStatistics() != null) {
- viewBinding.statsStartDatetimeValue.setText(StringUtils.formatDateTime(getContext(), track.getTrackStatistics().getStartTime()));
- }
+ viewBinding.statsStartDatetimeValue.setText(StringUtils.formatDateTime(getContext(), trackStatistics.getStartTime()));
}
private void updateUI() {
// Set total distance
{
- double totalDistance = trackStatistics == null ? Double.NaN : trackStatistics.getTotalDistance();
+ double totalDistance = trackStatistics.getTotalDistance();
Pair<String, String> parts = StringUtils.getDistanceParts(getContext(), totalDistance, preferenceMetricUnits);
viewBinding.statsDistanceValue.setText(parts.first);
@@ -197,14 +192,14 @@ public class StatisticsRecordedFragment extends Fragment {
}
// Set time and start datetime
- if (trackStatistics != null) {
+ {
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getMovingTime()));
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getTotalTime()));
}
// Set average speed/pace
{
- double speed = trackStatistics != null ? trackStatistics.getAverageSpeed() : Double.NaN;
+ double speed = trackStatistics.getAverageSpeed();
viewBinding.statsAverageSpeedLabel.setText(preferenceReportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, preferenceMetricUnits, preferenceReportSpeed);
@@ -214,7 +209,7 @@ public class StatisticsRecordedFragment extends Fragment {
// Set max speed/pace
{
- double speed = trackStatistics == null ? Double.NaN : trackStatistics.getMaxSpeed();
+ double speed = trackStatistics.getMaxSpeed();
viewBinding.statsMaxSpeedLabel.setText(preferenceReportSpeed ? R.string.stats_max_speed : R.string.stats_fastest_pace);
@@ -225,7 +220,7 @@ public class StatisticsRecordedFragment extends Fragment {
// Set moving speed/pace
{
- double speed = trackStatistics != null ? trackStatistics.getAverageMovingSpeed() : Double.NaN;
+ double speed = trackStatistics.getAverageMovingSpeed();
viewBinding.statsMovingSpeedLabel.setText(preferenceReportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
@@ -240,8 +235,8 @@ public class StatisticsRecordedFragment extends Fragment {
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
viewBinding.statsElevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
- Float elevationGain_m = trackStatistics != null ? trackStatistics.getTotalElevationGain() : null;
- Float elevationLoss_m = trackStatistics != null ? trackStatistics.getTotalElevationLoss() : null;
+ Float elevationGain_m = trackStatistics.getTotalElevationGain();
+ Float elevationLoss_m = trackStatistics.getTotalElevationLoss();
Pair<String, String> parts;
