Clean up.

This commit is contained in:
Johannes Mockenhaupt 2018-05-02 21:25:04 +02:00
parent 22e90743aa
commit 3b19db14fd
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -42,7 +42,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
}
public void setInsulin(double amount) {
this.amount = amount;
BolusProgressDialog.amount = amount;
bolusEnded = false;
}
@ -55,10 +55,10 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
Bundle savedInstanceState) {
getDialog().setTitle(String.format(MainApp.gs(R.string.overview_bolusprogress_goingtodeliver), amount));
View view = inflater.inflate(R.layout.overview_bolusprogress_dialog, container, false);
stopButton = (Button) view.findViewById(R.id.overview_bolusprogress_stop);
statusView = (TextView) view.findViewById(R.id.overview_bolusprogress_status);
stopPressedView = (TextView) view.findViewById(R.id.overview_bolusprogress_stoppressed);
progressBar = (ProgressBar) view.findViewById(R.id.overview_bolusprogress_progressbar);
stopButton = view.findViewById(R.id.overview_bolusprogress_stop);
statusView = view.findViewById(R.id.overview_bolusprogress_status);
stopPressedView = view.findViewById(R.id.overview_bolusprogress_stoppressed);
progressBar = view.findViewById(R.id.overview_bolusprogress_progressbar);
stopButton.setOnClickListener(this);
progressBar.setMax(100);
statusView.setText(MainApp.gs(R.string.waitingforpump));
@ -118,9 +118,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
public void onStatusEvent(final EventOverviewBolusProgress ev) {
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.runOnUiThread(() -> {
log.debug("Status: " + ev.status + " Percent: " + ev.percent);
statusView.setText(ev.status);
progressBar.setProgress(ev.percent);
@ -128,7 +126,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
stopButton.setVisibility(View.INVISIBLE);
scheduleDismiss();
}
}
});
}
}
@ -142,42 +139,26 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
@Subscribe
public void onStatusEvent(final EventPumpStatusChanged c) {
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
statusView.setText(c.textStatus());
activity.runOnUiThread(() -> statusView.setText(c.textStatus()));
}
}
);
}
}
private void scheduleDismiss() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Thread t = new Thread(() -> {
SystemClock.sleep(5000);
BolusProgressDialog.bolusEnded = true;
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
activity.runOnUiThread(() -> {
try {
dismiss();
} catch (Exception e) {
log.error("Unhandled exception", e);
}
}
});
}
}
});
t.start();
}