forked from upstream-mirrors/OpenTracks
StatisticsRecordingFragment: render Views manually (instead of RecyclerView).
Part of #1118.
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
package de.dennisguse.opentracks.ui.customRecordingLayout;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DataField implements Parcelable {
|
||||
|
||||
private final String key;
|
||||
private final String title;
|
||||
private boolean isVisible;
|
||||
private boolean isPrimary;
|
||||
private final boolean isWide;
|
||||
|
||||
public DataField(String key, String title, boolean isVisible, boolean isPrimary, boolean isWide) {
|
||||
public DataField(String key, boolean isVisible, boolean isPrimary, boolean isWide) {
|
||||
this.key = key;
|
||||
this.title = title;
|
||||
this.isVisible = isVisible;
|
||||
this.isPrimary = isPrimary;
|
||||
this.isWide = isWide;
|
||||
@@ -25,7 +21,6 @@ public class DataField implements Parcelable {
|
||||
|
||||
protected DataField(Parcel in) {
|
||||
key = in.readString();
|
||||
title = in.readString();
|
||||
isVisible = in.readByte() != 0;
|
||||
isPrimary = in.readByte() != 0;
|
||||
isWide = in.readByte() != 0;
|
||||
@@ -47,10 +42,6 @@ public class DataField implements Parcelable {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return isVisible;
|
||||
}
|
||||
@@ -71,58 +62,6 @@ public class DataField implements Parcelable {
|
||||
return isWide;
|
||||
}
|
||||
|
||||
public CustomLayoutFieldType getType(Context context) {
|
||||
if (key.equals(context.getString(R.string.stats_custom_layout_clock_key))) {
|
||||
return CustomLayoutFieldType.CLOCK;
|
||||
} else {
|
||||
return CustomLayoutFieldType.GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTitleByKey(Resources resources, String key) {
|
||||
if (key.equals(resources.getString(R.string.stats_custom_layout_total_time_key))) {
|
||||
return resources.getString(R.string.stats_total_time);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_moving_time_key))) {
|
||||
return resources.getString(R.string.stats_moving_time);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_distance_key))) {
|
||||
return resources.getString(R.string.stats_distance);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_speed_key))) {
|
||||
return resources.getString(R.string.stats_speed);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_pace_key))) {
|
||||
return resources.getString(R.string.stats_pace);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_average_moving_speed_key))) {
|
||||
return resources.getString(R.string.stats_average_moving_speed);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_average_speed_key))) {
|
||||
return resources.getString(R.string.stats_average_speed);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_max_speed_key))) {
|
||||
return resources.getString(R.string.stats_max_speed);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_average_moving_pace_key))) {
|
||||
return resources.getString(R.string.stats_average_moving_pace);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_average_pace_key))) {
|
||||
return resources.getString(R.string.stats_average_pace);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_fastest_pace_key))) {
|
||||
return resources.getString(R.string.stats_fastest_pace);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_altitude_key))) {
|
||||
return resources.getString(R.string.stats_altitude);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_gain_key))) {
|
||||
return resources.getString(R.string.stats_gain);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_loss_key))) {
|
||||
return resources.getString(R.string.stats_loss);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_coordinates_key))) {
|
||||
return resources.getString(R.string.stats_coordinates);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_heart_rate_key))) {
|
||||
return resources.getString(R.string.stats_sensors_heart_rate);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_cadence_key))) {
|
||||
return resources.getString(R.string.stats_sensors_cadence);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_power_key))) {
|
||||
return resources.getString(R.string.stats_sensors_power);
|
||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_clock_key))) {
|
||||
return resources.getString(R.string.stats_clock);
|
||||
} else {
|
||||
throw new RuntimeException("It doesn't exists a field with key: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
@@ -131,9 +70,21 @@ public class DataField implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeString(key);
|
||||
parcel.writeString(title);
|
||||
parcel.writeByte((byte) (isVisible ? 1 : 0));
|
||||
parcel.writeByte((byte) (isPrimary ? 1 : 0));
|
||||
parcel.writeByte((byte) (isWide ? 1 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DataField dataField = (DataField) o;
|
||||
return isVisible == dataField.isVisible && isPrimary == dataField.isPrimary && isWide == dataField.isWide && Objects.equals(key, dataField.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(key, isVisible, isPrimary, isWide);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Parcelable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
@@ -112,4 +113,17 @@ public class Layout implements Parcelable {
|
||||
parcel.writeInt(columnsPerRow);
|
||||
parcel.writeList(dataFields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Layout layout = (Layout) o;
|
||||
return columnsPerRow == layout.columnsPerRow && Objects.equals(name, layout.name) && Objects.equals(dataFields, layout.dataFields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, columnsPerRow, dataFields);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ public class LayoutIO {
|
||||
private static DataField fromCSV(String[] fieldParts, @NonNull Resources resources) {
|
||||
return new DataField(
|
||||
fieldParts[0],
|
||||
DataField.getTitleByKey(resources, fieldParts[0]),
|
||||
fieldParts[1].equals(YES_VALUE),
|
||||
fieldParts[2].equals(YES_VALUE),
|
||||
fieldParts[0].equals(resources.getString(R.string.stats_custom_layout_coordinates_key)));
|
||||
|
||||
+14
-2
@@ -11,27 +11,35 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.util.StatisticsUtils;
|
||||
import de.dennisguse.opentracks.viewmodels.Mapping;
|
||||
import de.dennisguse.opentracks.viewmodels.StatisticViewHolder;
|
||||
|
||||
public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Layout layout;
|
||||
private final Context context;
|
||||
private final SettingsCustomLayoutItemClickListener itemClickListener;
|
||||
private final Map<String, Callable<StatisticViewHolder<?>>> mapping;
|
||||
|
||||
|
||||
public SettingsCustomLayoutEditAdapter(Context context, SettingsCustomLayoutItemClickListener itemClickListener, Layout layout) {
|
||||
this.context = context;
|
||||
this.itemClickListener = itemClickListener;
|
||||
this.layout = layout;
|
||||
|
||||
mapping = Mapping.create(context);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.custom_stats_item, parent, false);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.custom_stats_item, parent, false); //TODO CustomStatsItemBinding or rather use mapping.get().call() directly
|
||||
return new SettingsCustomLayoutEditAdapter.ViewHolder(view);
|
||||
}
|
||||
|
||||
@@ -40,7 +48,11 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
|
||||
SettingsCustomLayoutEditAdapter.ViewHolder viewHolder = (SettingsCustomLayoutEditAdapter.ViewHolder) holder;
|
||||
DataField field = layout.getFields().get(position);
|
||||
viewHolder.itemView.setTag(field.getKey());
|
||||
viewHolder.title.setText(field.getTitle());
|
||||
try {
|
||||
viewHolder.title.setText(mapping.get(field.getKey()).call().getTitleId());
|
||||
} catch (Exception e) {
|
||||
//Ignored.
|
||||
}
|
||||
viewHolder.value.setText(StatisticsUtils.emptyValue(context, field.getKey()));
|
||||
|
||||
viewHolder.title.setTextAppearance(context, field.isVisible() ? (field.isPrimary() ? R.style.TextAppearance_OpenTracks_PrimaryHeader : R.style.TextAppearance_OpenTracks_SecondaryHeader) : R.style.TextAppearance_OpenTracks_HiddenHeader);
|
||||
|
||||
Reference in New Issue
Block a user