forked from upstream-mirrors/OpenTracks
Implement ViewBindings for Fragments.
This commit is contained in:
@@ -45,6 +45,10 @@ android {
|
|||||||
|
|
||||||
compileSdkVersion 30
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
buildFeatures {
|
||||||
|
viewBinding = true
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "de.dennisguse.opentracks"
|
applicationId "de.dennisguse.opentracks"
|
||||||
versionCode 3661
|
versionCode 3661
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import de.dennisguse.opentracks.content.TrackDataListener;
|
|||||||
import de.dennisguse.opentracks.content.data.Marker;
|
import de.dennisguse.opentracks.content.data.Marker;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
|
import de.dennisguse.opentracks.databinding.ChartBinding;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
|
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
|
||||||
import de.dennisguse.opentracks.util.LocationUtils;
|
import de.dennisguse.opentracks.util.LocationUtils;
|
||||||
@@ -73,6 +74,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
private TrackStatisticsUpdater trackStatisticsUpdater;
|
private TrackStatisticsUpdater trackStatisticsUpdater;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
|
||||||
|
private ChartBinding viewBinding;
|
||||||
|
|
||||||
//TODO Why is this needed?
|
//TODO Why is this needed?
|
||||||
private int recordingDistanceInterval;
|
private int recordingDistanceInterval;
|
||||||
private String category = "";
|
private String category = "";
|
||||||
@@ -147,15 +150,16 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.chart, container, false);
|
viewBinding = ChartBinding.inflate(inflater, container, false);
|
||||||
|
return viewBinding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
ViewGroup layout = getView().findViewById(R.id.chart_view_layout);
|
|
||||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||||
layout.addView(chartView, layoutParams);
|
viewBinding.chartViewLayout.addView(chartView, layoutParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -183,6 +187,12 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
layout.removeView(chartView);
|
layout.removeView(chartView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
viewBinding = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrackUpdated(Track track) {
|
public void onTrackUpdated(Track track) {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
|
|||||||
+12
-7
@@ -7,7 +7,6 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.GridView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
@@ -17,6 +16,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.databinding.ChooseActivityTypeBinding;
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,6 +39,8 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
|||||||
return TrackIconUtils.getAllIconValues().indexOf(iconValue);
|
return TrackIconUtils.getAllIconValues().indexOf(iconValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ChooseActivityTypeBinding viewBinding;
|
||||||
|
|
||||||
private final String preselectedCategory;
|
private final String preselectedCategory;
|
||||||
|
|
||||||
private ChooseActivityTypeCaller chooseActivityTypeCaller;
|
private ChooseActivityTypeCaller chooseActivityTypeCaller;
|
||||||
@@ -57,8 +59,7 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.choose_activity_type, container);
|
viewBinding = ChooseActivityTypeBinding.inflate(inflater, container, false);
|
||||||
GridView gridView = view.findViewById(R.id.choose_activity_type_grid_view);
|
|
||||||
|
|
||||||
List<Integer> imageIds = new ArrayList<>();
|
List<Integer> imageIds = new ArrayList<>();
|
||||||
for (String iconValue : TrackIconUtils.getAllIconValues()) {
|
for (String iconValue : TrackIconUtils.getAllIconValues()) {
|
||||||
@@ -66,15 +67,14 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
final ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(imageIds);
|
final ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(imageIds);
|
||||||
gridView.setAdapter(imageAdapter);
|
|
||||||
|
|
||||||
int position = getPosition(getContext(), preselectedCategory);
|
int position = getPosition(getContext(), preselectedCategory);
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
imageAdapter.setSelected(position);
|
imageAdapter.setSelected(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
gridView.setOnItemClickListener(this);
|
viewBinding.chooseActivityTypeGridView.setAdapter(imageAdapter);
|
||||||
return view;
|
viewBinding.chooseActivityTypeGridView.setOnItemClickListener(this);
|
||||||
|
return viewBinding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(@NonNull Context context) {
|
||||||
@@ -86,6 +86,11 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
viewBinding = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -25,6 +24,7 @@ import de.dennisguse.opentracks.content.TrackDataListener;
|
|||||||
import de.dennisguse.opentracks.content.data.Marker;
|
import de.dennisguse.opentracks.content.data.Marker;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
|
import de.dennisguse.opentracks.databinding.IntervalListViewBinding;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.util.UnitConversions;
|
import de.dennisguse.opentracks.util.UnitConversions;
|
||||||
import de.dennisguse.opentracks.viewmodels.IntervalStatistics;
|
import de.dennisguse.opentracks.viewmodels.IntervalStatistics;
|
||||||
@@ -38,7 +38,6 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
private static final String TAG = IntervalsFragment.class.getSimpleName();
|
private static final String TAG = IntervalsFragment.class.getSimpleName();
|
||||||
|
|
||||||
private IntervalStatisticsModel viewModel;
|
private IntervalStatisticsModel viewModel;
|
||||||
private ListView intervalListView;
|
|
||||||
protected IntervalStatisticsAdapter.StackMode stackModeListView;
|
protected IntervalStatisticsAdapter.StackMode stackModeListView;
|
||||||
private IntervalStatisticsModel.IntervalOption selectedInterval;
|
private IntervalStatisticsModel.IntervalOption selectedInterval;
|
||||||
|
|
||||||
@@ -47,11 +46,11 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
protected Spinner spinnerIntervals;
|
protected Spinner spinnerIntervals;
|
||||||
private ArrayAdapter<IntervalStatisticsModel.IntervalOption> spinnerAdapter;
|
private ArrayAdapter<IntervalStatisticsModel.IntervalOption> spinnerAdapter;
|
||||||
|
|
||||||
private TextView rateLabel;
|
|
||||||
|
|
||||||
private TrackDataHub trackDataHub;
|
private TrackDataHub trackDataHub;
|
||||||
private String category;
|
private String category;
|
||||||
|
|
||||||
|
private IntervalListViewBinding viewBinding;
|
||||||
|
|
||||||
protected final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
|
protected final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
|
||||||
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
||||||
intervalUnit = PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile);
|
intervalUnit = PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile);
|
||||||
@@ -68,7 +67,8 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.interval_list_view, container, false);
|
viewBinding = IntervalListViewBinding.inflate(inflater, container, false);
|
||||||
|
return viewBinding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,10 +78,7 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
PreferencesUtils.register(getContext(), sharedPreferenceChangeListener);
|
PreferencesUtils.register(getContext(), sharedPreferenceChangeListener);
|
||||||
intervalUnit = PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile);
|
intervalUnit = PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile);
|
||||||
|
|
||||||
rateLabel = view.findViewById(R.id.interval_rate);
|
viewBinding.intervalList.setEmptyView(view.findViewById(R.id.interval_list_empty_view));
|
||||||
|
|
||||||
intervalListView = view.findViewById(R.id.interval_list);
|
|
||||||
intervalListView.setEmptyView(view.findViewById(R.id.interval_list_empty_view));
|
|
||||||
|
|
||||||
stackModeListView = IntervalStatisticsAdapter.StackMode.STACK_FROM_TOP;
|
stackModeListView = IntervalStatisticsAdapter.StackMode.STACK_FROM_TOP;
|
||||||
|
|
||||||
@@ -133,13 +130,18 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
pauseTrackDataHub();
|
pauseTrackDataHub();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
viewBinding = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
PreferencesUtils.unregister(getContext(), sharedPreferenceChangeListener);
|
PreferencesUtils.unregister(getContext(), sharedPreferenceChangeListener);
|
||||||
|
|
||||||
intervalListView = null;
|
|
||||||
adapter = null;
|
adapter = null;
|
||||||
spinnerIntervals = null;
|
spinnerIntervals = null;
|
||||||
viewModel = null;
|
viewModel = null;
|
||||||
@@ -149,14 +151,14 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
* Update intervals through {@link IntervalStatisticsModel} view model.
|
* Update intervals through {@link IntervalStatisticsModel} view model.
|
||||||
*/
|
*/
|
||||||
protected synchronized void loadIntervals() {
|
protected synchronized void loadIntervals() {
|
||||||
if (viewModel == null || intervalListView == null) {
|
if (viewModel == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean metricUnits = PreferencesUtils.isMetricUnits(getContext()) ? true : false;
|
boolean metricUnits = PreferencesUtils.isMetricUnits(getContext());
|
||||||
IntervalStatistics intervalStatistics = viewModel.getIntervalStats(metricUnits, selectedInterval);
|
IntervalStatistics intervalStatistics = viewModel.getIntervalStats(metricUnits, selectedInterval);
|
||||||
adapter = new IntervalStatisticsAdapter(getContext(), intervalStatistics.getIntervalList(), category, stackModeListView);
|
adapter = new IntervalStatisticsAdapter(getContext(), intervalStatistics.getIntervalList(), category, stackModeListView);
|
||||||
intervalListView.setAdapter(adapter);
|
viewBinding.intervalList.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,10 +186,8 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
category = track != null ? track.getCategory() : "";
|
category = track != null ? track.getCategory() : "";
|
||||||
|
|
||||||
// Set rate label.
|
// Set rate label.
|
||||||
if (rateLabel != null) {
|
boolean reportSpeed = PreferencesUtils.isReportSpeed(getContext(), category);
|
||||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(getContext(), category);
|
viewBinding.intervalRate.setText(reportSpeed ? R.string.stats_speed : R.string.stats_pace);
|
||||||
rateLabel.setText(reportSpeed ? R.string.stats_speed : R.string.stats_pace);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import android.view.ViewGroup;
|
|||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.Animation.AnimationListener;
|
import android.view.animation.Animation.AnimationListener;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -42,6 +40,7 @@ import de.dennisguse.opentracks.MarkerEditActivity;
|
|||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.data.Marker;
|
import de.dennisguse.opentracks.content.data.Marker;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
|
import de.dennisguse.opentracks.databinding.MarkerDetailFragmentBinding;
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
import de.dennisguse.opentracks.util.ListItemUtils;
|
import de.dennisguse.opentracks.util.ListItemUtils;
|
||||||
import de.dennisguse.opentracks.util.MarkerUtils;
|
import de.dennisguse.opentracks.util.MarkerUtils;
|
||||||
@@ -64,10 +63,10 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
|
|
||||||
private ContentProviderUtils contentProviderUtils;
|
private ContentProviderUtils contentProviderUtils;
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
private ImageView photoView;
|
|
||||||
private ImageView textGradient;
|
|
||||||
private LinearLayout markerInfo;
|
|
||||||
private Marker marker;
|
private Marker marker;
|
||||||
|
|
||||||
|
private MarkerDetailFragmentBinding viewBinding;
|
||||||
|
|
||||||
private final Runnable hideText = new Runnable() {
|
private final Runnable hideText = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -84,12 +83,12 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Animation anim) {
|
public void onAnimationEnd(Animation anim) {
|
||||||
textGradient.setVisibility(View.GONE);
|
viewBinding.markerDetailMarkerTextGradient.setVisibility(View.GONE);
|
||||||
markerInfo.setVisibility(View.GONE);
|
viewBinding.markerDetailMarkerInfo.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
textGradient.startAnimation(animation);
|
viewBinding.markerDetailMarkerTextGradient.startAnimation(animation);
|
||||||
markerInfo.startAnimation(animation);
|
viewBinding.markerDetailMarkerInfo.startAnimation(animation);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,22 +118,18 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.marker_detail_fragment, container, false);
|
viewBinding = MarkerDetailFragmentBinding.inflate(inflater, container, false);
|
||||||
|
|
||||||
photoView = view.findViewById(R.id.marker_detail_marker_photo);
|
viewBinding.markerDetailMarkerPhoto.setOnClickListener(v -> {
|
||||||
textGradient = view.findViewById(R.id.marker_detail_marker_text_gradient);
|
|
||||||
markerInfo = view.findViewById(R.id.marker_detail_marker_info);
|
|
||||||
|
|
||||||
photoView.setOnClickListener(v -> {
|
|
||||||
handler.removeCallbacks(hideText);
|
handler.removeCallbacks(hideText);
|
||||||
int visibility = markerInfo.getVisibility() == View.GONE ? View.VISIBLE : View.GONE;
|
int visibility = viewBinding.markerDetailMarkerInfo.getVisibility() == View.GONE ? View.VISIBLE : View.GONE;
|
||||||
textGradient.setVisibility(visibility);
|
viewBinding.markerDetailMarkerTextGradient.setVisibility(visibility);
|
||||||
markerInfo.setVisibility(visibility);
|
viewBinding.markerDetailMarkerInfo.setVisibility(visibility);
|
||||||
if (visibility == View.VISIBLE) {
|
if (visibility == View.VISIBLE) {
|
||||||
handler.postDelayed(hideText, HIDE_TEXT_DELAY);
|
handler.postDelayed(hideText, HIDE_TEXT_DELAY);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return view;
|
return viewBinding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -153,6 +148,12 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
handler.removeCallbacks(hideText);
|
handler.removeCallbacks(hideText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
viewBinding = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMenuVisibility(boolean menuVisible) {
|
public void setMenuVisibility(boolean menuVisible) {
|
||||||
super.setMenuVisibility(menuVisible);
|
super.setMenuVisibility(menuVisible);
|
||||||
@@ -223,10 +224,10 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
boolean hasPhoto = marker.hasPhoto();
|
boolean hasPhoto = marker.hasPhoto();
|
||||||
if (hasPhoto) {
|
if (hasPhoto) {
|
||||||
handler.removeCallbacks(hideText);
|
handler.removeCallbacks(hideText);
|
||||||
photoView.setImageURI(marker.getPhotoURI());
|
viewBinding.markerDetailMarkerPhoto.setImageURI(marker.getPhotoURI());
|
||||||
handler.postDelayed(hideText, HIDE_TEXT_DELAY);
|
handler.postDelayed(hideText, HIDE_TEXT_DELAY);
|
||||||
} else {
|
} else {
|
||||||
photoView.setImageResource(MarkerUtils.ICON_ID);
|
viewBinding.markerDetailMarkerPhoto.setImageResource(MarkerUtils.ICON_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
setName(hasPhoto);
|
setName(hasPhoto);
|
||||||
|
|||||||
@@ -22,29 +22,28 @@ import android.util.Pair;
|
|||||||
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.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.constraintlayout.widget.Group;
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||||
|
import de.dennisguse.opentracks.databinding.StatisticsRecordedBinding;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment to display track statistics to the user.
|
* A fragment to display track statistics to the user for a recorded {@link Track}.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
|
//TODO During updateUI(): do not call PreferenceUtils (it is slow) rather use sharedPreferenceChangeListener.
|
||||||
public class StatisticsRecordedFragment extends Fragment {
|
public class StatisticsRecordedFragment extends Fragment {
|
||||||
|
|
||||||
private static final String TRACK_ID_KEY = "trackId";
|
private static final String TRACK_ID_KEY = "trackId";
|
||||||
@@ -54,6 +53,8 @@ public class StatisticsRecordedFragment extends Fragment {
|
|||||||
private Track.Id trackId;
|
private Track.Id trackId;
|
||||||
private ContentProviderUtils contentProviderUtils;
|
private ContentProviderUtils contentProviderUtils;
|
||||||
|
|
||||||
|
private StatisticsRecordedBinding viewBinding;
|
||||||
|
|
||||||
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
|
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
|
||||||
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
@@ -68,29 +69,10 @@ public class StatisticsRecordedFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.statistics_recorded, container, false);
|
viewBinding = StatisticsRecordedBinding.inflate(inflater, container, false);
|
||||||
|
return viewBinding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextView totalTimeValueView;
|
|
||||||
private TextView distanceValue;
|
|
||||||
private TextView distanceUnit;
|
|
||||||
private View activityLabel;
|
|
||||||
private ImageView activitySpinner;
|
|
||||||
private TextView movingTimeValue;
|
|
||||||
private TextView speedAvgLabel;
|
|
||||||
private TextView speedAvgValue;
|
|
||||||
private TextView speedAvgUnit;
|
|
||||||
private TextView speedMaxLabel;
|
|
||||||
private TextView speedMaxValue;
|
|
||||||
private TextView speedMaxUnit;
|
|
||||||
private TextView speedMovingLabel;
|
|
||||||
private TextView speedMovingValue;
|
|
||||||
private TextView speedMovingUnit;
|
|
||||||
|
|
||||||
private Group elevationGroup;
|
|
||||||
private TextView elevationTotalGainValue;
|
|
||||||
private TextView elevationTotalGainUnit;
|
|
||||||
|
|
||||||
public static StatisticsRecordedFragment newInstance(Track.Id trackId) {
|
public static StatisticsRecordedFragment newInstance(Track.Id trackId) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putParcelable(TRACK_ID_KEY, trackId);
|
bundle.putParcelable(TRACK_ID_KEY, trackId);
|
||||||
@@ -108,37 +90,6 @@ public class StatisticsRecordedFragment extends Fragment {
|
|||||||
contentProviderUtils = new ContentProviderUtils(getContext());
|
contentProviderUtils = new ContentProviderUtils(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
|
|
||||||
totalTimeValueView = view.findViewById(R.id.stats_total_time_value);
|
|
||||||
|
|
||||||
distanceValue = view.findViewById(R.id.stats_distance_value);
|
|
||||||
distanceUnit = view.findViewById(R.id.stats_distance_unit);
|
|
||||||
|
|
||||||
activityLabel = view.findViewById(R.id.stats_activity_type_label);
|
|
||||||
activitySpinner = view.findViewById(R.id.stats_activity_type_icon);
|
|
||||||
|
|
||||||
movingTimeValue = view.findViewById(R.id.stats_moving_time_value);
|
|
||||||
|
|
||||||
speedAvgLabel = view.findViewById(R.id.stats_average_speed_label);
|
|
||||||
speedAvgValue = view.findViewById(R.id.stats_average_speed_value);
|
|
||||||
speedAvgUnit = view.findViewById(R.id.stats_average_speed_unit);
|
|
||||||
|
|
||||||
speedMaxLabel = view.findViewById(R.id.stats_max_speed_label);
|
|
||||||
speedMaxValue = view.findViewById(R.id.stats_max_speed_value);
|
|
||||||
speedMaxUnit = view.findViewById(R.id.stats_max_speed_unit);
|
|
||||||
|
|
||||||
speedMovingLabel = view.findViewById(R.id.stats_moving_speed_label);
|
|
||||||
speedMovingValue = view.findViewById(R.id.stats_moving_speed_value);
|
|
||||||
speedMovingUnit = view.findViewById(R.id.stats_moving_speed_unit);
|
|
||||||
|
|
||||||
elevationGroup = view.findViewById(R.id.stats_elevation_group);
|
|
||||||
elevationTotalGainValue = view.findViewById(R.id.stats_elevation_gain_value);
|
|
||||||
elevationTotalGainUnit = view.findViewById(R.id.stats_elevation_gain_unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -150,34 +101,9 @@ public class StatisticsRecordedFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
viewBinding = null;
|
||||||
|
|
||||||
PreferencesUtils.unregister(getContext(), sharedPreferenceChangeListener);
|
PreferencesUtils.unregister(getContext(), sharedPreferenceChangeListener);
|
||||||
|
|
||||||
totalTimeValueView = null;
|
|
||||||
|
|
||||||
distanceValue = null;
|
|
||||||
distanceUnit = null;
|
|
||||||
|
|
||||||
activityLabel = null;
|
|
||||||
activitySpinner = null;
|
|
||||||
|
|
||||||
movingTimeValue = null;
|
|
||||||
|
|
||||||
speedAvgLabel = null;
|
|
||||||
speedAvgValue = null;
|
|
||||||
speedAvgUnit = null;
|
|
||||||
|
|
||||||
speedMaxLabel = null;
|
|
||||||
speedMaxValue = null;
|
|
||||||
speedMaxUnit = null;
|
|
||||||
|
|
||||||
speedMovingLabel = null;
|
|
||||||
speedMovingValue = null;
|
|
||||||
speedMovingUnit = null;
|
|
||||||
|
|
||||||
elevationGroup = null;
|
|
||||||
elevationTotalGainValue = null;
|
|
||||||
elevationTotalGainUnit = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadStatistics() {
|
public void loadStatistics() {
|
||||||
@@ -202,72 +128,66 @@ public class StatisticsRecordedFragment extends Fragment {
|
|||||||
double totalDistance = trackStatistics == null ? Double.NaN : trackStatistics.getTotalDistance();
|
double totalDistance = trackStatistics == null ? Double.NaN : trackStatistics.getTotalDistance();
|
||||||
Pair<String, String> parts = StringUtils.getDistanceParts(getContext(), totalDistance, metricUnits);
|
Pair<String, String> parts = StringUtils.getDistanceParts(getContext(), totalDistance, metricUnits);
|
||||||
|
|
||||||
distanceValue.setText(parts.first);
|
viewBinding.statsDistanceValue.setText(parts.first);
|
||||||
distanceUnit.setText(parts.second);
|
viewBinding.statsDistanceUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set activity type
|
// Set activity type
|
||||||
{
|
{
|
||||||
String trackIconValue = TrackIconUtils.getIconValue(getContext(), category);
|
String trackIconValue = TrackIconUtils.getIconValue(getContext(), category);
|
||||||
|
viewBinding.statsActivityTypeIcon.setEnabled(false);
|
||||||
activityLabel.setVisibility(trackIconValue != null ? View.VISIBLE : View.GONE);
|
viewBinding.statsActivityTypeIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), TrackIconUtils.getIconDrawable(trackIconValue)));
|
||||||
|
|
||||||
activitySpinner.setVisibility(trackIconValue != null ? View.VISIBLE : View.GONE);
|
|
||||||
activitySpinner.setEnabled(false);
|
|
||||||
if (trackIconValue != null) {
|
|
||||||
activitySpinner.setImageDrawable(ContextCompat.getDrawable(getContext(), TrackIconUtils.getIconDrawable(trackIconValue)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set time and start datetime
|
// Set time and start datetime
|
||||||
if (trackStatistics != null) {
|
if (trackStatistics != null) {
|
||||||
movingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getMovingTime()));
|
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getMovingTime()));
|
||||||
totalTimeValueView.setText(StringUtils.formatElapsedTime(trackStatistics.getTotalTime()));
|
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getTotalTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set average speed/pace
|
// Set average speed/pace
|
||||||
{
|
{
|
||||||
double speed = trackStatistics != null ? trackStatistics.getAverageSpeed() : Double.NaN;
|
double speed = trackStatistics != null ? trackStatistics.getAverageSpeed() : Double.NaN;
|
||||||
speedAvgLabel.setText(reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
|
viewBinding.statsAverageSpeedLabel.setText(reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedAvgValue.setText(parts.first);
|
viewBinding.statsAverageSpeedValue.setText(parts.first);
|
||||||
speedAvgUnit.setText(parts.second);
|
viewBinding.statsAverageSpeedUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set max speed/pace
|
// Set max speed/pace
|
||||||
{
|
{
|
||||||
double speed = trackStatistics == null ? Double.NaN : trackStatistics.getMaxSpeed();
|
double speed = trackStatistics == null ? Double.NaN : trackStatistics.getMaxSpeed();
|
||||||
|
|
||||||
speedMaxLabel.setText(reportSpeed ? R.string.stats_max_speed : R.string.stats_fastest_pace);
|
viewBinding.statsMaxSpeedLabel.setText(reportSpeed ? R.string.stats_max_speed : R.string.stats_fastest_pace);
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedMaxValue.setText(parts.first);
|
viewBinding.statsMaxSpeedValue.setText(parts.first);
|
||||||
speedMaxUnit.setText(parts.second);
|
viewBinding.statsMaxSpeedUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set moving speed/pace
|
// Set moving speed/pace
|
||||||
{
|
{
|
||||||
double speed = trackStatistics != null ? trackStatistics.getAverageMovingSpeed() : Double.NaN;
|
double speed = trackStatistics != null ? trackStatistics.getAverageMovingSpeed() : Double.NaN;
|
||||||
|
|
||||||
speedMovingLabel.setText(reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
|
viewBinding.statsMovingSpeedLabel.setText(reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedMovingValue.setText(parts.first);
|
viewBinding.statsMovingSpeedValue.setText(parts.first);
|
||||||
speedMovingUnit.setText(parts.second);
|
viewBinding.statsMovingSpeedUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set elevation gain
|
// Set elevation gain
|
||||||
{
|
{
|
||||||
// Make elevation visible?
|
// Make elevation visible?
|
||||||
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
||||||
elevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
viewBinding.statsElevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
Float elevationGain_m = trackStatistics != null ? trackStatistics.getTotalElevationGain() : null;
|
Float elevationGain_m = trackStatistics != null ? trackStatistics.getTotalElevationGain() : null;
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.formatElevation(getContext(), elevationGain_m, metricUnits);
|
Pair<String, String> parts = StringUtils.formatElevation(getContext(), elevationGain_m, metricUnits);
|
||||||
elevationTotalGainValue.setText(parts.first);
|
viewBinding.statsElevationGainValue.setText(parts.first);
|
||||||
elevationTotalGainUnit.setText(parts.second);
|
viewBinding.statsElevationGainUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-174
@@ -11,11 +11,8 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.constraintlayout.widget.Group;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
@@ -28,6 +25,7 @@ import de.dennisguse.opentracks.content.data.TrackPoint;
|
|||||||
import de.dennisguse.opentracks.content.sensor.SensorDataCycling;
|
import de.dennisguse.opentracks.content.sensor.SensorDataCycling;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataHeartRate;
|
import de.dennisguse.opentracks.content.sensor.SensorDataHeartRate;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
|
import de.dennisguse.opentracks.databinding.StatisticsRecordingBinding;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceInterface;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceInterface;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
@@ -38,11 +36,13 @@ import de.dennisguse.opentracks.util.TrackIconUtils;
|
|||||||
import de.dennisguse.opentracks.util.UnitConversions;
|
import de.dennisguse.opentracks.util.UnitConversions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment to display track statistics to the user.
|
* A fragment to display track statistics to the user for a currently recording {@link Track}.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
|
//TODO isRecording should not be relevant anymore as we now have StatisticRecordedFragment.
|
||||||
|
//TODO During updateUI(): do not call PreferenceUtils (it is slow) rather use sharedPreferenceChangeListener.
|
||||||
public class StatisticsRecordingFragment extends Fragment implements TrackDataListener {
|
public class StatisticsRecordingFragment extends Fragment implements TrackDataListener {
|
||||||
|
|
||||||
private static final String TAG = StatisticsRecordingFragment.class.getSimpleName();
|
private static final String TAG = StatisticsRecordingFragment.class.getSimpleName();
|
||||||
@@ -59,6 +59,8 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
private String category = "";
|
private String category = "";
|
||||||
|
|
||||||
|
private StatisticsRecordingBinding viewBinding;
|
||||||
|
|
||||||
public static Fragment newInstance() {
|
public static Fragment newInstance() {
|
||||||
return new StatisticsRecordingFragment();
|
return new StatisticsRecordingFragment();
|
||||||
}
|
}
|
||||||
@@ -80,19 +82,10 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.statistics_recording, container, false);
|
viewBinding = StatisticsRecordingBinding.inflate(inflater, container, false);
|
||||||
|
return viewBinding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Views */
|
|
||||||
private View sensorHorizontalLine;
|
|
||||||
private Group heartRateGroup;
|
|
||||||
private TextView heartRateValueView;
|
|
||||||
private TextView heartRateSensorView;
|
|
||||||
private Group cadenceGroup;
|
|
||||||
private TextView cadenceValueView;
|
|
||||||
private TextView cadenceSensorView;
|
|
||||||
|
|
||||||
private TextView totalTimeValueView;
|
|
||||||
private final Runnable updateUIeachSecond = new Runnable() {
|
private final Runnable updateUIeachSecond = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (isResumed() && isSelectedTrackRecording()) {
|
if (isResumed() && isSelectedTrackRecording()) {
|
||||||
@@ -105,84 +98,6 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private TextView distanceValue;
|
|
||||||
private TextView distanceUnit;
|
|
||||||
private View activityLabel;
|
|
||||||
private Spinner activitySpinner;
|
|
||||||
private TextView movingTimeValue;
|
|
||||||
private TextView speedAvgLabel;
|
|
||||||
private TextView speedAvgValue;
|
|
||||||
private TextView speedAvgUnit;
|
|
||||||
private TextView speedMaxLabel;
|
|
||||||
private TextView speedMaxValue;
|
|
||||||
private TextView speedMaxUnit;
|
|
||||||
private TextView speedMovingLabel;
|
|
||||||
private TextView speedMovingValue;
|
|
||||||
private TextView speedMovingUnit;
|
|
||||||
private TextView speedLabel;
|
|
||||||
private TextView speedValue;
|
|
||||||
private TextView speedUnit;
|
|
||||||
private Group elevationGroup;
|
|
||||||
private TextView elevationCurrentValue;
|
|
||||||
private TextView elevationCurrentUnit;
|
|
||||||
private TextView elevationTotalGainValue;
|
|
||||||
private TextView elevationTotalGainUnit;
|
|
||||||
private Group coordinateGroup;
|
|
||||||
private TextView latitudeValue;
|
|
||||||
private TextView longitudeValue;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
|
|
||||||
sensorHorizontalLine = view.findViewById(R.id.stats_sensor_horizontal_line);
|
|
||||||
|
|
||||||
heartRateGroup = view.findViewById(R.id.stats_sensor_heart_rate_group);
|
|
||||||
heartRateValueView = view.findViewById(R.id.stats_sensor_heart_rate_value);
|
|
||||||
heartRateSensorView = view.findViewById(R.id.stats_sensor_heart_rate_sensor_value);
|
|
||||||
|
|
||||||
cadenceGroup = view.findViewById(R.id.stats_sensor_cadence_group);
|
|
||||||
cadenceValueView = view.findViewById(R.id.stats_sensor_cadence_value);
|
|
||||||
cadenceSensorView = view.findViewById(R.id.stats_sensor_cadence_sensor_value);
|
|
||||||
|
|
||||||
totalTimeValueView = view.findViewById(R.id.stats_total_time_value);
|
|
||||||
|
|
||||||
distanceValue = view.findViewById(R.id.stats_distance_value);
|
|
||||||
distanceUnit = view.findViewById(R.id.stats_distance_unit);
|
|
||||||
|
|
||||||
activityLabel = view.findViewById(R.id.stats_activity_type_label);
|
|
||||||
activitySpinner = view.findViewById(R.id.stats_activity_type_icon);
|
|
||||||
|
|
||||||
movingTimeValue = view.findViewById(R.id.stats_moving_time_value);
|
|
||||||
|
|
||||||
speedAvgLabel = view.findViewById(R.id.stats_average_speed_label);
|
|
||||||
speedAvgValue = view.findViewById(R.id.stats_average_speed_value);
|
|
||||||
speedAvgUnit = view.findViewById(R.id.stats_average_speed_unit);
|
|
||||||
|
|
||||||
speedMaxLabel = view.findViewById(R.id.stats_max_speed_label);
|
|
||||||
speedMaxValue = view.findViewById(R.id.stats_max_speed_value);
|
|
||||||
speedMaxUnit = view.findViewById(R.id.stats_max_speed_unit);
|
|
||||||
|
|
||||||
speedMovingLabel = view.findViewById(R.id.stats_moving_speed_label);
|
|
||||||
speedMovingValue = view.findViewById(R.id.stats_moving_speed_value);
|
|
||||||
speedMovingUnit = view.findViewById(R.id.stats_moving_speed_unit);
|
|
||||||
|
|
||||||
speedLabel = view.findViewById(R.id.stats_speed_label);
|
|
||||||
speedValue = view.findViewById(R.id.stats_speed_value);
|
|
||||||
speedUnit = view.findViewById(R.id.stats_speed_unit);
|
|
||||||
|
|
||||||
elevationGroup = view.findViewById(R.id.stats_elevation_group);
|
|
||||||
elevationCurrentValue = view.findViewById(R.id.stats_elevation_current_value);
|
|
||||||
elevationCurrentUnit = view.findViewById(R.id.stats_elevation_current_unit);
|
|
||||||
|
|
||||||
elevationTotalGainValue = view.findViewById(R.id.stats_elevation_gain_value);
|
|
||||||
elevationTotalGainUnit = view.findViewById(R.id.stats_elevation_gain_unit);
|
|
||||||
|
|
||||||
coordinateGroup = view.findViewById(R.id.stats_coordinate_group);
|
|
||||||
|
|
||||||
latitudeValue = view.findViewById(R.id.stats_latitude_value);
|
|
||||||
longitudeValue = view.findViewById(R.id.stats_longitude_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
@@ -234,52 +149,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
sensorHorizontalLine = null;
|
viewBinding = null;
|
||||||
|
|
||||||
heartRateGroup = null;
|
|
||||||
heartRateValueView = null;
|
|
||||||
heartRateSensorView = null;
|
|
||||||
cadenceGroup = null;
|
|
||||||
cadenceValueView = null;
|
|
||||||
cadenceSensorView = null;
|
|
||||||
|
|
||||||
totalTimeValueView = null;
|
|
||||||
|
|
||||||
distanceValue = null;
|
|
||||||
distanceUnit = null;
|
|
||||||
|
|
||||||
activityLabel = null;
|
|
||||||
activitySpinner = null;
|
|
||||||
|
|
||||||
movingTimeValue = null;
|
|
||||||
|
|
||||||
speedAvgLabel = null;
|
|
||||||
speedAvgValue = null;
|
|
||||||
speedAvgUnit = null;
|
|
||||||
|
|
||||||
speedMaxLabel = null;
|
|
||||||
speedMaxValue = null;
|
|
||||||
speedMaxUnit = null;
|
|
||||||
|
|
||||||
speedMovingLabel = null;
|
|
||||||
speedMovingValue = null;
|
|
||||||
speedMovingUnit = null;
|
|
||||||
|
|
||||||
speedLabel = null;
|
|
||||||
speedValue = null;
|
|
||||||
speedUnit = null;
|
|
||||||
|
|
||||||
elevationGroup = null;
|
|
||||||
elevationCurrentValue = null;
|
|
||||||
elevationCurrentUnit = null;
|
|
||||||
|
|
||||||
elevationTotalGainValue = null;
|
|
||||||
elevationTotalGainUnit = null;
|
|
||||||
|
|
||||||
coordinateGroup = null;
|
|
||||||
|
|
||||||
latitudeValue = null;
|
|
||||||
longitudeValue = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -419,7 +289,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
private void setHeartRateSensorData(SensorDataSet sensorDataSet) {
|
private void setHeartRateSensorData(SensorDataSet sensorDataSet) {
|
||||||
int isVisible = sensorDataSet != null ? View.VISIBLE : View.GONE;
|
int isVisible = sensorDataSet != null ? View.VISIBLE : View.GONE;
|
||||||
heartRateGroup.setVisibility(isVisible);
|
viewBinding.statsSensorHeartRateGroup.setVisibility(isVisible);
|
||||||
setVisibilitySensorHorizontalLine();
|
setVisibilitySensorHorizontalLine();
|
||||||
|
|
||||||
String sensorValue = getContext().getString(R.string.value_unknown);
|
String sensorValue = getContext().getString(R.string.value_unknown);
|
||||||
@@ -433,13 +303,13 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
heartRateSensorView.setText(sensorName);
|
viewBinding.statsSensorHeartRateSensorValue.setText(sensorName);
|
||||||
heartRateValueView.setText(sensorValue);
|
viewBinding.statsSensorHeartRateValue.setText(sensorValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCadenceSensorData(SensorDataSet sensorDataSet) {
|
private void setCadenceSensorData(SensorDataSet sensorDataSet) {
|
||||||
int isVisible = sensorDataSet != null ? View.VISIBLE : View.GONE;
|
int isVisible = sensorDataSet != null ? View.VISIBLE : View.GONE;
|
||||||
cadenceGroup.setVisibility(isVisible);
|
viewBinding.statsSensorCadenceGroup.setVisibility(isVisible);
|
||||||
setVisibilitySensorHorizontalLine();
|
setVisibilitySensorHorizontalLine();
|
||||||
|
|
||||||
String sensorValue = getContext().getString(R.string.value_unknown);
|
String sensorValue = getContext().getString(R.string.value_unknown);
|
||||||
@@ -453,8 +323,8 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cadenceSensorView.setText(sensorName);
|
viewBinding.statsSensorCadenceSensorValue.setText(sensorName);
|
||||||
cadenceValueView.setText(sensorValue);
|
viewBinding.statsSensorCadenceValue.setText(sensorValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set elevation gain
|
// Set elevation gain
|
||||||
@@ -473,16 +343,16 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.formatElevation(getContext(), totalElevationGain, metricUnits);
|
Pair<String, String> parts = StringUtils.formatElevation(getContext(), totalElevationGain, metricUnits);
|
||||||
elevationTotalGainValue.setText(parts.first);
|
viewBinding.statsElevationGainValue.setText(parts.first);
|
||||||
elevationTotalGainUnit.setText(parts.second);
|
viewBinding.statsElevationGainUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If cadence and hear rate groups are invisible then sensor horizontal line hast to be invisible too.
|
* If cadence and hear rate groups are invisible then sensor horizontal line hast to be invisible too.
|
||||||
*/
|
*/
|
||||||
private void setVisibilitySensorHorizontalLine() {
|
private void setVisibilitySensorHorizontalLine() {
|
||||||
if (cadenceGroup.getVisibility() != View.VISIBLE && heartRateGroup.getVisibility() != View.VISIBLE) {
|
if (viewBinding.statsSensorCadenceGroup.getVisibility() != View.VISIBLE && viewBinding.statsSensorHeartRateGroup.getVisibility() != View.VISIBLE) {
|
||||||
sensorHorizontalLine.setVisibility(View.GONE);
|
viewBinding.statsSensorHorizontalLine.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,59 +380,59 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
double totalDistance = lastTrackStatistics == null ? Double.NaN : lastTrackStatistics.getTotalDistance();
|
double totalDistance = lastTrackStatistics == null ? Double.NaN : lastTrackStatistics.getTotalDistance();
|
||||||
Pair<String, String> parts = StringUtils.getDistanceParts(getContext(), totalDistance, metricUnits);
|
Pair<String, String> parts = StringUtils.getDistanceParts(getContext(), totalDistance, metricUnits);
|
||||||
|
|
||||||
distanceValue.setText(parts.first);
|
viewBinding.statsDistanceValue.setText(parts.first);
|
||||||
distanceUnit.setText(parts.second);
|
viewBinding.statsDistanceUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set activity type
|
// Set activity type
|
||||||
{
|
{
|
||||||
activitySpinner.setEnabled(isRecording);
|
viewBinding.statsActivityTypeIcon.setEnabled(isRecording);
|
||||||
TrackIconUtils.setIconSpinner(activitySpinner, trackIconValue);
|
TrackIconUtils.setIconSpinner(viewBinding.statsActivityTypeIcon, trackIconValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set time
|
// Set time
|
||||||
if (lastTrackStatistics != null) {
|
if (lastTrackStatistics != null) {
|
||||||
movingTimeValue.setText(StringUtils.formatElapsedTime(lastTrackStatistics.getMovingTime()));
|
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(lastTrackStatistics.getMovingTime()));
|
||||||
updateTotalTime();
|
updateTotalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set average speed/pace
|
// Set average speed/pace
|
||||||
{
|
{
|
||||||
double speed = lastTrackStatistics != null ? lastTrackStatistics.getAverageSpeed() : Double.NaN;
|
double speed = lastTrackStatistics != null ? lastTrackStatistics.getAverageSpeed() : Double.NaN;
|
||||||
speedAvgLabel.setText(reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
|
viewBinding.statsAverageSpeedLabel.setText(reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedAvgValue.setText(parts.first);
|
viewBinding.statsAverageSpeedValue.setText(parts.first);
|
||||||
speedAvgUnit.setText(parts.second);
|
viewBinding.statsAverageSpeedUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set max speed/pace
|
// Set max speed/pace
|
||||||
{
|
{
|
||||||
double speed = lastTrackStatistics == null ? Double.NaN : lastTrackStatistics.getMaxSpeed();
|
double speed = lastTrackStatistics == null ? Double.NaN : lastTrackStatistics.getMaxSpeed();
|
||||||
|
|
||||||
speedMaxLabel.setText(reportSpeed ? R.string.stats_max_speed : R.string.stats_fastest_pace);
|
viewBinding.statsMaxSpeedLabel.setText(reportSpeed ? R.string.stats_max_speed : R.string.stats_fastest_pace);
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedMaxValue.setText(parts.first);
|
viewBinding.statsMaxSpeedValue.setText(parts.first);
|
||||||
speedMaxUnit.setText(parts.second);
|
viewBinding.statsMaxSpeedUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set moving speed/pace
|
// Set moving speed/pace
|
||||||
{
|
{
|
||||||
double speed = lastTrackStatistics != null ? lastTrackStatistics.getAverageMovingSpeed() : Double.NaN;
|
double speed = lastTrackStatistics != null ? lastTrackStatistics.getAverageMovingSpeed() : Double.NaN;
|
||||||
|
|
||||||
speedMovingLabel.setText(reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
|
viewBinding.statsMovingSpeedLabel.setText(reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedMovingValue.setText(parts.first);
|
viewBinding.statsMovingSpeedValue.setText(parts.first);
|
||||||
speedMovingUnit.setText(parts.second);
|
viewBinding.statsMovingSpeedUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set elevation (gain)
|
// Set elevation (gain)
|
||||||
{
|
{
|
||||||
// Make elevation visible?
|
// Make elevation visible?
|
||||||
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
||||||
elevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
viewBinding.statsElevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,7 +443,7 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
} else {
|
} else {
|
||||||
totalTime = lastTrackStatistics.getTotalTime();
|
totalTime = lastTrackStatistics.getTotalTime();
|
||||||
}
|
}
|
||||||
totalTimeValueView.setText(StringUtils.formatElapsedTime(totalTime));
|
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(totalTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -598,28 +468,28 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
|
|
||||||
// Set elevation
|
// Set elevation
|
||||||
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
boolean showElevation = PreferencesUtils.isShowStatsElevation(getContext());
|
||||||
elevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
viewBinding.statsElevationGroup.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
if (showElevation) {
|
if (showElevation) {
|
||||||
// Current elevation
|
// Current elevation
|
||||||
Float altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? (float) lastTrackPoint.getAltitude() : null;
|
Float altitude = lastTrackPoint != null && lastTrackPoint.hasAltitude() ? (float) lastTrackPoint.getAltitude() : null;
|
||||||
Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits);
|
Pair<String, String> parts = StringUtils.formatElevation(getContext(), altitude, metricUnits);
|
||||||
elevationCurrentValue.setText(parts.first);
|
viewBinding.statsElevationCurrentValue.setText(parts.first);
|
||||||
elevationCurrentUnit.setText(parts.second);
|
viewBinding.statsElevationCurrentUnit.setText(parts.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set coordinate
|
// Set coordinate
|
||||||
boolean showCoordinate = PreferencesUtils.isStatsShowCoordinate(getContext());
|
boolean showCoordinate = PreferencesUtils.isStatsShowCoordinate(getContext());
|
||||||
|
|
||||||
coordinateGroup.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
viewBinding.statsCoordinateGroup.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
||||||
if (showCoordinate) {
|
if (showCoordinate) {
|
||||||
double latitude = lastTrackPoint != null ? lastTrackPoint.getLatitude() : Double.NaN;
|
double latitude = lastTrackPoint != null ? lastTrackPoint.getLatitude() : Double.NaN;
|
||||||
String latitudeText = Double.isNaN(latitude) || Double.isInfinite(latitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(latitude);
|
String latitudeText = Double.isNaN(latitude) || Double.isInfinite(latitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(latitude);
|
||||||
latitudeValue.setText(latitudeText);
|
viewBinding.statsLatitudeValue.setText(latitudeText);
|
||||||
|
|
||||||
double longitude = lastTrackPoint != null ? lastTrackPoint.getLongitude() : Double.NaN;
|
double longitude = lastTrackPoint != null ? lastTrackPoint.getLongitude() : Double.NaN;
|
||||||
String longitudeText = Double.isNaN(longitude) || Double.isInfinite(longitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(longitude);
|
String longitudeText = Double.isNaN(longitude) || Double.isInfinite(longitude) ? getContext().getString(R.string.value_unknown) : StringUtils.formatCoordinate(longitude);
|
||||||
longitudeValue.setText(longitudeText);
|
viewBinding.statsLongitudeValue.setText(longitudeText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,10 +497,10 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
boolean metricUnits = PreferencesUtils.isMetricUnits(getContext());
|
boolean metricUnits = PreferencesUtils.isMetricUnits(getContext());
|
||||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(getContext(), category);
|
boolean reportSpeed = PreferencesUtils.isReportSpeed(getContext(), category);
|
||||||
|
|
||||||
speedLabel.setText(reportSpeed ? R.string.stats_speed : R.string.stats_pace);
|
viewBinding.statsSpeedLabel.setText(reportSpeed ? R.string.stats_speed : R.string.stats_pace);
|
||||||
|
|
||||||
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
Pair<String, String> parts = StringUtils.getSpeedParts(getContext(), speed, metricUnits, reportSpeed);
|
||||||
speedValue.setText(parts.first);
|
viewBinding.statsSpeedValue.setText(parts.first);
|
||||||
speedUnit.setText(parts.second);
|
viewBinding.statsSpeedLabel.setText(parts.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user