mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-06 11:33:06 +02:00
+14
-14
@@ -10,38 +10,38 @@ import java.util.stream.Collectors;
|
||||
|
||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
|
||||
public class Layout implements Parcelable {
|
||||
public class RecordingLayout implements Parcelable {
|
||||
|
||||
// User-generated layout's name.
|
||||
private final String name;
|
||||
private int columnsPerRow;
|
||||
private final List<DataField> dataFields = new ArrayList<>();
|
||||
|
||||
public Layout(String name) {
|
||||
public RecordingLayout(String name) {
|
||||
this.name = name;
|
||||
this.columnsPerRow = PreferencesUtils.getLayoutColumnsByDefault();
|
||||
}
|
||||
|
||||
public Layout(String name, int columnsPerRow) {
|
||||
public RecordingLayout(String name, int columnsPerRow) {
|
||||
this.name = name;
|
||||
this.columnsPerRow = columnsPerRow;
|
||||
}
|
||||
|
||||
protected Layout(Parcel in) {
|
||||
protected RecordingLayout(Parcel in) {
|
||||
name = in.readString();
|
||||
columnsPerRow = in.readInt();
|
||||
in.readList(dataFields, DataField.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static final Creator<Layout> CREATOR = new Creator<>() {
|
||||
public static final Creator<RecordingLayout> CREATOR = new Creator<>() {
|
||||
@Override
|
||||
public Layout createFromParcel(Parcel in) {
|
||||
return new Layout(in);
|
||||
public RecordingLayout createFromParcel(Parcel in) {
|
||||
return new RecordingLayout(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Layout[] newArray(int size) {
|
||||
return new Layout[size];
|
||||
public RecordingLayout[] newArray(int size) {
|
||||
return new RecordingLayout[size];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -83,8 +83,8 @@ public class Layout implements Parcelable {
|
||||
this.columnsPerRow = columnsPerRow;
|
||||
}
|
||||
|
||||
public boolean sameName(Layout layout) {
|
||||
return this.name.equalsIgnoreCase(layout.getName());
|
||||
public boolean sameName(RecordingLayout recordingLayout) {
|
||||
return this.name.equalsIgnoreCase(recordingLayout.getName());
|
||||
}
|
||||
|
||||
public boolean sameName(String name) {
|
||||
@@ -98,7 +98,7 @@ public class Layout implements Parcelable {
|
||||
}
|
||||
|
||||
return getName() + CsvLayoutUtils.ITEM_SEPARATOR + getColumnsPerRow() + CsvLayoutUtils.ITEM_SEPARATOR
|
||||
+ fields.stream().map(LayoutIO::toCsv).collect(Collectors.joining(CsvLayoutUtils.ITEM_SEPARATOR))
|
||||
+ fields.stream().map(RecordingLayoutIO::toCsv).collect(Collectors.joining(CsvLayoutUtils.ITEM_SEPARATOR))
|
||||
+ CsvLayoutUtils.ITEM_SEPARATOR;
|
||||
}
|
||||
|
||||
@@ -118,8 +118,8 @@ public class Layout implements Parcelable {
|
||||
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);
|
||||
RecordingLayout recordingLayout = (RecordingLayout) o;
|
||||
return columnsPerRow == recordingLayout.columnsPerRow && Objects.equals(name, recordingLayout.name) && Objects.equals(dataFields, recordingLayout.dataFields);
|
||||
}
|
||||
|
||||
@Override
|
||||
+20
-15
@@ -6,41 +6,39 @@ import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
|
||||
public class LayoutIO {
|
||||
public class RecordingLayoutIO {
|
||||
|
||||
private static final String TAG = Layout.class.getSimpleName();
|
||||
private static final String TAG = RecordingLayout.class.getSimpleName();
|
||||
|
||||
private static final String YES_VALUE = "1";
|
||||
private static final String NOT_VALUE = "0";
|
||||
|
||||
public static String toCsv(DataField datafield) {
|
||||
String visible = datafield.isVisible() ? YES_VALUE : NOT_VALUE;
|
||||
String primary = datafield.isPrimary() ? YES_VALUE : NOT_VALUE;
|
||||
String wide = datafield.isWide() ? YES_VALUE : NOT_VALUE;
|
||||
return datafield.getKey() + CsvLayoutUtils.PROPERTY_SEPARATOR + visible + CsvLayoutUtils.PROPERTY_SEPARATOR + primary + CsvLayoutUtils.PROPERTY_SEPARATOR + wide;
|
||||
}
|
||||
|
||||
public static Layout fromCsv(@NonNull String csvLine, @NonNull Resources resources) {
|
||||
public static RecordingLayout fromCsv(@NonNull String csvLine, @NonNull Resources resources) {
|
||||
List<String> csvParts = CsvLayoutUtils.getCsvLineParts(csvLine);
|
||||
if (csvParts == null) {
|
||||
Log.e(TAG, "Invalid CSV layout. It shouldn't happen: " + csvLine);
|
||||
return new Layout(PreferencesUtils.getDefaultLayoutName());
|
||||
return new RecordingLayout(PreferencesUtils.getDefaultLayoutName());
|
||||
}
|
||||
|
||||
Layout layout = new Layout(csvParts.get(0), Integer.parseInt(csvParts.get(1)));
|
||||
RecordingLayout recordingLayout = new RecordingLayout(csvParts.get(0), Integer.parseInt(csvParts.get(1)));
|
||||
for (int i = 2; i < csvParts.size(); i++) {
|
||||
String[] fieldParts = CsvLayoutUtils.getCsvFieldParts(csvParts.get(i));
|
||||
if (fieldParts == null) {
|
||||
Log.e(TAG, "Invalid CSV layout. It shouldn't happen: " + csvLine);
|
||||
return layout;
|
||||
return recordingLayout;
|
||||
}
|
||||
layout.addField(fromCSV(fieldParts, resources));
|
||||
recordingLayout.addField(fromCSV(fieldParts, resources));
|
||||
}
|
||||
return layout;
|
||||
return recordingLayout;
|
||||
}
|
||||
|
||||
public static String toCSV(List<RecordingLayout> recordingLayouts) {
|
||||
return recordingLayouts.stream().map(RecordingLayout::toCsv).collect(Collectors.joining(CsvLayoutUtils.LINE_SEPARATOR));
|
||||
}
|
||||
|
||||
private static DataField fromCSV(String[] fieldParts, @NonNull Resources resources) {
|
||||
@@ -50,4 +48,11 @@ public class LayoutIO {
|
||||
fieldParts[2].equals(YES_VALUE),
|
||||
fieldParts[0].equals(resources.getString(R.string.stats_custom_layout_coordinates_key)));
|
||||
}
|
||||
|
||||
static String toCsv(DataField datafield) {
|
||||
String visible = datafield.isVisible() ? YES_VALUE : NOT_VALUE;
|
||||
String primary = datafield.isPrimary() ? YES_VALUE : NOT_VALUE;
|
||||
String wide = datafield.isWide() ? YES_VALUE : NOT_VALUE;
|
||||
return datafield.getKey() + CsvLayoutUtils.PROPERTY_SEPARATOR + visible + CsvLayoutUtils.PROPERTY_SEPARATOR + primary + CsvLayoutUtils.PROPERTY_SEPARATOR + wide;
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -58,16 +58,16 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
|
||||
demoData = new RecordingData(track, lastTrackPoint, null);
|
||||
}
|
||||
|
||||
private Layout layout;
|
||||
private RecordingLayout recordingLayout;
|
||||
private final Context context;
|
||||
private final SettingsCustomLayoutItemClickListener itemClickListener;
|
||||
private final Map<String, Callable<StatisticViewHolder<?>>> mapping;
|
||||
|
||||
|
||||
public SettingsCustomLayoutEditAdapter(Context context, SettingsCustomLayoutItemClickListener itemClickListener, Layout layout) {
|
||||
public SettingsCustomLayoutEditAdapter(Context context, SettingsCustomLayoutItemClickListener itemClickListener, RecordingLayout recordingLayout) {
|
||||
this.context = context;
|
||||
this.itemClickListener = itemClickListener;
|
||||
this.layout = layout;
|
||||
this.recordingLayout = recordingLayout;
|
||||
|
||||
mapping = Mapping.create(context);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
SettingsCustomLayoutEditAdapter.ViewHolder viewHolder = (SettingsCustomLayoutEditAdapter.ViewHolder) holder;
|
||||
DataField field = layout.getFields().get(position);
|
||||
DataField field = recordingLayout.getFields().get(position);
|
||||
viewHolder.itemView.setTag(field.getKey());
|
||||
try {
|
||||
StatisticViewHolder<?> m = mapping.get(field.getKey()).call();
|
||||
@@ -103,32 +103,32 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (layout == null) {
|
||||
if (recordingLayout == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return layout.getFields().size();
|
||||
return recordingLayout.getFields().size();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isItemWide(int position) {
|
||||
return layout.getFields().get(position).isWide();
|
||||
return recordingLayout.getFields().get(position).isWide();
|
||||
}
|
||||
|
||||
public DataField getItem(int position) {
|
||||
return layout.getFields().get(position);
|
||||
return recordingLayout.getFields().get(position);
|
||||
}
|
||||
|
||||
public void swapValues(Layout data) {
|
||||
this.layout = data;
|
||||
if (this.layout != null) {
|
||||
public void swapValues(RecordingLayout data) {
|
||||
this.recordingLayout = data;
|
||||
if (this.recordingLayout != null) {
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Layout move(int fromPosition, int toPosition) {
|
||||
layout.moveField(fromPosition, toPosition);
|
||||
public RecordingLayout move(int fromPosition, int toPosition) {
|
||||
recordingLayout.moveField(fromPosition, toPosition);
|
||||
notifyItemMoved(fromPosition, toPosition);
|
||||
return layout;
|
||||
return recordingLayout;
|
||||
}
|
||||
|
||||
private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
@@ -145,7 +145,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String statTitle = (String) view.getTag();
|
||||
Optional<DataField> optionalField = layout.getFields().stream().filter(f -> f.getKey().equals(statTitle)).findFirst();
|
||||
Optional<DataField> optionalField = recordingLayout.getFields().stream().filter(f -> f.getKey().equals(statTitle)).findFirst();
|
||||
optionalField.ifPresent(itemClickListener::onSettingsCustomLayoutItemClicked);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-17
@@ -17,14 +17,14 @@ import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
|
||||
public class SettingsCustomLayoutListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<Layout> layoutList;
|
||||
private List<RecordingLayout> recordingLayoutList;
|
||||
private final Context context;
|
||||
private final SettingsCustomLayoutProfileClickListener itemClickListener;
|
||||
|
||||
public SettingsCustomLayoutListAdapter(Context context, SettingsCustomLayoutProfileClickListener itemClickListener) {
|
||||
this.context = context;
|
||||
this.itemClickListener = itemClickListener;
|
||||
layoutList = PreferencesUtils.getAllCustomLayouts();
|
||||
recordingLayoutList = PreferencesUtils.getAllCustomLayouts();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -37,37 +37,37 @@ public class SettingsCustomLayoutListAdapter extends RecyclerView.Adapter<Recycl
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
SettingsCustomLayoutListAdapter.ViewHolder viewHolder = (SettingsCustomLayoutListAdapter.ViewHolder) holder;
|
||||
Layout layout = layoutList.get(position);
|
||||
viewHolder.itemView.setTag(layout.getName());
|
||||
viewHolder.title.setText(layout.getName());
|
||||
RecordingLayout recordingLayout = recordingLayoutList.get(position);
|
||||
viewHolder.itemView.setTag(recordingLayout.getName());
|
||||
viewHolder.title.setText(recordingLayout.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (layoutList == null) {
|
||||
if (recordingLayoutList == null) {
|
||||
return 0;
|
||||
}
|
||||
return layoutList.size();
|
||||
return recordingLayoutList.size();
|
||||
}
|
||||
|
||||
public List<Layout> getLayouts() {
|
||||
return layoutList;
|
||||
public List<RecordingLayout> getLayouts() {
|
||||
return recordingLayoutList;
|
||||
}
|
||||
|
||||
public void reloadLayouts() {
|
||||
layoutList = PreferencesUtils.getAllCustomLayouts();
|
||||
recordingLayoutList = PreferencesUtils.getAllCustomLayouts();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void removeLayout(int position) {
|
||||
layoutList.remove(position);
|
||||
PreferencesUtils.updateCustomLayouts(layoutList);
|
||||
recordingLayoutList.remove(position);
|
||||
PreferencesUtils.updateCustomLayouts(recordingLayoutList);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void restoreItem(Layout layout, int position) {
|
||||
layoutList.add(position, layout);
|
||||
PreferencesUtils.updateCustomLayouts(layoutList);
|
||||
public void restoreItem(RecordingLayout recordingLayout, int position) {
|
||||
recordingLayoutList.add(position, recordingLayout);
|
||||
PreferencesUtils.updateCustomLayouts(recordingLayoutList);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -83,12 +83,12 @@ public class SettingsCustomLayoutListAdapter extends RecyclerView.Adapter<Recycl
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String profile = (String) view.getTag();
|
||||
Optional<Layout> optionalLayout = layoutList.stream().filter(layout -> layout.sameName(new Layout(profile))).findFirst();
|
||||
Optional<RecordingLayout> optionalLayout = recordingLayoutList.stream().filter(layout -> layout.sameName(new RecordingLayout(profile))).findFirst();
|
||||
optionalLayout.ifPresent(itemClickListener::onSettingsCustomLayoutProfileClicked);
|
||||
}
|
||||
}
|
||||
|
||||
public interface SettingsCustomLayoutProfileClickListener {
|
||||
void onSettingsCustomLayoutProfileClicked(@NonNull Layout layout);
|
||||
void onSettingsCustomLayoutProfileClicked(@NonNull RecordingLayout recordingLayout);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user