use onAttach for context in WizardDialog

This commit is contained in:
Milos Kozak 2017-03-09 10:57:20 +01:00
parent aa8fa729ad
commit 7c6d708d06
2 changed files with 44 additions and 45 deletions

View file

@ -85,17 +85,19 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
Handler mHandler;
public static HandlerThread mHandlerThread;
Context parentContext;
Context context;
public WizardDialog() {
super();
mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName());
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper());
}
public void setContext(Context context) {
parentContext = context;
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
}
final private TextWatcher textWatcher = new TextWatcher() {
@ -129,7 +131,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
@Override
public void onNothingSelected(AdapterView<?> parent) {
ToastUtils.showToastInUiThread(parentContext, MainApp.sResources.getString(R.string.noprofileselected));
ToastUtils.showToastInUiThread(context, MainApp.sResources.getString(R.string.noprofileselected));
wizardDialogDeliverButton.setVisibility(View.GONE);
}
};
@ -201,7 +203,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g";
if (insulinAfterConstraints - calculatedTotalInsulin != 0 || !carbsAfterConstraints.equals(calculatedCarbs)) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput));
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
@ -212,8 +214,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
if (parentContext != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@ -224,7 +225,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
@Override
public void run() {
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
parentContext,
context,
finalInsulinAfterConstraints,
finalCarbsAfterConstraints,
SafeParse.stringToDouble(bgInput.getText().toString()),
@ -233,7 +234,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
boluscalcJSON
);
if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
builder.setMessage(result.comment);
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
@ -251,7 +252,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
} else {
log.error("parentContext == null");
}
}
break;
}

View file

@ -216,7 +216,6 @@ public class OverviewFragment extends Fragment {
public void onClick(View view) {
FragmentManager manager = getFragmentManager();
WizardDialog wizardDialog = new WizardDialog();
wizardDialog.setContext(getContext());
wizardDialog.show(manager, "WizardDialog");
}
});