mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Recording intervals received a null trackId because trackId is created in a Runnable.
Unit changed needs refreshing the intervals. Fixes #406.
This commit is contained in:
@@ -66,6 +66,9 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc
|
||||
// Preferences
|
||||
private boolean recordingTrackPaused;
|
||||
|
||||
// Intervals recording fragment needs Track.Id when the activity creates it.
|
||||
private OnTrackIdListener intervalsListener;
|
||||
|
||||
private final Runnable bindChangedCallback = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -82,6 +85,9 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc
|
||||
if (trackId == null) {
|
||||
// trackId isn't initialized -> leads a new recording.
|
||||
trackId = service.startNewTrack();
|
||||
if (intervalsListener != null) {
|
||||
intervalsListener.onTrackId(trackId);
|
||||
}
|
||||
} else {
|
||||
// trackId is initialized -> resumes the track.
|
||||
service.resumeTrack(trackId);
|
||||
@@ -410,4 +416,12 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnTrackIdListener {
|
||||
void onTrackId(Track.Id trackId);
|
||||
}
|
||||
|
||||
public void setTrackIdListener(OnTrackIdListener listener) {
|
||||
this.intervalsListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -90,4 +90,16 @@ public class IntervalsRecordedFragment extends Fragment implements IntervalListV
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitChanged() {
|
||||
if (viewModel != null) {
|
||||
LiveData<IntervalStatistics> liveData = viewModel.getIntervalStats(trackId, null);
|
||||
liveData.observe(getActivity(), intervalStatistics -> {
|
||||
if (intervalStatistics != null) {
|
||||
intervalListView.display(intervalStatistics.getIntervalList());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.TrackRecordingActivity;
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.util.UnitConversions;
|
||||
import de.dennisguse.opentracks.viewmodels.IntervalStatistics;
|
||||
@@ -23,7 +24,7 @@ import de.dennisguse.opentracks.views.IntervalListView;
|
||||
/**
|
||||
* A fragment to display the intervals from recording track.
|
||||
*/
|
||||
public class IntervalsRecordingFragment extends Fragment implements IntervalListView.IntervalListListener {
|
||||
public class IntervalsRecordingFragment extends Fragment implements IntervalListView.IntervalListListener, TrackRecordingActivity.OnTrackIdListener {
|
||||
|
||||
private static final String TAG = IntervalsRecordingFragment.class.getSimpleName();
|
||||
|
||||
@@ -68,6 +69,7 @@ public class IntervalsRecordingFragment extends Fragment implements IntervalList
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
trackId = getArguments().getParcelable(TRACK_ID_KEY);
|
||||
((TrackRecordingActivity) getActivity()).setTrackIdListener(this);
|
||||
|
||||
intervalHandler = new Handler();
|
||||
|
||||
@@ -124,4 +126,20 @@ public class IntervalsRecordingFragment extends Fragment implements IntervalList
|
||||
intervalChanged(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitChanged() {
|
||||
if (viewModel != null) {
|
||||
LiveData<IntervalStatistics> liveData = viewModel.getIntervalStats(trackId, null);
|
||||
liveData.observe(getActivity(), intervalStatistics -> {
|
||||
if (intervalStatistics != null) {
|
||||
intervalListView.display(intervalStatistics.getIntervalList());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackId(Track.Id trackId) {
|
||||
this.trackId = trackId;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
||||
public class IntervalStatisticsModel extends AndroidViewModel {
|
||||
|
||||
private MutableLiveData<IntervalStatistics> intervalStats = new MutableLiveData<>();
|
||||
private IntervalOption interval = IntervalOption.OPTION_1;
|
||||
|
||||
public IntervalStatisticsModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
@@ -35,6 +35,7 @@ public class IntervalListView extends LinearLayout {
|
||||
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(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile));
|
||||
listener.unitChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -92,6 +93,7 @@ public class IntervalListView extends LinearLayout {
|
||||
|
||||
public interface IntervalListListener {
|
||||
void intervalChanged(IntervalStatisticsModel.IntervalOption interval);
|
||||
void unitChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user