force use iob when cob is selected

This commit is contained in:
Milos Kozak 2019-08-22 21:33:10 +02:00
parent 6ed0f9b40e
commit 40ffb6f199
2 changed files with 54 additions and 13 deletions

View file

@ -8,6 +8,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
@ -59,17 +60,17 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
View view = inflater.inflate(R.layout.overview_editquickwizard_dialog, container, false);
buttonEdit = (EditText) view.findViewById(R.id.overview_editquickwizard_button_edit);
carbsEdit = (EditText) view.findViewById(R.id.overview_editquickwizard_carbs_edit);
fromSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_from_spinner);
toSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_to_spinner);
useBGSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebg_spinner);
useCOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usecob_spinner);
useBolusIOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebolusiob_spinner);
useBasalIOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebasaliob_spinner);
useTrendSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usetrend_spinner);
useSuperBolusSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usesuperbolus_spinner);
useTempTargetSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usetemptarget_spinner);
buttonEdit = view.findViewById(R.id.overview_editquickwizard_button_edit);
carbsEdit = view.findViewById(R.id.overview_editquickwizard_carbs_edit);
fromSpinner = view.findViewById(R.id.overview_editquickwizard_from_spinner);
toSpinner = view.findViewById(R.id.overview_editquickwizard_to_spinner);
useBGSpinner = view.findViewById(R.id.overview_editquickwizard_usebg_spinner);
useCOBSpinner = view.findViewById(R.id.overview_editquickwizard_usecob_spinner);
useBolusIOBSpinner = view.findViewById(R.id.overview_editquickwizard_usebolusiob_spinner);
useBasalIOBSpinner = view.findViewById(R.id.overview_editquickwizard_usebasaliob_spinner);
useTrendSpinner = view.findViewById(R.id.overview_editquickwizard_usetrend_spinner);
useSuperBolusSpinner = view.findViewById(R.id.overview_editquickwizard_usesuperbolus_spinner);
useTempTargetSpinner = view.findViewById(R.id.overview_editquickwizard_usetemptarget_spinner);
view.findViewById(R.id.ok).setOnClickListener(this);
view.findViewById(R.id.cancel).setOnClickListener(this);
@ -104,6 +105,19 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
setSelection(useSuperBolusSpinner, entry.useSuperBolus());
setSelection(useTempTargetSpinner, entry.useTempTarget());
useCOBSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
processCob();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
processCob();
return view;
}
@ -147,6 +161,18 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
}
}
private void processCob() {
if (getSelection(useCOBSpinner) == QuickWizardEntry.YES) {
useBolusIOBSpinner.setEnabled(false);
useBasalIOBSpinner.setEnabled(false);
setSelection(useBolusIOBSpinner, QuickWizardEntry.YES);
setSelection(useBasalIOBSpinner, QuickWizardEntry.YES);
} else {
useBolusIOBSpinner.setEnabled(true);
useBasalIOBSpinner.setEnabled(true);
}
}
int getSelection(Spinner spinner) {
String value = spinner.getSelectedItem().toString();
if (value.equals(MainApp.gs(R.string.yes)))

View file

@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.general.overview.dialogs;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
@ -23,6 +21,8 @@ import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.fragment.app.DialogFragment;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
@ -254,6 +254,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
editCarbTime.setValue(savedInstanceState.getDouble("editCarbTime"));
editCorr.setValue(savedInstanceState.getDouble("editCorr"));
}
processCobCheckBox();
return view;
}
@ -261,9 +262,23 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
saveCheckedStates();
ttCheckbox.setEnabled(bgCheckbox.isChecked() && TreatmentsPlugin.getPlugin().getTempTargetFromHistory() != null);
if (buttonView.getId() == cobCheckbox.getId())
processCobCheckBox();
calculateInsulin();
}
private void processCobCheckBox() {
if (cobCheckbox.isChecked()) {
bolusIobCheckbox.setEnabled(false);
basalIobCheckbox.setEnabled(false);
bolusIobCheckbox.setChecked(true);
basalIobCheckbox.setChecked(true);
} else {
bolusIobCheckbox.setEnabled(true);
basalIobCheckbox.setEnabled(true);
}
}
private void saveCheckedStates() {
SP.putBoolean(MainApp.gs(R.string.key_wizard_include_cob), cobCheckbox.isChecked());
SP.putBoolean(MainApp.gs(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked());