forked from upstream-mirrors/OpenTracks
@@ -78,18 +78,12 @@ public class IntervalsRecordedFragment extends Fragment implements IntervalListV
|
||||
* @param interval intervals will split in this interval if not null. If it's null then view model will use the default one.
|
||||
*/
|
||||
@Override
|
||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
||||
public void intervalChanged(@Nullable IntervalStatisticsModel.IntervalOption interval) {
|
||||
if (viewModel == null || intervalListView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.invalidate();
|
||||
LiveData<IntervalStatistics> liveData;
|
||||
if (interval == null) {
|
||||
liveData = viewModel.getIntervalStats(trackId);
|
||||
} else {
|
||||
liveData = viewModel.getIntervalStats(trackId, interval);
|
||||
}
|
||||
LiveData<IntervalStatistics> liveData = viewModel.getIntervalStats(trackId, interval);
|
||||
liveData.observe(getActivity(), intervalStatistics -> {
|
||||
if (intervalStatistics != null) {
|
||||
intervalListView.display(intervalStatistics.getIntervalList());
|
||||
|
||||
@@ -107,18 +107,12 @@ public class IntervalsRecordingFragment extends Fragment implements IntervalList
|
||||
* @param interval intervals will split in this interval if not null. If it's null then view model will use the default one.
|
||||
*/
|
||||
@Override
|
||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
||||
public void intervalChanged(@Nullable IntervalStatisticsModel.IntervalOption interval) {
|
||||
if (viewModel == null || intervalListView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.invalidate();
|
||||
LiveData<IntervalStatistics> liveData;
|
||||
if (interval == null) {
|
||||
liveData = viewModel.getIntervalStats(trackId);
|
||||
} else {
|
||||
liveData = viewModel.getIntervalStats(trackId, interval);
|
||||
}
|
||||
LiveData<IntervalStatistics> liveData = viewModel.getIntervalStats(trackId, interval);
|
||||
liveData.observe(getActivity(), intervalStatistics -> {
|
||||
if (intervalStatistics != null) {
|
||||
intervalListView.display(intervalStatistics.getIntervalList());
|
||||
|
||||
@@ -24,32 +24,22 @@ 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);
|
||||
}
|
||||
|
||||
public LiveData<IntervalStatistics> getIntervalStats(@Nullable Track.Id trackId, IntervalOption interval) {
|
||||
if (trackId != null && this.interval != interval) {
|
||||
this.interval = interval;
|
||||
loadIntervalStats(trackId);
|
||||
public LiveData<IntervalStatistics> getIntervalStats(@Nullable Track.Id trackId, @Nullable IntervalOption interval) {
|
||||
if (interval == null) {
|
||||
interval = IntervalOption.OPTION_1;
|
||||
}
|
||||
if (trackId != null) {
|
||||
loadIntervalStats(trackId, interval);
|
||||
}
|
||||
return intervalStats;
|
||||
}
|
||||
|
||||
public LiveData<IntervalStatistics> getIntervalStats(Track.Id trackId) {
|
||||
return getIntervalStats(trackId, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method when you want to force the view model to re-load intervals.
|
||||
*/
|
||||
public void invalidate() {
|
||||
intervalStats = new MutableLiveData<>();
|
||||
}
|
||||
|
||||
private void loadIntervalStats(final Track.Id trackId) {
|
||||
private void loadIntervalStats(final Track.Id trackId, IntervalOption interval) {
|
||||
new Thread(() -> {
|
||||
Context context = getApplication().getApplicationContext();
|
||||
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||
|
||||
Reference in New Issue
Block a user