forked from upstream-mirrors/OpenTracks
New field for recording layout: clock.
With this change fields can be: short, wide, clock short or clock wide. Fixes #1015.
This commit is contained in:
@@ -61,13 +61,8 @@ public class SettingsCustomLayoutAdapter extends RecyclerView.Adapter<RecyclerVi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemViewType(int position) {
|
|
||||||
return layout.getFields().get(position).isWide() ? CustomLayoutFieldType.WIDE.value() : CustomLayoutFieldType.SHORT.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isItemWide(int position) {
|
public boolean isItemWide(int position) {
|
||||||
return getItemViewType(position) == CustomLayoutFieldType.WIDE.value();
|
return layout.getFields().get(position).isWide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataField getItem(int position) {
|
public DataField getItem(int position) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextClock;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -13,6 +14,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
|
import de.dennisguse.opentracks.content.data.CustomLayoutFieldType;
|
||||||
import de.dennisguse.opentracks.viewmodels.StatisticData;
|
import de.dennisguse.opentracks.viewmodels.StatisticData;
|
||||||
|
|
||||||
public class StatisticsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class StatisticsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
@@ -28,15 +30,26 @@ public class StatisticsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.stats_item, parent, false);
|
View view;
|
||||||
return new StatisticsAdapter.ViewHolder(view);
|
if (viewType == CustomLayoutFieldType.CLOCK.value()) {
|
||||||
|
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.stats_clock_item, parent, false);
|
||||||
|
return new StatisticsAdapter.ViewClockHolder(view);
|
||||||
|
} else {
|
||||||
|
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.stats_generic_item, parent, false);
|
||||||
|
return new StatisticsAdapter.ViewHolder(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
StatisticsAdapter.ViewHolder viewHolder = (StatisticsAdapter.ViewHolder) holder;
|
|
||||||
StatisticData statisticData = statisticDataList.get(position);
|
StatisticData statisticData = statisticDataList.get(position);
|
||||||
viewHolder.setData(statisticData);
|
if (getItemViewType(position) == CustomLayoutFieldType.CLOCK.value()) {
|
||||||
|
StatisticsAdapter.ViewClockHolder viewHolder = (StatisticsAdapter.ViewClockHolder) holder;
|
||||||
|
viewHolder.setData(statisticData);
|
||||||
|
} else {
|
||||||
|
StatisticsAdapter.ViewHolder viewHolder = (StatisticsAdapter.ViewHolder) holder;
|
||||||
|
viewHolder.setData(statisticData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,11 +63,15 @@ public class StatisticsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
return statisticDataList.get(position).getField().isWide() ? CustomLayoutFieldType.WIDE.value() : CustomLayoutFieldType.SHORT.value();
|
if (statisticDataList.get(position).getField().getType(context) == CustomLayoutFieldType.CLOCK) {
|
||||||
|
return CustomLayoutFieldType.CLOCK.value();
|
||||||
|
} else {
|
||||||
|
return CustomLayoutFieldType.GENERIC.value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isItemWide(int position) {
|
public boolean isItemWide(int position) {
|
||||||
return getItemViewType(position) == CustomLayoutFieldType.WIDE.value();
|
return statisticDataList.get(position).getField().isWide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StatisticData> swapData(List<StatisticData> data) {
|
public List<StatisticData> swapData(List<StatisticData> data) {
|
||||||
@@ -116,6 +133,25 @@ public class StatisticsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ViewClockHolder extends RecyclerView.ViewHolder {
|
||||||
|
final TextClock value;
|
||||||
|
final TextView descMain;
|
||||||
|
|
||||||
|
public ViewClockHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
value = itemView.findViewById(R.id.stats_clock);
|
||||||
|
descMain = itemView.findViewById(R.id.stats_description_main);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(StatisticData statisticData) {
|
||||||
|
if (statisticData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.value.setTextAppearance(context, statisticData.getField().isPrimary() ? R.style.StatsPrimaryValue : R.style.StatsSecondaryValue);
|
||||||
|
this.descMain.setTextAppearance(context, statisticData.getField().isPrimary() ? R.style.StatsPrimaryLabel : R.style.StatsSecondaryLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ViewRecordedHolder extends ViewHolder {
|
private class ViewRecordedHolder extends ViewHolder {
|
||||||
|
|
||||||
public ViewRecordedHolder(@NonNull View itemView) {
|
public ViewRecordedHolder(@NonNull View itemView) {
|
||||||
|
|||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
package de.dennisguse.opentracks.adapters;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
enum CustomLayoutFieldType {
|
public enum CustomLayoutFieldType {
|
||||||
SHORT(0),
|
GENERIC(1),
|
||||||
WIDE(1);
|
CLOCK(2);
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.dennisguse.opentracks.content.data;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
@@ -51,6 +52,14 @@ public class DataField {
|
|||||||
return isWide;
|
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 String toCsv() {
|
public String toCsv() {
|
||||||
String visible = this.isVisible ? YES_VALUE : NOT_VALUE;
|
String visible = this.isVisible ? YES_VALUE : NOT_VALUE;
|
||||||
String primary = this.isPrimary ? YES_VALUE : NOT_VALUE;
|
String primary = this.isPrimary ? YES_VALUE : NOT_VALUE;
|
||||||
@@ -94,6 +103,8 @@ public class DataField {
|
|||||||
return resources.getString(R.string.stats_sensors_cadence);
|
return resources.getString(R.string.stats_sensors_cadence);
|
||||||
} else if (key.equals(resources.getString(R.string.stats_custom_layout_power_key))) {
|
} else if (key.equals(resources.getString(R.string.stats_custom_layout_power_key))) {
|
||||||
return resources.getString(R.string.stats_sensors_power);
|
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 {
|
} else {
|
||||||
throw new RuntimeException("It doesn't exists a field with key: " + key);
|
throw new RuntimeException("It doesn't exists a field with key: " + key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import de.dennisguse.opentracks.settings.PreferencesUtils;
|
|||||||
public class StatisticsUtils {
|
public class StatisticsUtils {
|
||||||
|
|
||||||
public static String emptyValue(@NonNull Context context, @NonNull String statTitle) {
|
public static String emptyValue(@NonNull Context context, @NonNull String statTitle) {
|
||||||
if (PreferencesUtils.isKey(R.string.stats_custom_layout_total_time_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_moving_time_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_pace_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_moving_pace_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_pace_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_fastest_pace_key, statTitle)) {
|
if (PreferencesUtils.isKey(R.string.stats_custom_layout_total_time_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_moving_time_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_pace_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_moving_pace_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_pace_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_fastest_pace_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_clock_key, statTitle)) {
|
||||||
return context.getString(R.string.stats_empty_value_time);
|
return context.getString(R.string.stats_empty_value_time);
|
||||||
} else if (PreferencesUtils.isKey(R.string.stats_custom_layout_distance_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_speed_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_speed_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_max_speed_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_moving_speed_key, statTitle)) {
|
} else if (PreferencesUtils.isKey(R.string.stats_custom_layout_distance_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_speed_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_speed_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_max_speed_key, statTitle) || PreferencesUtils.isKey(R.string.stats_custom_layout_average_moving_speed_key, statTitle)) {
|
||||||
return context.getString(R.string.stats_empty_value_float);
|
return context.getString(R.string.stats_empty_value_float);
|
||||||
|
|||||||
@@ -137,6 +137,9 @@ public class StatisticDataBuilder {
|
|||||||
valueAndUnit = StringUtils.getPowerParts(context, null);
|
valueAndUnit = StringUtils.getPowerParts(context, null);
|
||||||
description = sensorUnknown;
|
description = sensorUnknown;
|
||||||
}
|
}
|
||||||
|
} else if (fieldKey.equals(context.getString(R.string.stats_custom_layout_clock_key))) {
|
||||||
|
title = context.getString(R.string.stats_clock);
|
||||||
|
valueAndUnit = new Pair<>(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueAndUnit == null) {
|
if (valueAndUnit == null) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
android:id="@+id/stats_layout"
|
android:id="@+id/stats_layout"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
layout="@layout/stats_item"
|
layout="@layout/stats_generic_item"
|
||||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||||
app:layout_constraintStart_toEndOf="@id/stats_iv_drag_indicator"
|
app:layout_constraintStart_toEndOf="@id/stats_iv_drag_indicator"
|
||||||
app:layout_constraintEnd_toStartOf="@id/stats_icon_show_status"
|
app:layout_constraintEnd_toStartOf="@id/stats_icon_show_status"
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:paddingTop="16dp">
|
||||||
|
|
||||||
|
<TextClock
|
||||||
|
android:id="@+id/stats_clock"
|
||||||
|
style="@style/StatsPrimaryValue"
|
||||||
|
android:value="@string/value_unknown"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
tools:text="00:00" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/stats_description_main"
|
||||||
|
style="@style/StatsPrimaryLabel"
|
||||||
|
android:text="@string/stats_clock"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/stats_clock" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -354,6 +354,7 @@
|
|||||||
<string name="stats_custom_layout_cadence_key" translatable="false">cadence</string>
|
<string name="stats_custom_layout_cadence_key" translatable="false">cadence</string>
|
||||||
<string name="stats_custom_layout_average_cadence_key" translatable="false">average_cadence</string>
|
<string name="stats_custom_layout_average_cadence_key" translatable="false">average_cadence</string>
|
||||||
<string name="stats_custom_layout_power_key" translatable="false">power</string>
|
<string name="stats_custom_layout_power_key" translatable="false">power</string>
|
||||||
|
<string name="stats_custom_layout_clock_key" translatable="false">time</string>
|
||||||
<!--
|
<!--
|
||||||
Default dataFields for stats layout customization in a set of arrays.
|
Default dataFields for stats layout customization in a set of arrays.
|
||||||
Every array has two items:
|
Every array has two items:
|
||||||
@@ -433,6 +434,10 @@
|
|||||||
<item>@string/stats_custom_layout_power_key</item>
|
<item>@string/stats_custom_layout_power_key</item>
|
||||||
<item>0,0,0</item>
|
<item>0,0,0</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="stats_custom_layout_fields_default_value_18">
|
||||||
|
<item>@string/stats_custom_layout_clock_key</item>
|
||||||
|
<item>0,0,0</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<!-- Stats empty values -->
|
<!-- Stats empty values -->
|
||||||
<string name="stats_empty_value_integer" translatable="false">0</string>
|
<string name="stats_empty_value_integer" translatable="false">0</string>
|
||||||
|
|||||||
@@ -428,6 +428,7 @@ limitations under the License.
|
|||||||
<string name="stats_sensors_heart_rate">Heart Rate</string>
|
<string name="stats_sensors_heart_rate">Heart Rate</string>
|
||||||
<string name="stats_sensors_cadence">Cadence</string>
|
<string name="stats_sensors_cadence">Cadence</string>
|
||||||
<string name="stats_sensors_power">Power</string>
|
<string name="stats_sensors_power">Power</string>
|
||||||
|
<string name="stats_clock">Clock</string>
|
||||||
<!-- Track -->
|
<!-- Track -->
|
||||||
<string name="track_name_format">Track %1$d</string>
|
<string name="track_name_format">Track %1$d</string>
|
||||||
<string name="track_recording_notification_accuracy">Location accuracy: %1$s</string>
|
<string name="track_recording_notification_accuracy">Location accuracy: %1$s</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user