Preferred rate is used for aggregated stats. Fixes #321.

Lambda expression for Observer.
This commit is contained in:
Román
2020-07-15 21:26:50 +02:00
committed by Dennis Guse
parent a2b53c75f4
commit b8d2d14d68
2 changed files with 12 additions and 12 deletions
@@ -23,15 +23,12 @@ public class AggregatedStatisticsActivity extends AbstractActivity {
listView.setEmptyView(findViewById(R.id.aggregated_stats_empty_view)); listView.setEmptyView(findViewById(R.id.aggregated_stats_empty_view));
final AggregatedStatisticsModel viewModel = new ViewModelProvider(this).get(AggregatedStatisticsModel.class); final AggregatedStatisticsModel viewModel = new ViewModelProvider(this).get(AggregatedStatisticsModel.class);
viewModel.getAggregatedStats().observe(this, new Observer<AggregatedStatistics>() { viewModel.getAggregatedStats().observe(this, aggregatedStatistics -> {
@Override if (aggregatedStatistics != null) {
public void onChanged(AggregatedStatistics aggregatedStatistics) { adapter = new AggregatedStatisticsAdapter(getApplicationContext(), aggregatedStatistics);
if (aggregatedStatistics != null) { listView.setAdapter(adapter);
adapter = new AggregatedStatisticsAdapter(getApplicationContext(), aggregatedStatistics);
listView.setAdapter(adapter);
}
adapter.notifyDataSetChanged();
} }
adapter.notifyDataSetChanged();
}); });
} }
@@ -83,12 +83,15 @@ public class AggregatedStatisticsAdapter extends BaseAdapter {
protected TextView distanceUnit; protected TextView distanceUnit;
protected TextView time; protected TextView time;
protected boolean metricsUnits; protected boolean metricsUnits;
protected boolean reportSpeed;
public ViewHolder() { public ViewHolder() {
metricsUnits = PreferencesUtils.isMetricUnits(context); metricsUnits = PreferencesUtils.isMetricUnits(context);
} }
public void setValues(View view, int iconDrawable, String name, AggregatedStatistics.AggregatedStatistic aggregatedStats) { public void setValues(View view, int iconDrawable, String name, AggregatedStatistics.AggregatedStatistic aggregatedStats) {
reportSpeed = PreferencesUtils.isReportSpeed(context, name);
sportIcon = view.findViewById(R.id.aggregated_stats_sport_icon); sportIcon = view.findViewById(R.id.aggregated_stats_sport_icon);
typeLabel = view.findViewById(R.id.aggregated_stats_type_label); typeLabel = view.findViewById(R.id.aggregated_stats_type_label);
numTracks = view.findViewById(R.id.aggregated_stats_num_tracks); numTracks = view.findViewById(R.id.aggregated_stats_num_tracks);
@@ -128,14 +131,14 @@ public class AggregatedStatisticsAdapter extends BaseAdapter {
maxSpeedLabel = view.findViewById(R.id.aggregated_stats_max_rate_label); maxSpeedLabel = view.findViewById(R.id.aggregated_stats_max_rate_label);
{ {
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getAverageMovingSpeed(), metricsUnits, true); Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getAverageMovingSpeed(), metricsUnits, reportSpeed);
avgSpeed.setText(parts.first); avgSpeed.setText(parts.first);
avgSpeedUnit.setText(parts.second); avgSpeedUnit.setText(parts.second);
avgSpeedLabel.setText(context.getString(R.string.stats_average_moving_speed)); avgSpeedLabel.setText(context.getString(R.string.stats_average_moving_speed));
} }
{ {
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getMaxSpeed(), metricsUnits, true); Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getMaxSpeed(), metricsUnits, reportSpeed);
maxSpeed.setText(parts.first); maxSpeed.setText(parts.first);
maxSpeedUnit.setText(parts.second); maxSpeedUnit.setText(parts.second);
maxSpeedLabel.setText(context.getString(R.string.stats_max_speed)); maxSpeedLabel.setText(context.getString(R.string.stats_max_speed));
@@ -164,14 +167,14 @@ public class AggregatedStatisticsAdapter extends BaseAdapter {
maxPaceLabel = view.findViewById(R.id.aggregated_stats_max_rate_label); maxPaceLabel = view.findViewById(R.id.aggregated_stats_max_rate_label);
{ {
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getAverageMovingSpeed(), metricsUnits, false); Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getAverageMovingSpeed(), metricsUnits, reportSpeed);
avgPace.setText(parts.first); avgPace.setText(parts.first);
avgPaceUnit.setText(parts.second); avgPaceUnit.setText(parts.second);
avgPaceLabel.setText(R.string.stats_average_moving_pace); avgPaceLabel.setText(R.string.stats_average_moving_pace);
} }
{ {
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getMaxSpeed(), metricsUnits, false); Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getMaxSpeed(), metricsUnits, reportSpeed);
maxPace.setText(parts.first); maxPace.setText(parts.first);
maxPaceUnit.setText(parts.second); maxPaceUnit.setText(parts.second);
maxPaceLabel.setText(R.string.stats_fastest_pace); maxPaceLabel.setText(R.string.stats_fastest_pace);