move getConfigBuilder() to MainApp
This commit is contained in:
parent
2a2589f5eb
commit
58388c4a87
14 changed files with 47 additions and 49 deletions
|
@ -47,10 +47,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
private static ConfigBuilderFragment configBuilderFragment;
|
||||
|
||||
public static ConfigBuilderFragment getConfigBuilder() {
|
||||
return configBuilderFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
@ -152,11 +152,11 @@ public class DataService extends IntentService {
|
|||
String profile = bundles.getString("profile");
|
||||
NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile);
|
||||
EventNewBasalProfile event = new EventNewBasalProfile(nsProfile);
|
||||
if (MainActivity.getConfigBuilder() == null) {
|
||||
if (MainApp.getConfigBuilder() == null) {
|
||||
log.error("Config builder not ready on receive profile");
|
||||
return;
|
||||
}
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
if (pump != null) {
|
||||
pump.setNewBasalProfile(nsProfile);
|
||||
} else {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class TempBasal {
|
|||
|
||||
public IobTotal iobCalc(Date time) {
|
||||
IobTotal result = new IobTotal();
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
|
||||
if (profile == null)
|
||||
return result;
|
||||
|
|
|
@ -208,7 +208,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
ConstraintsInterface constraintsInterface = MainActivity.getConfigBuilder();
|
||||
ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder();
|
||||
if (constraintsInterface.isAutomaticProcessingEnabled()) {
|
||||
invoke();
|
||||
updateGUI();
|
||||
|
@ -216,8 +216,8 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
}
|
||||
|
||||
private void invoke() {
|
||||
ConstraintsInterface constraintsInterface = MainActivity.getConfigBuilder();
|
||||
PumpInterface pumpInterface = MainActivity.getConfigBuilder().getActivePump();
|
||||
ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder();
|
||||
PumpInterface pumpInterface = MainApp.getConfigBuilder().getActivePump();
|
||||
APSResult result = null;
|
||||
|
||||
if (constraintsInterface == null || pumpInterface == null || !isEnabled())
|
||||
|
|
|
@ -220,8 +220,8 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
|
|||
public void invoke() {
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
|
||||
if (!isEnabled()) {
|
||||
updateResultGUI(MainApp.instance().getString(R.string.openapsma_disabled));
|
||||
|
|
|
@ -216,8 +216,8 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
|
||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
|
||||
if (!isEnabled()) {
|
||||
updateResultGUI(MainApp.instance().getString(R.string.openapsma_disabled));
|
||||
|
@ -266,8 +266,8 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
minBg = Round.roundTo(minBg, 1d);
|
||||
maxBg = Round.roundTo(maxBg, 1d);
|
||||
|
||||
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
|
||||
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
|
||||
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments();
|
||||
TempBasalsInterface tempBasals = MainApp.getConfigBuilder().getActiveTempBasals();
|
||||
treatments.updateTotalIOB();
|
||||
tempBasals.updateTotalIOB();
|
||||
IobTotal bolusIob = treatments.getLastCalculation();
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.widget.EditText;
|
|||
import android.widget.RadioButton;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -58,7 +59,7 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
|||
|
||||
String confirmMessage = getString(R.string.setextendedbolusquestion);
|
||||
|
||||
Double insulinAfterConstraint = MainActivity.getConfigBuilder().applyBolusConstraints(insulin);
|
||||
Double insulinAfterConstraint = MainApp.getConfigBuilder().applyBolusConstraints(insulin);
|
||||
confirmMessage += " " + insulinAfterConstraint + " U ";
|
||||
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?";
|
||||
if (insulinAfterConstraint != insulin)
|
||||
|
@ -73,7 +74,7 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
|||
builder.setMessage(confirmMessage);
|
||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.widget.EditText;
|
|||
import android.widget.RadioButton;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -63,13 +64,13 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
|||
|
||||
String confirmMessage = getString(R.string.setbasalquestion);
|
||||
if (setAsPercent) {
|
||||
basalPercent = MainActivity.getConfigBuilder().applyBasalConstraints(basal.intValue());
|
||||
basalPercent = MainApp.getConfigBuilder().applyBasalConstraints(basal.intValue());
|
||||
confirmMessage += "\n " + basalPercent + "% ";
|
||||
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?";
|
||||
if (basalPercent != basal.intValue())
|
||||
confirmMessage += "\n" + getString(R.string.constraintapllied);
|
||||
} else {
|
||||
Double basalAfterConstraint = MainActivity.getConfigBuilder().applyBasalConstraints(basal);
|
||||
Double basalAfterConstraint = MainApp.getConfigBuilder().applyBasalConstraints(basal);
|
||||
confirmMessage += "\n " + basalAfterConstraint + " U/h ";
|
||||
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?";
|
||||
if (basalAfterConstraint != basal)
|
||||
|
@ -86,7 +87,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
|||
builder.setMessage(confirmMessage);
|
||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result;
|
||||
if (setAsPercent) {
|
||||
result = pump.setTempBasalPercent(finalBasalPercent, finalDurationInMinutes);
|
||||
|
|
|
@ -53,8 +53,8 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
|
||||
String confirmMessage = getString(R.string.entertreatmentquestion);
|
||||
|
||||
Double insulinAfterConstraints = MainActivity.getConfigBuilder().applyBolusConstraints(insulin);
|
||||
Integer carbsAfterConstraints = MainActivity.getConfigBuilder().applyCarbsConstraints(carbs);
|
||||
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin);
|
||||
Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs);
|
||||
|
||||
confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U";
|
||||
confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
||||
|
@ -70,7 +70,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
|
|
|
@ -115,8 +115,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
||||
String confirmMessage = getString(R.string.entertreatmentquestion);
|
||||
|
||||
Double insulinAfterConstraints = MainActivity.getConfigBuilder().applyBolusConstraints(calculatedTotalInsulin);
|
||||
Integer carbsAfterConstraints = MainActivity.getConfigBuilder().applyCarbsConstraints(calculatedCarbs);
|
||||
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(calculatedTotalInsulin);
|
||||
Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(calculatedCarbs);
|
||||
|
||||
confirmMessage += "\n" + getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U";
|
||||
confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
||||
|
@ -139,7 +139,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
|
@ -161,7 +161,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
}
|
||||
|
||||
private void initDialog() {
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
|
||||
if (profile == null) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), "No profile loaded from NS yet");
|
||||
|
@ -197,8 +197,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
}
|
||||
|
||||
// IOB calculation
|
||||
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
|
||||
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
|
||||
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments();
|
||||
TempBasalsInterface tempBasals = MainApp.getConfigBuilder().getActiveTempBasals();
|
||||
treatments.updateTotalIOB();
|
||||
tempBasals.updateTotalIOB();
|
||||
IobTotal bolusIob = treatments.getLastCalculation();
|
||||
|
@ -213,7 +213,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
}
|
||||
|
||||
private void calculateInsulin() {
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
|
||||
// Entered values
|
||||
String i_bg = this.bgInput.getText().toString().replace("," , ".");
|
||||
|
@ -226,12 +226,12 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
c_carbs = (Integer) Math.round(c_carbs);
|
||||
Double c_correction = 0d;
|
||||
try { c_correction = Double.parseDouble(i_correction.equals("") ? "0" : i_correction); } catch (Exception e) {}
|
||||
if(c_correction != MainActivity.getConfigBuilder().applyBolusConstraints(c_correction)) {
|
||||
if(c_correction != MainApp.getConfigBuilder().applyBolusConstraints(c_correction)) {
|
||||
this.correctionInput.setText("");
|
||||
wizardDialogDeliverButton.setVisibility(Button.GONE);
|
||||
return;
|
||||
}
|
||||
if(c_carbs != MainActivity.getConfigBuilder().applyCarbsConstraints(c_carbs)) {
|
||||
if(c_carbs != MainApp.getConfigBuilder().applyCarbsConstraints(c_carbs)) {
|
||||
this.carbsInput.setText("");
|
||||
wizardDialogDeliverButton.setVisibility(Button.GONE);
|
||||
return;
|
||||
|
@ -259,8 +259,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
carbsInsulin.setText(numberFormat.format(insulinFromCarbs) + "U");
|
||||
|
||||
// Insulin from IOB
|
||||
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
|
||||
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
|
||||
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments();
|
||||
TempBasalsInterface tempBasals = MainApp.getConfigBuilder().getActiveTempBasals();
|
||||
treatments.updateTotalIOB();
|
||||
tempBasals.updateTotalIOB();
|
||||
IobTotal bolusIob = treatments.getLastCalculation();
|
||||
|
|
|
@ -175,7 +175,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
cancelTempButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
if (pump.isTempBasalInProgress()) {
|
||||
pump.cancelTempBasal();
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
|
@ -271,9 +271,9 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
public void updateGUI() {
|
||||
BgReading actualBG = MainApp.getDbHelper().actualBg();
|
||||
BgReading lastBG = MainApp.getDbHelper().lastBg();
|
||||
if (MainActivity.getConfigBuilder() == null || MainActivity.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
|
||||
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
|
||||
return;
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null)
|
||||
return;
|
||||
|
||||
|
@ -284,7 +284,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
return;
|
||||
|
||||
// **** Temp button ****
|
||||
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
|
||||
if (pump.isTempBasalInProgress()) {
|
||||
TempBasal activeTemp = pump.getTempBasal();
|
||||
|
|
|
@ -85,7 +85,7 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
Double maxBasal = Double.parseDouble(SP.getString("openapsma_max_basal", "1").replace(",", "."));
|
||||
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (absoluteRate < 0) absoluteRate = 0d;
|
||||
|
||||
Integer maxBasalMult = 4;
|
||||
|
@ -115,7 +115,7 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
Double maxBasal = Double.parseDouble(SP.getString("openapsma_max_basal", "1").replace(",", "."));
|
||||
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
Double currentBasal = profile.getBasal(profile.secondsFromMidnight());
|
||||
|
||||
Double absoluteRate = currentBasal * ((double) percentRate / 100);
|
||||
|
|
|
@ -134,9 +134,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
public void updateTotalIOB() {
|
||||
IobTotal total = new IobTotal();
|
||||
|
||||
if (MainActivity.getConfigBuilder() == null || MainActivity.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
|
||||
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
|
||||
return;
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null) {
|
||||
lastCalculation = total;
|
||||
return;
|
||||
|
@ -170,7 +170,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
@Override
|
||||
public MealData getMealData() {
|
||||
MealData result = new MealData();
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null)
|
||||
return result;
|
||||
|
||||
|
@ -207,9 +207,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(TreatmentsViewHolder holder, int position) {
|
||||
if (MainActivity.getConfigBuilder() == null || MainActivity.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
|
||||
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
|
||||
return;
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null)
|
||||
return;
|
||||
// TODO: implement locales
|
||||
|
|
|
@ -180,12 +180,12 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
|
||||
@Override
|
||||
public void setNewBasalProfile(NSProfile profile) {
|
||||
// Do nothing here. we are using MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null)
|
||||
return defaultBasalValue;
|
||||
return profile.getBasal(profile.secondsFromMidnight());
|
||||
|
@ -198,7 +198,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
if (tempBasal.isAbsolute) {
|
||||
return tempBasal.absolute;
|
||||
} else {
|
||||
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null)
|
||||
return defaultBasalValue;
|
||||
Double baseRate = profile.getBasal(profile.secondsFromMidnight());
|
||||
|
|
Loading…
Reference in a new issue