From ac0559e83f8452d1ac6e8d02de51a9f6b80fdbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=C5=9Alimak?= Date: Thu, 17 Sep 2020 14:51:55 +0200 Subject: [PATCH] Updates of the views should be done in the UI thread --- .../screens/stream/graph/GraphActivity.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/pl/llp/aircasting/screens/stream/graph/GraphActivity.java b/src/main/java/pl/llp/aircasting/screens/stream/graph/GraphActivity.java index 35679ba9..f97fb113 100644 --- a/src/main/java/pl/llp/aircasting/screens/stream/graph/GraphActivity.java +++ b/src/main/java/pl/llp/aircasting/screens/stream/graph/GraphActivity.java @@ -52,6 +52,7 @@ import java.util.ArrayList; import java.util.Date; +import java.util.concurrent.atomic.AtomicBoolean; import static com.google.common.collect.Iterables.getLast; import static com.google.common.collect.Lists.newArrayList; @@ -75,6 +76,8 @@ public class GraphActivity extends AirCastingActivity implements View.OnClickLis @Inject ViewingSessionsManager viewingSessionsManager; @Inject FormatHelper mFormatHelper; + final AtomicBoolean noUpdateInProgress = new AtomicBoolean(true); + @Override protected void onCreate(Bundle savedInstanceState) { @@ -186,9 +189,18 @@ public void onMeasurement(Measurement measurement) {} @Override public void updateGauges() { - double peak = measurementPresenter.getTimelinePeak(); - double avg = measurementPresenter.getTimelineAvg(); - mGaugeHelper.updateGaugesFromTimeline(peak, avg); + if (noUpdateInProgress.get()) { + noUpdateInProgress.set(false); + runOnUiThread(new Runnable() { + @Override + public void run() { + double peak = measurementPresenter.getTimelinePeak(); + double avg = measurementPresenter.getTimelineAvg(); + mGaugeHelper.updateGaugesFromTimeline(peak, avg); + noUpdateInProgress.set(true); + } + }); + } } private void refresh() {