mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Interval statistics: listen preferred units change (metric/imperial) and recreate intervals.
This commit is contained in:
@@ -63,6 +63,9 @@ public class StatisticsRecordedFragment extends Fragment implements IntervalList
|
||||
|
||||
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 (viewModel != null) {
|
||||
viewModel.invalidate();
|
||||
}
|
||||
if (isResumed()) {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
if (isResumed()) {
|
||||
@@ -187,16 +190,12 @@ public class StatisticsRecordedFragment extends Fragment implements IntervalList
|
||||
loadStatistics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
PreferencesUtils.unregister(getContext(), sharedPreferenceChangeListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
PreferencesUtils.unregister(getContext(), sharedPreferenceChangeListener);
|
||||
|
||||
totalTimeValueView = null;
|
||||
|
||||
distanceValue = null;
|
||||
@@ -218,6 +217,10 @@ public class StatisticsRecordedFragment extends Fragment implements IntervalList
|
||||
speedMovingLabel = null;
|
||||
speedMovingValue = null;
|
||||
speedMovingUnit = null;
|
||||
|
||||
intervalListView.destroy();
|
||||
intervalListView = null;
|
||||
viewModel = null;
|
||||
}
|
||||
|
||||
public void loadStatistics() {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package de.dennisguse.opentracks.viewmodels;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ public class IntervalStatisticsModel extends AndroidViewModel {
|
||||
return getIntervalStats(trackId, interval);
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
intervalStats = null;
|
||||
}
|
||||
|
||||
private void loadIntervalStats(long trackId) {
|
||||
new Thread(() -> {
|
||||
Context context = getApplication().getApplicationContext();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.dennisguse.opentracks.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
@@ -26,10 +27,19 @@ public class IntervalListView extends LinearLayout {
|
||||
private Context context;
|
||||
private IntervalListListener listener;
|
||||
|
||||
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 (spinnerIntervalsUnit != null) {
|
||||
spinnerIntervalsUnit.setText(PreferencesUtils.isMetricUnits(context) ? context.getString(R.string.unit_kilometer) : context.getString(R.string.unit_mile));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public IntervalListView(Context context, IntervalListListener listener) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.listener = listener;
|
||||
PreferencesUtils.register(getContext(), sharedPreferenceChangeListener);
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -55,6 +65,16 @@ public class IntervalListView extends LinearLayout {
|
||||
});
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
PreferencesUtils.unregister(getContext(), sharedPreferenceChangeListener);
|
||||
adapter = null;
|
||||
linearLayoutIntervals = null;
|
||||
spinnerIntervals = null;
|
||||
spinnerIntervalsUnit = null;
|
||||
context = null;
|
||||
listener = null;
|
||||
}
|
||||
|
||||
public void display(List<IntervalStatistics.Interval> intervalList) {
|
||||
if (intervalList != null) {
|
||||
adapter = new IntervalStatisticsAdapter(getContext(), intervalList);
|
||||
|
||||
Reference in New Issue
Block a user