Clean up.
This commit is contained in:
parent
22e90743aa
commit
3b19db14fd
1 changed files with 25 additions and 44 deletions
|
@ -42,7 +42,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInsulin(double amount) {
|
public void setInsulin(double amount) {
|
||||||
this.amount = amount;
|
BolusProgressDialog.amount = amount;
|
||||||
bolusEnded = false;
|
bolusEnded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +55,10 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
getDialog().setTitle(String.format(MainApp.gs(R.string.overview_bolusprogress_goingtodeliver), amount));
|
getDialog().setTitle(String.format(MainApp.gs(R.string.overview_bolusprogress_goingtodeliver), amount));
|
||||||
View view = inflater.inflate(R.layout.overview_bolusprogress_dialog, container, false);
|
View view = inflater.inflate(R.layout.overview_bolusprogress_dialog, container, false);
|
||||||
stopButton = (Button) view.findViewById(R.id.overview_bolusprogress_stop);
|
stopButton = view.findViewById(R.id.overview_bolusprogress_stop);
|
||||||
statusView = (TextView) view.findViewById(R.id.overview_bolusprogress_status);
|
statusView = view.findViewById(R.id.overview_bolusprogress_status);
|
||||||
stopPressedView = (TextView) view.findViewById(R.id.overview_bolusprogress_stoppressed);
|
stopPressedView = view.findViewById(R.id.overview_bolusprogress_stoppressed);
|
||||||
progressBar = (ProgressBar) view.findViewById(R.id.overview_bolusprogress_progressbar);
|
progressBar = view.findViewById(R.id.overview_bolusprogress_progressbar);
|
||||||
stopButton.setOnClickListener(this);
|
stopButton.setOnClickListener(this);
|
||||||
progressBar.setMax(100);
|
progressBar.setMax(100);
|
||||||
statusView.setText(MainApp.gs(R.string.waitingforpump));
|
statusView.setText(MainApp.gs(R.string.waitingforpump));
|
||||||
|
@ -118,16 +118,13 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(() -> {
|
||||||
@Override
|
log.debug("Status: " + ev.status + " Percent: " + ev.percent);
|
||||||
public void run() {
|
statusView.setText(ev.status);
|
||||||
log.debug("Status: " + ev.status + " Percent: " + ev.percent);
|
progressBar.setProgress(ev.percent);
|
||||||
statusView.setText(ev.status);
|
if (ev.percent == 100) {
|
||||||
progressBar.setProgress(ev.percent);
|
stopButton.setVisibility(View.INVISIBLE);
|
||||||
if (ev.percent == 100) {
|
scheduleDismiss();
|
||||||
stopButton.setVisibility(View.INVISIBLE);
|
|
||||||
scheduleDismiss();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -142,41 +139,25 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPumpStatusChanged c) {
|
public void onStatusEvent(final EventPumpStatusChanged c) {
|
||||||
|
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
activity.runOnUiThread(
|
activity.runOnUiThread(() -> statusView.setText(c.textStatus()));
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
statusView.setText(c.textStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleDismiss() {
|
private void scheduleDismiss() {
|
||||||
Thread t = new Thread(new Runnable() {
|
Thread t = new Thread(() -> {
|
||||||
@Override
|
SystemClock.sleep(5000);
|
||||||
public void run() {
|
BolusProgressDialog.bolusEnded = true;
|
||||||
SystemClock.sleep(5000);
|
Activity activity = getActivity();
|
||||||
BolusProgressDialog.bolusEnded = true;
|
if (activity != null) {
|
||||||
Activity activity = getActivity();
|
activity.runOnUiThread(() -> {
|
||||||
if (activity != null) {
|
try {
|
||||||
activity.runOnUiThread(
|
dismiss();
|
||||||
new Runnable() {
|
} catch (Exception e) {
|
||||||
@Override
|
log.error("Unhandled exception", e);
|
||||||
public void run() {
|
}
|
||||||
try {
|
});
|
||||||
dismiss();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
|
|
Loading…
Reference in a new issue