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.
|
* @param interval intervals will split in this interval if not null. If it's null then view model will use the default one.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
public void intervalChanged(@Nullable IntervalStatisticsModel.IntervalOption interval) {
|
||||||
if (viewModel == null || intervalListView == null) {
|
if (viewModel == null || intervalListView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.invalidate();
|
LiveData<IntervalStatistics> liveData = viewModel.getIntervalStats(trackId, interval);
|
||||||
LiveData<IntervalStatistics> liveData;
|
|
||||||
if (interval == null) {
|
|
||||||
liveData = viewModel.getIntervalStats(trackId);
|
|
||||||
} else {
|
|
||||||
liveData = viewModel.getIntervalStats(trackId, interval);
|
|
||||||
}
|
|
||||||
liveData.observe(getActivity(), intervalStatistics -> {
|
liveData.observe(getActivity(), intervalStatistics -> {
|
||||||
if (intervalStatistics != null) {
|
if (intervalStatistics != null) {
|
||||||
intervalListView.display(intervalStatistics.getIntervalList());
|
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.
|
* @param interval intervals will split in this interval if not null. If it's null then view model will use the default one.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
public void intervalChanged(@Nullable IntervalStatisticsModel.IntervalOption interval) {
|
||||||
if (viewModel == null || intervalListView == null) {
|
if (viewModel == null || intervalListView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.invalidate();
|
LiveData<IntervalStatistics> liveData = viewModel.getIntervalStats(trackId, interval);
|
||||||
LiveData<IntervalStatistics> liveData;
|
|
||||||
if (interval == null) {
|
|
||||||
liveData = viewModel.getIntervalStats(trackId);
|
|
||||||
} else {
|
|
||||||
liveData = viewModel.getIntervalStats(trackId, interval);
|
|
||||||
}
|
|
||||||
liveData.observe(getActivity(), intervalStatistics -> {
|
liveData.observe(getActivity(), intervalStatistics -> {
|
||||||
if (intervalStatistics != null) {
|
if (intervalStatistics != null) {
|
||||||
intervalListView.display(intervalStatistics.getIntervalList());
|
intervalListView.display(intervalStatistics.getIntervalList());
|
||||||
|
|||||||
@@ -24,32 +24,22 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
|||||||
public class IntervalStatisticsModel extends AndroidViewModel {
|
public class IntervalStatisticsModel extends AndroidViewModel {
|
||||||
|
|
||||||
private MutableLiveData<IntervalStatistics> intervalStats = new MutableLiveData<>();
|
private MutableLiveData<IntervalStatistics> intervalStats = new MutableLiveData<>();
|
||||||
private IntervalOption interval = IntervalOption.OPTION_1;
|
|
||||||
|
|
||||||
public IntervalStatisticsModel(@NonNull Application application) {
|
public IntervalStatisticsModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<IntervalStatistics> getIntervalStats(@Nullable Track.Id trackId, IntervalOption interval) {
|
public LiveData<IntervalStatistics> getIntervalStats(@Nullable Track.Id trackId, @Nullable IntervalOption interval) {
|
||||||
if (trackId != null && this.interval != interval) {
|
if (interval == null) {
|
||||||
this.interval = interval;
|
interval = IntervalOption.OPTION_1;
|
||||||
loadIntervalStats(trackId);
|
}
|
||||||
|
if (trackId != null) {
|
||||||
|
loadIntervalStats(trackId, interval);
|
||||||
}
|
}
|
||||||
return intervalStats;
|
return intervalStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<IntervalStatistics> getIntervalStats(Track.Id trackId) {
|
private void loadIntervalStats(final Track.Id trackId, IntervalOption interval) {
|
||||||
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) {
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
Context context = getApplication().getApplicationContext();
|
Context context = getApplication().getApplicationContext();
|
||||||
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||||
|
|||||||
Reference in New Issue
Block a user