Skip to content

Commit

Permalink
Updates of the views should be done in the UI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Ślimak committed Sep 18, 2020
1 parent 1649c6a commit ac0559e
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ac0559e

Please sign in to comment.