display SMB reasons
This commit is contained in:
parent
4d6d7941ac
commit
afe3d68a10
|
@ -31,7 +31,6 @@ import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
|
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
||||||
|
@ -188,7 +187,7 @@ public class MainApp extends Application {
|
||||||
pluginsList.add(new PersistentNotificationPlugin(this));
|
pluginsList.add(new PersistentNotificationPlugin(this));
|
||||||
pluginsList.add(NSClientPlugin.getPlugin());
|
pluginsList.add(NSClientPlugin.getPlugin());
|
||||||
|
|
||||||
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.getPlugin());
|
pluginsList.add(sConfigBuilder = ConfigBuilderPlugin.getPlugin());
|
||||||
|
|
||||||
MainApp.getConfigBuilder().initialize();
|
MainApp.getConfigBuilder().initialize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,31 +64,31 @@ public class DataService extends IntentService {
|
||||||
if (Config.logFunctionCalls)
|
if (Config.logFunctionCalls)
|
||||||
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
|
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
|
||||||
|
|
||||||
if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
|
if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
|
||||||
xDripEnabled = true;
|
xDripEnabled = true;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
dexcomG5Enabled = false;
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = true;
|
nsClientEnabled = true;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
dexcomG5Enabled = false;
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = true;
|
mm640gEnabled = true;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
dexcomG5Enabled = false;
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = true;
|
glimpEnabled = true;
|
||||||
dexcomG5Enabled = false;
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceDexcomG5Plugin.class)) {
|
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceDexcomG5Plugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
|
|
|
@ -4,9 +4,11 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 19.03.2018.
|
* Created by mike on 19.03.2018.
|
||||||
|
@ -41,6 +43,10 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
return isSMBModeEnabled(new Constraint<>(true));
|
return isSMBModeEnabled(new Constraint<>(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Constraint<Boolean> isAdvancedFilteringEnabled() {
|
||||||
|
return isAdvancedFilteringEnabled(new Constraint<>(true));
|
||||||
|
}
|
||||||
|
|
||||||
public Constraint<Double> getMaxBasalAllowed(Profile profile) {
|
public Constraint<Double> getMaxBasalAllowed(Profile profile) {
|
||||||
return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile);
|
return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile);
|
||||||
}
|
}
|
||||||
|
@ -121,6 +127,17 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Constraint<Boolean> isAdvancedFilteringEnabled(Constraint<Boolean> value) {
|
||||||
|
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||||
|
for (PluginBase p : constraintsPlugins) {
|
||||||
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
||||||
|
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
|
||||||
|
constraint.isAdvancedFilteringEnabled(value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
||||||
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class ProfileIntervals<T extends Interval> {
|
||||||
if (index >= 0) return rawData.valueAt(index);
|
if (index >= 0) return rawData.valueAt(index);
|
||||||
// if we request data older than first record, use oldest instead
|
// if we request data older than first record, use oldest instead
|
||||||
if (rawData.size() > 0) {
|
if (rawData.size() > 0) {
|
||||||
log.debug("Requested profile for time: " + DateUtil.dateAndTimeString(time) + ". Providing oldest record: " + rawData.valueAt(0).toString());
|
//log.debug("Requested profile for time: " + DateUtil.dateAndTimeString(time) + ". Providing oldest record: " + rawData.valueAt(0).toString());
|
||||||
return rawData.valueAt(0);
|
return rawData.valueAt(0);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -27,6 +27,10 @@ public interface ConstraintsInterface {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Constraint<Boolean> isAdvancedFilteringEnabled(Constraint<Boolean> value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
default Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
default Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
||||||
return absoluteRate;
|
return absoluteRate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ package info.nightscout.androidaps.plugins.ConfigBuilder;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.annotation.NonNull;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -17,11 +17,13 @@ import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.PreferencesActivity;
|
import info.nightscout.androidaps.PreferencesActivity;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -35,6 +37,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin;
|
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
|
@ -43,33 +46,46 @@ import info.nightscout.utils.FabricPrivacy;
|
||||||
import info.nightscout.utils.PasswordProtection;
|
import info.nightscout.utils.PasswordProtection;
|
||||||
|
|
||||||
|
|
||||||
public class ConfigBuilderFragment extends Fragment {
|
public class ConfigBuilderFragment extends SubscriberFragment {
|
||||||
|
|
||||||
static ConfigBuilderPlugin configBuilderPlugin = new ConfigBuilderPlugin();
|
|
||||||
|
|
||||||
static public ConfigBuilderPlugin getPlugin() {
|
|
||||||
return configBuilderPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@BindView(R.id.configbuilder_insulinlistview)
|
||||||
ListView insulinListView;
|
ListView insulinListView;
|
||||||
|
@BindView(R.id.configbuilder_sensitivitylistview)
|
||||||
ListView sensitivityListView;
|
ListView sensitivityListView;
|
||||||
|
@BindView(R.id.configbuilder_bgsourcelistview)
|
||||||
ListView bgsourceListView;
|
ListView bgsourceListView;
|
||||||
|
@BindView(R.id.configbuilder_bgsourcelabel)
|
||||||
TextView bgsourceLabel;
|
TextView bgsourceLabel;
|
||||||
|
@BindView(R.id.configbuilder_pumplistview)
|
||||||
ListView pumpListView;
|
ListView pumpListView;
|
||||||
|
@BindView(R.id.configbuilder_pumplabel)
|
||||||
TextView pumpLabel;
|
TextView pumpLabel;
|
||||||
|
@BindView(R.id.configbuilder_looplistview)
|
||||||
ListView loopListView;
|
ListView loopListView;
|
||||||
|
@BindView(R.id.configbuilder_looplabel)
|
||||||
TextView loopLabel;
|
TextView loopLabel;
|
||||||
|
@BindView(R.id.configbuilder_treatmentslistview)
|
||||||
ListView treatmentsListView;
|
ListView treatmentsListView;
|
||||||
|
@BindView(R.id.configbuilder_treatmentslabel)
|
||||||
TextView treatmentsLabel;
|
TextView treatmentsLabel;
|
||||||
|
@BindView(R.id.configbuilder_profilelistview)
|
||||||
ListView profileListView;
|
ListView profileListView;
|
||||||
|
@BindView(R.id.configbuilder_profilelabel)
|
||||||
TextView profileLabel;
|
TextView profileLabel;
|
||||||
|
@BindView(R.id.configbuilder_apslistview)
|
||||||
ListView apsListView;
|
ListView apsListView;
|
||||||
|
@BindView(R.id.configbuilder_apslabel)
|
||||||
TextView apsLabel;
|
TextView apsLabel;
|
||||||
|
@BindView(R.id.configbuilder_constraintslistview)
|
||||||
ListView constraintsListView;
|
ListView constraintsListView;
|
||||||
|
@BindView(R.id.configbuilder_constraintslabel)
|
||||||
TextView constraintsLabel;
|
TextView constraintsLabel;
|
||||||
|
@BindView(R.id.configbuilder_generallistview)
|
||||||
ListView generalListView;
|
ListView generalListView;
|
||||||
|
|
||||||
|
@BindView(R.id.configbuilder_mainlayout)
|
||||||
LinearLayout mainLayout;
|
LinearLayout mainLayout;
|
||||||
|
@BindView(R.id.configbuilder_unlock)
|
||||||
Button unlock;
|
Button unlock;
|
||||||
|
|
||||||
PluginCustomAdapter insulinDataAdapter = null;
|
PluginCustomAdapter insulinDataAdapter = null;
|
||||||
|
@ -84,51 +100,17 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
PluginCustomAdapter generalDataAdapter = null;
|
PluginCustomAdapter generalDataAdapter = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
try {
|
try {
|
||||||
View view = inflater.inflate(R.layout.configbuilder_fragment, container, false);
|
View view = inflater.inflate(R.layout.configbuilder_fragment, container, false);
|
||||||
|
|
||||||
insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview);
|
unbinder = ButterKnife.bind(this, view);
|
||||||
sensitivityListView = (ListView) view.findViewById(R.id.configbuilder_sensitivitylistview);
|
|
||||||
bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview);
|
|
||||||
bgsourceLabel = (TextView) view.findViewById(R.id.configbuilder_bgsourcelabel);
|
|
||||||
pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview);
|
|
||||||
pumpLabel = (TextView) view.findViewById(R.id.configbuilder_pumplabel);
|
|
||||||
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
|
|
||||||
loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel);
|
|
||||||
treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview);
|
|
||||||
treatmentsLabel = (TextView) view.findViewById(R.id.configbuilder_treatmentslabel);
|
|
||||||
profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview);
|
|
||||||
profileLabel = (TextView) view.findViewById(R.id.configbuilder_profilelabel);
|
|
||||||
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
|
|
||||||
apsLabel = (TextView) view.findViewById(R.id.configbuilder_apslabel);
|
|
||||||
constraintsListView = (ListView) view.findViewById(R.id.configbuilder_constraintslistview);
|
|
||||||
constraintsLabel = (TextView) view.findViewById(R.id.configbuilder_constraintslabel);
|
|
||||||
generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview);
|
|
||||||
|
|
||||||
mainLayout = (LinearLayout) view.findViewById(R.id.configbuilder_mainlayout);
|
if (PasswordProtection.isLocked("settings_password"))
|
||||||
unlock = (Button) view.findViewById(R.id.configbuilder_unlock);
|
|
||||||
|
|
||||||
setViews();
|
|
||||||
|
|
||||||
if (PasswordProtection.isLocked("settings_password")) {
|
|
||||||
mainLayout.setVisibility(View.GONE);
|
mainLayout.setVisibility(View.GONE);
|
||||||
unlock.setOnClickListener(new View.OnClickListener() {
|
else
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mainLayout.setVisibility(View.VISIBLE);
|
|
||||||
unlock.setVisibility(View.GONE);
|
unlock.setVisibility(View.GONE);
|
||||||
}
|
|
||||||
}, null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
unlock.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FabricPrivacy.logException(e);
|
FabricPrivacy.logException(e);
|
||||||
|
@ -137,7 +119,18 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setViews() {
|
@OnClick(R.id.configbuilder_unlock)
|
||||||
|
public void onClickUnlock() {
|
||||||
|
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", () -> {
|
||||||
|
mainLayout.setVisibility(View.VISIBLE);
|
||||||
|
unlock.setVisibility(View.GONE);
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateGUI() {
|
||||||
|
|
||||||
insulinDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginBase.INSULIN), PluginBase.INSULIN);
|
insulinDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginBase.INSULIN), PluginBase.INSULIN);
|
||||||
insulinListView.setAdapter(insulinDataAdapter);
|
insulinListView.setAdapter(insulinDataAdapter);
|
||||||
setListViewHeightBasedOnChildren(insulinListView);
|
setListViewHeightBasedOnChildren(insulinListView);
|
||||||
|
@ -182,7 +175,6 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.GENERAL), PluginBase.GENERAL);
|
generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.GENERAL), PluginBase.GENERAL);
|
||||||
generalListView.setAdapter(generalDataAdapter);
|
generalListView.setAdapter(generalDataAdapter);
|
||||||
setListViewHeightBasedOnChildren(generalListView);
|
setListViewHeightBasedOnChildren(generalListView);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -194,7 +186,7 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
private ArrayList<PluginBase> pluginList;
|
private ArrayList<PluginBase> pluginList;
|
||||||
final private int type;
|
final private int type;
|
||||||
|
|
||||||
public PluginCustomAdapter(Context context, int textViewResourceId,
|
PluginCustomAdapter(Context context, int textViewResourceId,
|
||||||
ArrayList<PluginBase> pluginList, int type) {
|
ArrayList<PluginBase> pluginList, int type) {
|
||||||
super(context, textViewResourceId, pluginList);
|
super(context, textViewResourceId, pluginList);
|
||||||
this.pluginList = new ArrayList<>();
|
this.pluginList = new ArrayList<>();
|
||||||
|
@ -209,10 +201,11 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
ImageView settings;
|
ImageView settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, @NonNull ViewGroup parent) {
|
||||||
|
|
||||||
PluginViewHolder holder = null;
|
PluginViewHolder holder;
|
||||||
PluginBase plugin = pluginList.get(position);
|
PluginBase plugin = pluginList.get(position);
|
||||||
|
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
|
@ -231,60 +224,45 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
|
|
||||||
view.setTag(holder);
|
view.setTag(holder);
|
||||||
|
|
||||||
holder.checkboxEnabled.setOnClickListener(new View.OnClickListener() {
|
holder.checkboxEnabled.setOnClickListener(v -> {
|
||||||
public void onClick(View v) {
|
|
||||||
CheckBox cb = (CheckBox) v;
|
CheckBox cb = (CheckBox) v;
|
||||||
PluginBase plugin = (PluginBase) cb.getTag();
|
PluginBase plugin1 = (PluginBase) cb.getTag();
|
||||||
plugin.setPluginEnabled(type, cb.isChecked());
|
plugin1.setPluginEnabled(type, cb.isChecked());
|
||||||
plugin.setFragmentVisible(type, cb.isChecked());
|
plugin1.setFragmentVisible(type, cb.isChecked());
|
||||||
onEnabledCategoryChanged(plugin, type);
|
onEnabledCategoryChanged(plugin1, type);
|
||||||
configBuilderPlugin.storeSettings();
|
ConfigBuilderPlugin.getPlugin().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshGui());
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
MainApp.bus().post(new EventConfigBuilderChange());
|
MainApp.bus().post(new EventConfigBuilderChange());
|
||||||
getPlugin().logPluginStatus();
|
ConfigBuilderPlugin.getPlugin().logPluginStatus();
|
||||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("ConfigurationChange"));
|
FabricPrivacy.getInstance().logCustom(new CustomEvent("ConfigurationChange"));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
holder.checkboxVisible.setOnClickListener(new View.OnClickListener() {
|
holder.checkboxVisible.setOnClickListener(v -> {
|
||||||
public void onClick(View v) {
|
|
||||||
CheckBox cb = (CheckBox) v;
|
CheckBox cb = (CheckBox) v;
|
||||||
PluginBase plugin = (PluginBase) cb.getTag();
|
PluginBase plugin12 = (PluginBase) cb.getTag();
|
||||||
plugin.setFragmentVisible(type, cb.isChecked());
|
plugin12.setFragmentVisible(type, cb.isChecked());
|
||||||
configBuilderPlugin.storeSettings();
|
ConfigBuilderPlugin.getPlugin().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshGui());
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
getPlugin().logPluginStatus();
|
ConfigBuilderPlugin.getPlugin().logPluginStatus();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
holder.settings.setOnClickListener(new View.OnClickListener() {
|
holder.settings.setOnClickListener(v -> {
|
||||||
public void onClick(View v) {
|
final PluginBase plugin13 = (PluginBase) v.getTag();
|
||||||
final PluginBase plugin = (PluginBase) v.getTag();
|
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", () -> {
|
||||||
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Intent i = new Intent(getContext(), PreferencesActivity.class);
|
Intent i = new Intent(getContext(), PreferencesActivity.class);
|
||||||
i.putExtra("id", plugin.getPreferencesId());
|
i.putExtra("id", plugin13.getPreferencesId());
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
|
||||||
}, null);
|
}, null);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
holder.name.setOnLongClickListener(new View.OnLongClickListener() {
|
holder.name.setOnLongClickListener(v -> {
|
||||||
@Override
|
final PluginBase plugin14 = (PluginBase) v.getTag();
|
||||||
public boolean onLongClick(View v) {
|
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", () -> {
|
||||||
final PluginBase plugin = (PluginBase) v.getTag();
|
|
||||||
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Intent i = new Intent(getContext(), PreferencesActivity.class);
|
Intent i = new Intent(getContext(), PreferencesActivity.class);
|
||||||
i.putExtra("id", plugin.getPreferencesId());
|
i.putExtra("id", plugin14.getPreferencesId());
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
|
||||||
}, null);
|
}, null);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -317,7 +295,7 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
if (pluginList.size() < 2) {
|
if (pluginList.size() < 2) {
|
||||||
holder.checkboxEnabled.setEnabled(false);
|
holder.checkboxEnabled.setEnabled(false);
|
||||||
plugin.setPluginEnabled(type, true);
|
plugin.setPluginEnabled(type, true);
|
||||||
getPlugin().storeSettings();
|
ConfigBuilderPlugin.getPlugin().storeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constraints cannot be disabled
|
// Constraints cannot be disabled
|
||||||
|
@ -396,17 +374,17 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
}
|
}
|
||||||
} else { // enable first plugin in list
|
} else { // enable first plugin in list
|
||||||
if (type == PluginBase.PUMP)
|
if (type == PluginBase.PUMP)
|
||||||
MainApp.getSpecificPlugin(VirtualPumpPlugin.class).setPluginEnabled(type, true);
|
VirtualPumpPlugin.getPlugin().setPluginEnabled(type, true);
|
||||||
else if (type == PluginBase.INSULIN)
|
else if (type == PluginBase.INSULIN)
|
||||||
MainApp.getSpecificPlugin(InsulinFastactingPlugin.class).setPluginEnabled(type, true);
|
InsulinFastactingPlugin.getPlugin().setPluginEnabled(type, true);
|
||||||
else if (type == PluginBase.SENSITIVITY)
|
else if (type == PluginBase.SENSITIVITY)
|
||||||
MainApp.getSpecificPlugin(SensitivityOref0Plugin.class).setPluginEnabled(type, true);
|
SensitivityOref0Plugin.getPlugin().setPluginEnabled(type, true);
|
||||||
else if (type == PluginBase.PROFILE)
|
else if (type == PluginBase.PROFILE)
|
||||||
MainApp.getSpecificPlugin(NSProfilePlugin.class).setPluginEnabled(type, true);
|
NSProfilePlugin.getPlugin().setPluginEnabled(type, true);
|
||||||
else
|
else
|
||||||
pluginsInCategory.get(0).setPluginEnabled(type, true);
|
pluginsInCategory.get(0).setPluginEnabled(type, true);
|
||||||
}
|
}
|
||||||
setViews();
|
updateGUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileIntervals;
|
import info.nightscout.androidaps.data.ProfileIntervals;
|
||||||
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
|
@ -58,7 +59,15 @@ import info.nightscout.utils.ToastUtils;
|
||||||
public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
|
public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
|
||||||
|
|
||||||
private static BgSourceInterface activeBgSource;
|
private static ConfigBuilderPlugin configBuilderPlugin;
|
||||||
|
|
||||||
|
static public ConfigBuilderPlugin getPlugin() {
|
||||||
|
if (configBuilderPlugin == null)
|
||||||
|
configBuilderPlugin = new ConfigBuilderPlugin();
|
||||||
|
return configBuilderPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BgSourceInterface activeBgSource;
|
||||||
private static PumpInterface activePump;
|
private static PumpInterface activePump;
|
||||||
private static ProfileInterface activeProfile;
|
private static ProfileInterface activeProfile;
|
||||||
private static TreatmentsInterface activeTreatments;
|
private static TreatmentsInterface activeTreatments;
|
||||||
|
@ -197,7 +206,7 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
|
||||||
return commandQueue;
|
return commandQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BgSourceInterface getActiveBgSource() {
|
public BgSourceInterface getActiveBgSource() {
|
||||||
return activeBgSource;
|
return activeBgSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -657,11 +666,14 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
|
||||||
if (profileSwitch.profileJson != null) {
|
if (profileSwitch.profileJson != null) {
|
||||||
return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
|
return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
|
||||||
} else {
|
} else {
|
||||||
Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName);
|
ProfileStore profileStore = activeProfile.getProfile();
|
||||||
|
if (profileStore != null) {
|
||||||
|
Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName);
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
return profileSwitch.profileName;
|
return profileSwitch.profileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return MainApp.gs(R.string.noprofileselected);
|
return MainApp.gs(R.string.noprofileselected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,9 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
@ -126,6 +128,21 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
|
||||||
boolean enabled = SP.getBoolean(R.string.key_use_smb, false);
|
boolean enabled = SP.getBoolean(R.string.key_use_smb, false);
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
value.set(false, MainApp.gs(R.string.smbdisabledinpreferences), this);
|
value.set(false, MainApp.gs(R.string.smbdisabledinpreferences), this);
|
||||||
|
ConstraintChecker constraintChecker = MainApp.getConstraintChecker();
|
||||||
|
Constraint<Boolean> closedLoop = constraintChecker.isClosedLoopAllowed();
|
||||||
|
if (!closedLoop.value())
|
||||||
|
value.set(false, MainApp.gs(R.string.smbnotallowedinopenloopmode), this);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Constraint<Boolean> isAdvancedFilteringEnabled(Constraint<Boolean> value) {
|
||||||
|
BgSourceInterface bgSource = MainApp.getConfigBuilder().getActiveBgSource();
|
||||||
|
|
||||||
|
if (bgSource != null) {
|
||||||
|
if (!bgSource.advancedFilteringSupported())
|
||||||
|
value.set(false, MainApp.gs(R.string.smbalwaysdisabled), this);
|
||||||
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
private JSONObject mCurrentTemp;
|
private JSONObject mCurrentTemp;
|
||||||
private JSONObject mAutosensData = null;
|
private JSONObject mAutosensData = null;
|
||||||
private boolean mMicrobolusAllowed;
|
private boolean mMicrobolusAllowed;
|
||||||
|
private boolean mSMBAlwaysAllowed;
|
||||||
|
|
||||||
private String storedCurrentTemp = null;
|
private String storedCurrentTemp = null;
|
||||||
private String storedIobData = null;
|
private String storedIobData = null;
|
||||||
|
@ -55,6 +56,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
private String storedMeal_data = null;
|
private String storedMeal_data = null;
|
||||||
private String storedAutosens_data = null;
|
private String storedAutosens_data = null;
|
||||||
private String storedMicroBolusAllowed = null;
|
private String storedMicroBolusAllowed = null;
|
||||||
|
private String storedSMBAlwaysAllowed = null;
|
||||||
|
|
||||||
private String scriptDebug = "";
|
private String scriptDebug = "";
|
||||||
|
|
||||||
|
@ -82,6 +84,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
||||||
log.debug("Reservoir data: " + "undefined");
|
log.debug("Reservoir data: " + "undefined");
|
||||||
log.debug("MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed));
|
log.debug("MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed));
|
||||||
|
log.debug("SMBAlwaysAllowed: " + (storedSMBAlwaysAllowed = "" + mSMBAlwaysAllowed));
|
||||||
|
|
||||||
DetermineBasalResultSMB determineBasalResultSMB = null;
|
DetermineBasalResultSMB determineBasalResultSMB = null;
|
||||||
|
|
||||||
|
@ -210,7 +213,8 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
MealData mealData,
|
MealData mealData,
|
||||||
double autosensDataRatio,
|
double autosensDataRatio,
|
||||||
boolean tempTargetSet,
|
boolean tempTargetSet,
|
||||||
boolean microBolusAllowed
|
boolean microBolusAllowed,
|
||||||
|
boolean smbAlwaysAllowed
|
||||||
) throws JSONException {
|
) throws JSONException {
|
||||||
|
|
||||||
String units = profile.getUnits();
|
String units = profile.getUnits();
|
||||||
|
@ -244,12 +248,11 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap);
|
mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap);
|
||||||
mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false));
|
mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false));
|
||||||
mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable);
|
mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable);
|
||||||
boolean SMBEnabled = MainApp.getConstraintChecker().isSMBModeEnabled().value() && MainApp.getConstraintChecker().isClosedLoopAllowed().value();
|
mProfile.put("enableSMB_with_COB", SP.getBoolean(R.string.key_enableSMB_with_COB, false));
|
||||||
mProfile.put("enableSMB_with_COB", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_with_COB, false));
|
mProfile.put("enableSMB_with_temptarget", SP.getBoolean(R.string.key_enableSMB_with_temptarget, false));
|
||||||
mProfile.put("enableSMB_with_temptarget", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_with_temptarget, false));
|
mProfile.put("allowSMB_with_high_temptarget", SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
|
||||||
mProfile.put("allowSMB_with_high_temptarget", SMBEnabled && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
|
mProfile.put("enableSMB_always", SP.getBoolean(R.string.key_enableSMB_always, false) && smbAlwaysAllowed);
|
||||||
mProfile.put("enableSMB_always", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_always, false) && ConfigBuilderPlugin.getActiveBgSource().advancedFilteringSupported());
|
mProfile.put("enableSMB_after_carbs", SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && smbAlwaysAllowed);
|
||||||
mProfile.put("enableSMB_after_carbs", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && ConfigBuilderPlugin.getActiveBgSource().advancedFilteringSupported());
|
|
||||||
mProfile.put("maxSMBBasalMinutes", SP.getInt("key_smbmaxminutes", SMBDefaults.maxSMBBasalMinutes));
|
mProfile.put("maxSMBBasalMinutes", SP.getInt("key_smbmaxminutes", SMBDefaults.maxSMBBasalMinutes));
|
||||||
mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold);
|
mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold);
|
||||||
|
|
||||||
|
@ -308,6 +311,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mAutosensData.put("ratio", 1.0);
|
mAutosensData.put("ratio", 1.0);
|
||||||
}
|
}
|
||||||
mMicrobolusAllowed = microBolusAllowed;
|
mMicrobolusAllowed = microBolusAllowed;
|
||||||
|
mSMBAlwaysAllowed = smbAlwaysAllowed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,15 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
||||||
} else {
|
} else {
|
||||||
lastAutosensResult = new AutosensResult();
|
lastAutosensResult = new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Constraint<Boolean> smbAllowed = new Constraint<>(true);
|
||||||
|
MainApp.getConstraintChecker().isSMBModeEnabled(smbAllowed);
|
||||||
|
inputConstraints.copyReasons(smbAllowed);
|
||||||
|
|
||||||
|
Constraint<Boolean> smbAlwaysEnabled = new Constraint<>(true);
|
||||||
|
MainApp.getConstraintChecker().isAdvancedFilteringEnabled(smbAlwaysEnabled);
|
||||||
|
inputConstraints.copyReasons(smbAlwaysEnabled);
|
||||||
|
|
||||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||||
Profiler.log(log, "SMB data gathering", start);
|
Profiler.log(log, "SMB data gathering", start);
|
||||||
|
|
||||||
|
@ -239,7 +248,8 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
||||||
determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
||||||
lastAutosensResult.ratio, //autosensDataRatio
|
lastAutosensResult.ratio, //autosensDataRatio
|
||||||
isTempTarget,
|
isTempTarget,
|
||||||
true //microBolusAllowed
|
smbAllowed.value(),
|
||||||
|
smbAlwaysEnabled.value()
|
||||||
);
|
);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
|
|
@ -991,5 +991,7 @@
|
||||||
<string name="key_openapsama_useautosens" translatable="false">openapsama_useautosens</string>
|
<string name="key_openapsama_useautosens" translatable="false">openapsama_useautosens</string>
|
||||||
<string name="record_pump_site_change">Record pump site change</string>
|
<string name="record_pump_site_change">Record pump site change</string>
|
||||||
<string name="record_insulin_cartridge_change">Record insulin cartridge change</string>
|
<string name="record_insulin_cartridge_change">Record insulin cartridge change</string>
|
||||||
|
<string name="smbalwaysdisabled">SMB always and after carbs disabled because active BG source doesn\'t support advanced filtering</string>
|
||||||
|
<string name="smbnotallowedinopenloopmode">SMB not allowed in open loop mode</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Locale;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -56,6 +57,9 @@ public class AAPSMocker {
|
||||||
when(MainApp.gs(R.string.pumpisnottempbasalcapable)).thenReturn("Pump is not temp basal capable");
|
when(MainApp.gs(R.string.pumpisnottempbasalcapable)).thenReturn("Pump is not temp basal capable");
|
||||||
when(MainApp.gs(R.string.loop)).thenReturn("Loop");
|
when(MainApp.gs(R.string.loop)).thenReturn("Loop");
|
||||||
when(MainApp.gs(R.string.loop_shortname)).thenReturn("LOOP");
|
when(MainApp.gs(R.string.loop_shortname)).thenReturn("LOOP");
|
||||||
|
when(MainApp.gs(R.string.smbalwaysdisabled)).thenReturn("SMB always and after carbs disabled because active BG source doesn\\'t support advanced filtering");
|
||||||
|
when(MainApp.gs(R.string.smbnotallowedinopenloopmode)).thenReturn("SMB not allowed in open loop mode");
|
||||||
|
when(MainApp.gs(R.string.Glimp)).thenReturn("Glimp");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MainApp mockMainApp() {
|
public static MainApp mockMainApp() {
|
||||||
|
@ -71,6 +75,11 @@ public class AAPSMocker {
|
||||||
when(MainApp.getConfigBuilder()).thenReturn(configBuilderPlugin);
|
when(MainApp.getConfigBuilder()).thenReturn(configBuilderPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void mockConstraintsChecker() {
|
||||||
|
ConstraintChecker constraintChecker = mock(ConstraintChecker.class);
|
||||||
|
when(MainApp.getConstraintChecker()).thenReturn(constraintChecker);
|
||||||
|
}
|
||||||
|
|
||||||
public static void mockBus() {
|
public static void mockBus() {
|
||||||
Bus bus = PowerMockito.mock(Bus.class);
|
Bus bus = PowerMockito.mock(Bus.class);
|
||||||
when(MainApp.bus()).thenReturn(bus);
|
when(MainApp.bus()).thenReturn(bus);
|
||||||
|
|
|
@ -34,6 +34,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
|
import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner;
|
import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner;
|
||||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
||||||
import info.nightscout.utils.FabricPrivacy;
|
import info.nightscout.utils.FabricPrivacy;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
@ -110,10 +111,21 @@ public class ConstraintsCheckerTest {
|
||||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAdvancedFilteringEnabledTest() throws Exception {
|
||||||
|
when(MainApp.getConfigBuilder().getActiveBgSource()).thenReturn(SourceGlimpPlugin.getPlugin());
|
||||||
|
|
||||||
|
Constraint<Boolean> c = constraintChecker.isAdvancedFilteringEnabled();
|
||||||
|
Assert.assertEquals(true, c.getReasonList().size() == 1); // Safety
|
||||||
|
Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 1); // Safety
|
||||||
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSMBModeEnabledTest() throws Exception {
|
public void isSMBModeEnabledTest() throws Exception {
|
||||||
objectivesPlugin.objectives.get(7).setStarted(new Date(0));
|
objectivesPlugin.objectives.get(7).setStarted(new Date(0));
|
||||||
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
||||||
|
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
||||||
|
|
||||||
Constraint<Boolean> c = constraintChecker.isSMBModeEnabled();
|
Constraint<Boolean> c = constraintChecker.isSMBModeEnabled();
|
||||||
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
|
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
|
||||||
|
@ -240,6 +252,7 @@ public class ConstraintsCheckerTest {
|
||||||
|
|
||||||
MainApp mainApp = AAPSMocker.mockMainApp();
|
MainApp mainApp = AAPSMocker.mockMainApp();
|
||||||
AAPSMocker.mockConfigBuilder();
|
AAPSMocker.mockConfigBuilder();
|
||||||
|
AAPSMocker.mockConstraintsChecker();
|
||||||
AAPSMocker.mockApplicationContext();
|
AAPSMocker.mockApplicationContext();
|
||||||
AAPSMocker.mockBus();
|
AAPSMocker.mockBus();
|
||||||
AAPSMocker.mockStrings();
|
AAPSMocker.mockStrings();
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -70,6 +71,7 @@ public class SafetyPluginTest {
|
||||||
@Test
|
@Test
|
||||||
public void notEnabledSMBInPreferencesDisablesSMB() throws Exception {
|
public void notEnabledSMBInPreferencesDisablesSMB() throws Exception {
|
||||||
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
||||||
|
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
||||||
|
|
||||||
Constraint<Boolean> c = new Constraint<>(true);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = safetyPlugin.isSMBModeEnabled(c);
|
c = safetyPlugin.isSMBModeEnabled(c);
|
||||||
|
@ -77,6 +79,27 @@ public class SafetyPluginTest {
|
||||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void openLoopPreventsSMB() throws Exception {
|
||||||
|
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(true);
|
||||||
|
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(false));
|
||||||
|
|
||||||
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
|
c = safetyPlugin.isSMBModeEnabled(c);
|
||||||
|
Assert.assertEquals(true, c.getReasons().contains("SMB not allowed in open loop mode"));
|
||||||
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bgsourceShouldPreventSMBAlways() throws Exception {
|
||||||
|
when(MainApp.getConfigBuilder().getActiveBgSource()).thenReturn(SourceGlimpPlugin.getPlugin());
|
||||||
|
|
||||||
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
|
c = safetyPlugin.isAdvancedFilteringEnabled(c);
|
||||||
|
Assert.assertEquals("Safety: SMB always and after carbs disabled because active BG source doesn\\'t support advanced filtering", c.getReasons());
|
||||||
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basalRateShouldBeLimited() throws Exception {
|
public void basalRateShouldBeLimited() throws Exception {
|
||||||
when(SP.getDouble(R.string.key_openapsma_max_basal, 1d)).thenReturn(1d);
|
when(SP.getDouble(R.string.key_openapsma_max_basal, 1d)).thenReturn(1d);
|
||||||
|
@ -204,9 +227,12 @@ public class SafetyPluginTest {
|
||||||
public void prepareMock() {
|
public void prepareMock() {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
AAPSMocker.mockConfigBuilder();
|
AAPSMocker.mockConfigBuilder();
|
||||||
|
AAPSMocker.mockConstraintsChecker();
|
||||||
AAPSMocker.mockSP();
|
AAPSMocker.mockSP();
|
||||||
AAPSMocker.mockStrings();
|
AAPSMocker.mockStrings();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
when(MainApp.getConfigBuilder().getActivePump()).thenReturn(pump);
|
when(MainApp.getConfigBuilder().getActivePump()).thenReturn(pump);
|
||||||
|
|
||||||
safetyPlugin = SafetyPlugin.getPlugin();
|
safetyPlugin = SafetyPlugin.getPlugin();
|
||||||
|
|
Loading…
Reference in a new issue