forked from upstream-mirrors/OpenTracks
Cleanup: AggregatedStatisticsAdapter uses ViewBinding.
This commit is contained in:
+24
-52
@@ -3,10 +3,7 @@ package de.dennisguse.opentracks.ui.aggregatedStatistics;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
@@ -18,6 +15,7 @@ import de.dennisguse.opentracks.R;
|
|||||||
import de.dennisguse.opentracks.data.models.ActivityType;
|
import de.dennisguse.opentracks.data.models.ActivityType;
|
||||||
import de.dennisguse.opentracks.data.models.DistanceFormatter;
|
import de.dennisguse.opentracks.data.models.DistanceFormatter;
|
||||||
import de.dennisguse.opentracks.data.models.SpeedFormatter;
|
import de.dennisguse.opentracks.data.models.SpeedFormatter;
|
||||||
|
import de.dennisguse.opentracks.databinding.AggregatedStatsListItemBinding;
|
||||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.settings.UnitSystem;
|
import de.dennisguse.opentracks.settings.UnitSystem;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
@@ -35,8 +33,7 @@ public class AggregatedStatisticsAdapter extends RecyclerView.Adapter<RecyclerVi
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.aggregated_stats_list_item, parent, false);
|
return new ViewHolder(AggregatedStatsListItemBinding.inflate(LayoutInflater.from(parent.getContext())));
|
||||||
return new ViewHolder(view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,38 +72,13 @@ public class AggregatedStatisticsAdapter extends RecyclerView.Adapter<RecyclerVi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class ViewHolder extends RecyclerView.ViewHolder {
|
private class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
private final ImageView sportIcon;
|
private final AggregatedStatsListItemBinding viewBinding;
|
||||||
private final TextView typeLabel;
|
|
||||||
private final TextView numTracks;
|
|
||||||
private final TextView distance;
|
|
||||||
private final TextView distanceUnit;
|
|
||||||
private final TextView time;
|
|
||||||
|
|
||||||
private final TextView avgSpeed;
|
|
||||||
private final TextView avgSpeedUnit;
|
|
||||||
private final TextView avgSpeedLabel;
|
|
||||||
private final TextView maxSpeed;
|
|
||||||
private final TextView maxSpeedUnit;
|
|
||||||
private final TextView maxSpeedLabel;
|
|
||||||
|
|
||||||
private UnitSystem unitSystem = UnitSystem.defaultUnitSystem();
|
private UnitSystem unitSystem = UnitSystem.defaultUnitSystem();
|
||||||
private boolean reportSpeed;
|
private boolean reportSpeed;
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
public ViewHolder(AggregatedStatsListItemBinding viewBinding) {
|
||||||
super(view);
|
super(viewBinding.getRoot());
|
||||||
sportIcon = view.findViewById(R.id.aggregated_stats_sport_icon);
|
this.viewBinding = viewBinding;
|
||||||
typeLabel = view.findViewById(R.id.aggregated_stats_type_label);
|
|
||||||
numTracks = view.findViewById(R.id.aggregated_stats_num_tracks);
|
|
||||||
distance = view.findViewById(R.id.aggregated_stats_distance);
|
|
||||||
distanceUnit = view.findViewById(R.id.aggregated_stats_distance_unit);
|
|
||||||
time = view.findViewById(R.id.aggregated_stats_time);
|
|
||||||
|
|
||||||
avgSpeed = view.findViewById(R.id.aggregated_stats_avg_rate);
|
|
||||||
avgSpeedUnit = view.findViewById(R.id.aggregated_stats_avg_rate_unit);
|
|
||||||
avgSpeedLabel = view.findViewById(R.id.aggregated_stats_avg_rate_label);
|
|
||||||
maxSpeed = view.findViewById(R.id.aggregated_stats_max_rate);
|
|
||||||
maxSpeedUnit = view.findViewById(R.id.aggregated_stats_max_rate_unit);
|
|
||||||
maxSpeedLabel = view.findViewById(R.id.aggregated_stats_max_rate_label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
public void setSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
||||||
@@ -115,16 +87,16 @@ public class AggregatedStatisticsAdapter extends RecyclerView.Adapter<RecyclerVi
|
|||||||
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context);
|
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context);
|
||||||
{
|
{
|
||||||
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getAverageMovingSpeed());
|
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getAverageMovingSpeed());
|
||||||
avgSpeed.setText(parts.first);
|
viewBinding.aggregatedStatsAvgRate.setText(parts.first);
|
||||||
avgSpeedUnit.setText(parts.second);
|
viewBinding.aggregatedStatsAvgRateUnit.setText(parts.second);
|
||||||
avgSpeedLabel.setText(context.getString(R.string.stats_average_moving_speed));
|
viewBinding.aggregatedStatsAvgRateLabel.setText(context.getString(R.string.stats_average_moving_speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed());
|
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed());
|
||||||
maxSpeed.setText(parts.first);
|
viewBinding.aggregatedStatsMaxRate.setText(parts.first);
|
||||||
maxSpeedUnit.setText(parts.second);
|
viewBinding.aggregatedStatsMaxRateUnit.setText(parts.second);
|
||||||
maxSpeedLabel.setText(context.getString(R.string.stats_max_speed));
|
viewBinding.aggregatedStatsMaxRateLabel.setText(context.getString(R.string.stats_max_speed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,16 +106,16 @@ public class AggregatedStatisticsAdapter extends RecyclerView.Adapter<RecyclerVi
|
|||||||
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context);
|
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context);
|
||||||
{
|
{
|
||||||
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getAverageMovingSpeed());
|
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getAverageMovingSpeed());
|
||||||
avgSpeed.setText(parts.first);
|
viewBinding.aggregatedStatsAvgRate.setText(parts.first);
|
||||||
avgSpeedUnit.setText(parts.second);
|
viewBinding.aggregatedStatsAvgRateUnit.setText(parts.second);
|
||||||
avgSpeedLabel.setText(context.getString(R.string.stats_average_moving_pace));
|
viewBinding.aggregatedStatsAvgRateLabel.setText(context.getString(R.string.stats_average_moving_pace));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed());
|
Pair<String, String> parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed());
|
||||||
maxSpeed.setText(parts.first);
|
viewBinding.aggregatedStatsMaxRate.setText(parts.first);
|
||||||
maxSpeedUnit.setText(parts.second);
|
viewBinding.aggregatedStatsMaxRateUnit.setText(parts.second);
|
||||||
maxSpeedLabel.setText(R.string.stats_fastest_pace);
|
viewBinding.aggregatedStatsMaxRateLabel.setText(R.string.stats_fastest_pace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,17 +126,17 @@ public class AggregatedStatisticsAdapter extends RecyclerView.Adapter<RecyclerVi
|
|||||||
reportSpeed = PreferencesUtils.isReportSpeed(activityType);
|
reportSpeed = PreferencesUtils.isReportSpeed(activityType);
|
||||||
unitSystem = PreferencesUtils.getUnitSystem();
|
unitSystem = PreferencesUtils.getUnitSystem();
|
||||||
|
|
||||||
sportIcon.setImageResource(getIcon(aggregatedStatistic));
|
viewBinding.activityIcon.setImageResource(getIcon(aggregatedStatistic));
|
||||||
typeLabel.setText(activityType);
|
viewBinding.aggregatedStatsTypeLabel.setText(activityType);
|
||||||
numTracks.setText(StringUtils.valueInParentheses(String.valueOf(aggregatedStatistic.getCountTracks())));
|
viewBinding.aggregatedStatsNumTracks.setText(StringUtils.valueInParentheses(String.valueOf(aggregatedStatistic.getCountTracks())));
|
||||||
|
|
||||||
Pair<String, String> parts = DistanceFormatter.Builder()
|
Pair<String, String> parts = DistanceFormatter.Builder()
|
||||||
.setUnit(unitSystem)
|
.setUnit(unitSystem)
|
||||||
.build(context).getDistanceParts(aggregatedStatistic.getTrackStatistics().getTotalDistance());
|
.build(context).getDistanceParts(aggregatedStatistic.getTrackStatistics().getTotalDistance());
|
||||||
distance.setText(parts.first);
|
viewBinding.aggregatedStatsDistance.setText(parts.first);
|
||||||
distanceUnit.setText(parts.second);
|
viewBinding.aggregatedStatsDistanceUnit.setText(parts.second);
|
||||||
|
|
||||||
time.setText(StringUtils.formatElapsedTime(aggregatedStatistic.getTrackStatistics().getMovingTime()));
|
viewBinding.aggregatedStatsTime.setText(StringUtils.formatElapsedTime(aggregatedStatistic.getTrackStatistics().getMovingTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getIcon(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
private int getIcon(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
<!-- Icon and sport name -->
|
<!-- Icon and sport name -->
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/aggregated_stats_sport_icon"
|
android:id="@+id/activity_icon"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintEnd_toStartOf="@id/aggregated_stats_type_label"
|
app:layout_constraintEnd_toStartOf="@id/aggregated_stats_type_label"
|
||||||
@@ -49,9 +49,9 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="0dp"
|
android:layout_marginTop="0dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/aggregated_stats_sport_icon"
|
app:layout_constraintBottom_toBottomOf="@+id/activity_icon"
|
||||||
app:layout_constraintStart_toEndOf="@+id/aggregated_stats_sport_icon"
|
app:layout_constraintStart_toEndOf="@+id/activity_icon"
|
||||||
app:layout_constraintTop_toTopOf="@+id/aggregated_stats_sport_icon"
|
app:layout_constraintTop_toTopOf="@+id/activity_icon"
|
||||||
tools:text="@string/activity_type_cycling" />
|
tools:text="@string/activity_type_cycling" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
app:layout_constraintEnd_toStartOf="@id/aggregated_stats_distance_unit"
|
app:layout_constraintEnd_toStartOf="@id/aggregated_stats_distance_unit"
|
||||||
app:layout_constraintHorizontal_chainStyle="packed"
|
app:layout_constraintHorizontal_chainStyle="packed"
|
||||||
app:layout_constraintStart_toEndOf="@id/guideline1"
|
app:layout_constraintStart_toEndOf="@id/guideline1"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/aggregated_stats_sport_icon"
|
app:layout_constraintTop_toBottomOf="@+id/activity_icon"
|
||||||
tools:layout_editor_absoluteX="52dp"
|
tools:layout_editor_absoluteX="52dp"
|
||||||
tools:text="100000" />
|
tools:text="100000" />
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintEnd_toEndOf="@id/guideline3"
|
app:layout_constraintEnd_toEndOf="@id/guideline3"
|
||||||
app:layout_constraintStart_toStartOf="@+id/guideline2"
|
app:layout_constraintStart_toStartOf="@+id/guideline2"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/aggregated_stats_sport_icon"
|
app:layout_constraintTop_toBottomOf="@+id/activity_icon"
|
||||||
tools:text="00:00:00" />
|
tools:text="00:00:00" />
|
||||||
|
|
||||||
<!-- Avg. rate -->
|
<!-- Avg. rate -->
|
||||||
|
|||||||
Reference in New Issue
Block a user