forked from upstream-mirrors/OpenTracks
ChartFragment: re-added isResume() check.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.fragments;
|
package de.dennisguse.opentracks.fragments;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -24,7 +25,6 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -169,55 +169,69 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrackUpdated(Track track) {
|
public void onTrackUpdated(Track track) {
|
||||||
if (track == null) {
|
if (isResumed()) {
|
||||||
category = "";
|
if (track == null) {
|
||||||
return;
|
category = "";
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
category = track.getCategory();
|
category = track.getCategory();
|
||||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(PreferencesUtils.getSharedPreferences(getContext()), getContext(), category);
|
boolean reportSpeed = PreferencesUtils.isReportSpeed(PreferencesUtils.getSharedPreferences(getContext()), getContext(), category);
|
||||||
if (reportSpeed != viewBinding.chartView.getReportSpeed()) {
|
if (reportSpeed != viewBinding.chartView.getReportSpeed()) {
|
||||||
viewBinding.chartView.setReportSpeed(reportSpeed);
|
viewBinding.chartView.setReportSpeed(reportSpeed);
|
||||||
viewBinding.chartView.applyReportSpeed();
|
viewBinding.chartView.applyReportSpeed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTrackPoints() {
|
public void clearTrackPoints() {
|
||||||
pendingPoints.clear();
|
if (isResumed()) {
|
||||||
viewBinding.chartView.reset();
|
pendingPoints.clear();
|
||||||
runOnUiThread(() -> {
|
viewBinding.chartView.reset();
|
||||||
if (isResumed()) {
|
runOnUiThread(() -> {
|
||||||
viewBinding.chartView.resetScroll();
|
if (isResumed()) {
|
||||||
}
|
viewBinding.chartView.resetScroll();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics, Speed smoothedSpeed, double smoothedAltitude_m) {
|
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics, Speed smoothedSpeed, double smoothedAltitude_m) {
|
||||||
ChartPoint point = new ChartPoint(trackStatistics, trackPoint, smoothedSpeed, smoothedAltitude_m, chartByDistance, viewBinding.chartView.getMetricUnits());
|
if (isResumed()) {
|
||||||
pendingPoints.add(point);
|
ChartPoint point = new ChartPoint(trackStatistics, trackPoint, smoothedSpeed, smoothedAltitude_m, chartByDistance, viewBinding.chartView.getMetricUnits());
|
||||||
|
pendingPoints.add(point);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewTrackPointsDone() {
|
public void onNewTrackPointsDone() {
|
||||||
viewBinding.chartView.addChartPoints(pendingPoints);
|
if (isResumed()) {
|
||||||
pendingPoints.clear();
|
viewBinding.chartView.addChartPoints(pendingPoints);
|
||||||
runOnUiThread(updateChart);
|
pendingPoints.clear();
|
||||||
|
runOnUiThread(updateChart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearMarkers() {
|
public void clearMarkers() {
|
||||||
viewBinding.chartView.clearMarker();
|
if (isResumed()) {
|
||||||
|
viewBinding.chartView.clearMarker();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewMarker(@NonNull Marker marker) {
|
public void onNewMarker(@NonNull Marker marker) {
|
||||||
viewBinding.chartView.addMarker(marker);
|
if (isResumed()) {
|
||||||
|
viewBinding.chartView.addMarker(marker);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewMarkersDone() {
|
public void onNewMarkersDone() {
|
||||||
runOnUiThread(updateChart);
|
if (isResumed()) {
|
||||||
|
runOnUiThread(updateChart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,7 +278,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
* @param runnable the runnable
|
* @param runnable the runnable
|
||||||
*/
|
*/
|
||||||
private void runOnUiThread(Runnable runnable) {
|
private void runOnUiThread(Runnable runnable) {
|
||||||
FragmentActivity fragmentActivity = getActivity();
|
Activity fragmentActivity = getActivity();
|
||||||
if (fragmentActivity != null) {
|
if (fragmentActivity != null) {
|
||||||
fragmentActivity.runOnUiThread(runnable);
|
fragmentActivity.runOnUiThread(runnable);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user