mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Interval Stats: fixed NPE introduced in 25ef0ecad1.
Includes some refactoring.
This commit is contained in:
@@ -167,6 +167,7 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc
|
||||
//Activity was recreated.
|
||||
trackId = savedInstanceState.getParcelable(EXTRA_TRACK_ID);
|
||||
} else {
|
||||
// Resume a track
|
||||
trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID);
|
||||
if (trackId != null && contentProviderUtils.getTrack(trackId) == null) {
|
||||
Log.w(TAG, "TrackId does not exists; cannot continue the recording.");
|
||||
|
||||
@@ -60,7 +60,7 @@ public class IntervalsRecordedFragment extends Fragment implements IntervalListV
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(IntervalStatisticsModel.class);
|
||||
|
||||
updateIntervals(null);
|
||||
intervalChanged(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +77,8 @@ 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.
|
||||
*/
|
||||
private void updateIntervals(@Nullable IntervalStatisticsModel.IntervalOption interval) {
|
||||
@Override
|
||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
||||
if (viewModel == null || intervalListView == null) {
|
||||
return;
|
||||
}
|
||||
@@ -95,9 +96,4 @@ public class IntervalsRecordedFragment extends Fragment implements IntervalListV
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
||||
updateIntervals(interval);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,8 @@ 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.
|
||||
*/
|
||||
private void updateIntervals(@Nullable IntervalStatisticsModel.IntervalOption interval) {
|
||||
@Override
|
||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
||||
if (viewModel == null || intervalListView == null) {
|
||||
return;
|
||||
}
|
||||
@@ -126,11 +127,7 @@ public class IntervalsRecordingFragment extends Fragment implements IntervalList
|
||||
}
|
||||
|
||||
private void updateIntervals() {
|
||||
updateIntervals(null);
|
||||
intervalChanged(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void intervalChanged(IntervalStatisticsModel.IntervalOption interval) {
|
||||
updateIntervals(interval);
|
||||
}
|
||||
}
|
||||
@@ -109,8 +109,6 @@ public class StatisticsRecordedFragment extends Fragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
ViewGroup rootView = view.findViewById(R.id.root_view);
|
||||
|
||||
totalTimeValueView = view.findViewById(R.id.stats_total_time_value);
|
||||
|
||||
distanceValue = view.findViewById(R.id.stats_distance_value);
|
||||
|
||||
@@ -48,8 +48,6 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
||||
|
||||
private static final String TAG = StatisticsRecordingFragment.class.getSimpleName();
|
||||
|
||||
private static final String TRACK_ID_KEY = "trackId";
|
||||
|
||||
private static final long UI_UPDATE_INTERVAL = UnitConversions.ONE_SECOND_MS;
|
||||
|
||||
private TrackDataHub trackDataHub;
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
@@ -22,17 +23,15 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
||||
*/
|
||||
public class IntervalStatisticsModel extends AndroidViewModel {
|
||||
|
||||
private MutableLiveData<IntervalStatistics> intervalStats;
|
||||
private IntervalOption interval;
|
||||
private MutableLiveData<IntervalStatistics> intervalStats = new MutableLiveData<>();
|
||||
private IntervalOption interval = IntervalOption.OPTION_1;
|
||||
|
||||
public IntervalStatisticsModel(@NonNull Application application) {
|
||||
super(application);
|
||||
interval = IntervalOption.OPTION_1;
|
||||
}
|
||||
|
||||
public LiveData<IntervalStatistics> getIntervalStats(Track.Id trackId, IntervalOption interval) {
|
||||
if (intervalStats == null || this.interval != interval) {
|
||||
intervalStats = new MutableLiveData<>();
|
||||
public LiveData<IntervalStatistics> getIntervalStats(@Nullable Track.Id trackId, IntervalOption interval) {
|
||||
if (trackId != null && this.interval != interval) {
|
||||
this.interval = interval;
|
||||
loadIntervalStats(trackId);
|
||||
}
|
||||
@@ -47,10 +46,10 @@ public class IntervalStatisticsModel extends AndroidViewModel {
|
||||
* Call this method when you want to force the view model to re-load intervals.
|
||||
*/
|
||||
public void invalidate() {
|
||||
intervalStats = null;
|
||||
intervalStats = new MutableLiveData<>();
|
||||
}
|
||||
|
||||
private void loadIntervalStats(Track.Id trackId) {
|
||||
private void loadIntervalStats(final Track.Id trackId) {
|
||||
new Thread(() -> {
|
||||
Context context = getApplication().getApplicationContext();
|
||||
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
style="@style/StatsScrollView">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/root_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user