forked from upstream-mirrors/OpenTracks
AggregatedStatistics: fixed ViewHolder pattern.
This commit is contained in:
@@ -46,49 +46,45 @@ public class AggregatedStatisticsAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
AggregatedStatistics.AggregatedStatistic aggregatedStats = getItem(position);
|
AggregatedStatistics.AggregatedStatistic aggregatedStatistic = getItem(position);
|
||||||
ViewHolder viewHolder;
|
|
||||||
|
|
||||||
if (isSpeedSport(position)) {
|
ViewHolder viewHolder;
|
||||||
viewHolder = new ViewSpeedHolder();
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(context).inflate(R.layout.aggregated_stats_list_item, parent, false);
|
||||||
|
viewHolder = new ViewHolder(convertView);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
} else {
|
} else {
|
||||||
viewHolder = new ViewPaceHolder();
|
viewHolder = (ViewHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
convertView = LayoutInflater.from(context).inflate(R.layout.aggregated_stats_list_item, parent, false);
|
if (TrackIconUtils.isSpeedIcon(context, aggregatedStatistic.getCategory())) {
|
||||||
viewHolder.setValues(convertView, getIcon(position), getName(position), aggregatedStats);
|
viewHolder.setSpeed(aggregatedStatistic);
|
||||||
|
} else {
|
||||||
|
viewHolder.setPace(aggregatedStatistic);
|
||||||
|
}
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSpeedSport(int position) {
|
|
||||||
String category = aggregatedStatistics.getCategory(position);
|
|
||||||
return TrackIconUtils.isSpeedIcon(context, category);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getIcon(int position) {
|
|
||||||
String iconValue = TrackIconUtils.getIconValue(context, aggregatedStatistics.getCategory(position));
|
|
||||||
return TrackIconUtils.getIconDrawable(iconValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getName(int position) {
|
|
||||||
return aggregatedStatistics.getCategory(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ViewHolder {
|
private class ViewHolder {
|
||||||
protected ImageView sportIcon;
|
private final ImageView sportIcon;
|
||||||
protected TextView typeLabel;
|
private final TextView typeLabel;
|
||||||
protected TextView numTracks;
|
private final TextView numTracks;
|
||||||
protected TextView distance;
|
private final TextView distance;
|
||||||
protected TextView distanceUnit;
|
private final TextView distanceUnit;
|
||||||
protected TextView time;
|
private final TextView time;
|
||||||
protected boolean metricsUnits;
|
|
||||||
protected boolean reportSpeed;
|
|
||||||
|
|
||||||
public void setValues(View view, int iconDrawable, String name, AggregatedStatistics.AggregatedStatistic aggregatedStats) {
|
private final TextView avgSpeed;
|
||||||
reportSpeed = PreferencesUtils.isReportSpeed(context, name);
|
private final TextView avgSpeedUnit;
|
||||||
metricsUnits = PreferencesUtils.isMetricUnits(context);
|
private final TextView avgSpeedLabel;
|
||||||
|
private final TextView maxSpeed;
|
||||||
|
private final TextView maxSpeedUnit;
|
||||||
|
private final TextView maxSpeedLabel;
|
||||||
|
|
||||||
|
private boolean metricsUnits;
|
||||||
|
private boolean reportSpeed;
|
||||||
|
|
||||||
|
public ViewHolder(View view) {
|
||||||
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);
|
||||||
@@ -96,86 +92,68 @@ public class AggregatedStatisticsAdapter extends BaseAdapter {
|
|||||||
distanceUnit = view.findViewById(R.id.aggregated_stats_distance_unit);
|
distanceUnit = view.findViewById(R.id.aggregated_stats_distance_unit);
|
||||||
time = view.findViewById(R.id.aggregated_stats_time);
|
time = view.findViewById(R.id.aggregated_stats_time);
|
||||||
|
|
||||||
sportIcon.setImageResource(iconDrawable);
|
|
||||||
typeLabel.setText(name);
|
|
||||||
numTracks.setText(StringUtils.valueInParentheses(String.valueOf(aggregatedStats.getCountTracks())));
|
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getDistanceParts(context, aggregatedStats.getTrackStatistics().getTotalDistance(), metricsUnits);
|
|
||||||
distance.setText(parts.first);
|
|
||||||
distanceUnit.setText(parts.second);
|
|
||||||
|
|
||||||
time.setText(StringUtils.formatElapsedTime(aggregatedStats.getTrackStatistics().getMovingTime()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ViewSpeedHolder extends ViewHolder {
|
|
||||||
private TextView avgSpeed;
|
|
||||||
private TextView avgSpeedUnit;
|
|
||||||
private TextView avgSpeedLabel;
|
|
||||||
private TextView maxSpeed;
|
|
||||||
private TextView maxSpeedUnit;
|
|
||||||
private TextView maxSpeedLabel;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setValues(View view, int iconDrawable, String name, AggregatedStatistics.AggregatedStatistic aggregatedStats) {
|
|
||||||
super.setValues(view, iconDrawable, name, aggregatedStats);
|
|
||||||
|
|
||||||
avgSpeed = view.findViewById(R.id.aggregated_stats_avg_rate);
|
avgSpeed = view.findViewById(R.id.aggregated_stats_avg_rate);
|
||||||
avgSpeedUnit = view.findViewById(R.id.aggregated_stats_avg_rate_unit);
|
avgSpeedUnit = view.findViewById(R.id.aggregated_stats_avg_rate_unit);
|
||||||
avgSpeedLabel = view.findViewById(R.id.aggregated_stats_avg_rate_label);
|
avgSpeedLabel = view.findViewById(R.id.aggregated_stats_avg_rate_label);
|
||||||
maxSpeed = view.findViewById(R.id.aggregated_stats_max_rate);
|
maxSpeed = view.findViewById(R.id.aggregated_stats_max_rate);
|
||||||
maxSpeedUnit = view.findViewById(R.id.aggregated_stats_max_rate_unit);
|
maxSpeedUnit = view.findViewById(R.id.aggregated_stats_max_rate_unit);
|
||||||
maxSpeedLabel = view.findViewById(R.id.aggregated_stats_max_rate_label);
|
maxSpeedLabel = view.findViewById(R.id.aggregated_stats_max_rate_label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
||||||
|
setCommonValues(aggregatedStatistic);
|
||||||
{
|
{
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getAverageMovingSpeed(), metricsUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStatistic.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, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStatistic.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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private class ViewPaceHolder extends ViewHolder {
|
|
||||||
private TextView avgPace;
|
|
||||||
private TextView avgPaceUnit;
|
|
||||||
private TextView avgPaceLabel;
|
|
||||||
private TextView maxPace;
|
|
||||||
private TextView maxPaceUnit;
|
|
||||||
private TextView maxPaceLabel;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setValues(View view, int iconDrawable, String name, AggregatedStatistics.AggregatedStatistic aggregatedStats) {
|
|
||||||
super.setValues(view, iconDrawable, name, aggregatedStats);
|
|
||||||
|
|
||||||
avgPace = view.findViewById(R.id.aggregated_stats_avg_rate);
|
|
||||||
avgPaceUnit = view.findViewById(R.id.aggregated_stats_avg_rate_unit);
|
|
||||||
avgPaceLabel = view.findViewById(R.id.aggregated_stats_avg_rate_label);
|
|
||||||
|
|
||||||
maxPace = view.findViewById(R.id.aggregated_stats_max_rate);
|
|
||||||
maxPaceUnit = view.findViewById(R.id.aggregated_stats_max_rate_unit);
|
|
||||||
maxPaceLabel = view.findViewById(R.id.aggregated_stats_max_rate_label);
|
|
||||||
|
|
||||||
|
public void setPace(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
||||||
|
setCommonValues(aggregatedStatistic);
|
||||||
{
|
{
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getAverageMovingSpeed(), metricsUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStatistic.getTrackStatistics().getAverageMovingSpeed(), metricsUnits, reportSpeed);
|
||||||
avgPace.setText(parts.first);
|
avgSpeed.setText(parts.first);
|
||||||
avgPaceUnit.setText(parts.second);
|
avgSpeedUnit.setText(parts.second);
|
||||||
avgPaceLabel.setText(R.string.stats_average_moving_pace);
|
avgSpeedLabel.setText(context.getString(R.string.stats_average_moving_pace));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStats.getTrackStatistics().getMaxSpeed(), metricsUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(context, aggregatedStatistic.getTrackStatistics().getMaxSpeed(), metricsUnits, reportSpeed);
|
||||||
maxPace.setText(parts.first);
|
maxSpeed.setText(parts.first);
|
||||||
maxPaceUnit.setText(parts.second);
|
maxSpeedUnit.setText(parts.second);
|
||||||
maxPaceLabel.setText(R.string.stats_fastest_pace);
|
maxSpeedLabel.setText(R.string.stats_fastest_pace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCommonValues(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
||||||
|
String category = aggregatedStatistic.getCategory();
|
||||||
|
|
||||||
|
reportSpeed = PreferencesUtils.isReportSpeed(context, category);
|
||||||
|
metricsUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
|
|
||||||
|
sportIcon.setImageResource(getIcon(aggregatedStatistic));
|
||||||
|
typeLabel.setText(category);
|
||||||
|
numTracks.setText(StringUtils.valueInParentheses(String.valueOf(aggregatedStatistic.getCountTracks())));
|
||||||
|
|
||||||
|
Pair<String, String> parts = StringUtils.getDistanceParts(context, aggregatedStatistic.getTrackStatistics().getTotalDistance(), metricsUnits);
|
||||||
|
distance.setText(parts.first);
|
||||||
|
distanceUnit.setText(parts.second);
|
||||||
|
|
||||||
|
time.setText(StringUtils.formatElapsedTime(aggregatedStatistic.getTrackStatistics().getMovingTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getIcon(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
||||||
|
String iconValue = TrackIconUtils.getIconValue(context, aggregatedStatistic.getCategory());
|
||||||
|
return TrackIconUtils.getIconDrawable(iconValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class IntervalStatisticsAdapter extends ArrayAdapter<IntervalStatistics.I
|
|||||||
|
|
||||||
private final StackMode stackMode;
|
private final StackMode stackMode;
|
||||||
private final boolean metricUnits;
|
private final boolean metricUnits;
|
||||||
private float sumDistance_m;
|
|
||||||
private final String category;
|
private final String category;
|
||||||
|
|
||||||
public IntervalStatisticsAdapter(Context context, List<IntervalStatistics.Interval> intervalList, String category, StackMode stackMode) {
|
public IntervalStatisticsAdapter(Context context, List<IntervalStatistics.Interval> intervalList, String category, StackMode stackMode) {
|
||||||
@@ -52,6 +51,7 @@ public class IntervalStatisticsAdapter extends ArrayAdapter<IntervalStatistics.I
|
|||||||
viewHolder = (ViewHolder) intervalView.getTag();
|
viewHolder = (ViewHolder) intervalView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float sumDistance_m;
|
||||||
if (actualPosition + 1 == getCount() && actualPosition > 0) {
|
if (actualPosition + 1 == getCount() && actualPosition > 0) {
|
||||||
sumDistance_m = actualPosition * getItem(actualPosition - 1).getDistance_m() + interval.getDistance_m();
|
sumDistance_m = actualPosition * getItem(actualPosition - 1).getDistance_m() + interval.getDistance_m();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user