This commit is contained in:
Milos Kozak 2018-06-20 23:56:50 +02:00
commit 5292e09535
6 changed files with 56 additions and 46 deletions

View file

@ -22,9 +22,7 @@ import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick; import butterknife.OnClick;
import butterknife.Optional;
import butterknife.Unbinder; import butterknife.Unbinder;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.PreferencesActivity; import info.nightscout.androidaps.PreferencesActivity;
@ -51,7 +49,7 @@ import info.nightscout.utils.PasswordProtection;
public class ConfigBuilderFragment extends SubscriberFragment { public class ConfigBuilderFragment extends SubscriberFragment {
private List<PluginView> pluginViews = new ArrayList<>(); private List<PluginViewHolder> pluginViewHolders = new ArrayList<>();
@BindView(R.id.profile_plugins) @BindView(R.id.profile_plugins)
LinearLayout profilePlugins; LinearLayout profilePlugins;
@ -111,33 +109,33 @@ public class ConfigBuilderFragment extends SubscriberFragment {
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
for (PluginView pluginView : pluginViews) pluginView.unbind(); for (PluginViewHolder pluginViewHolder : pluginViewHolders) pluginViewHolder.unbind();
pluginViews.clear(); pluginViewHolders.clear();
} }
@Override @Override
protected void updateGUI() { protected void updateGUI() {
for (PluginView pluginView : pluginViews) pluginView.update(); for (PluginViewHolder pluginViewHolder : pluginViewHolders) pluginViewHolder.update();
} }
private void createViews() { private void createViews() {
createViewsForPlugins(profilePlugins, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginType.PROFILE)); createViewsForPlugins(profilePlugins, PluginType.PROFILE, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginType.PROFILE));
createViewsForPlugins(insulinPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginType.INSULIN)); createViewsForPlugins(insulinPlugins, PluginType.INSULIN, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginType.INSULIN));
createViewsForPlugins(bgSourcePlugins, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginType.BGSOURCE)); createViewsForPlugins(bgSourcePlugins, PluginType.BGSOURCE, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginType.BGSOURCE));
createViewsForPlugins(pumpPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP)); createViewsForPlugins(pumpPlugins, PluginType.PUMP, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP));
createViewsForPlugins(sensitivityPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginType.SENSITIVITY)); createViewsForPlugins(sensitivityPlugins, PluginType.SENSITIVITY, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginType.SENSITIVITY));
createViewsForPlugins(apsPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.APS)); createViewsForPlugins(apsPlugins, PluginType.APS, MainApp.getSpecificPluginsVisibleInList(PluginType.APS));
createViewsForPlugins(loopPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP)); createViewsForPlugins(loopPlugins, PluginType.LOOP, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP));
createViewsForPlugins(constraintsPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginType.CONSTRAINTS)); createViewsForPlugins(constraintsPlugins, PluginType.CONSTRAINTS, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginType.CONSTRAINTS));
createViewsForPlugins(treatmentsPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT)); createViewsForPlugins(treatmentsPlugins, PluginType.TREATMENT, MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT));
createViewsForPlugins(generalPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.GENERAL)); createViewsForPlugins(generalPlugins, PluginType.GENERAL, MainApp.getSpecificPluginsVisibleInList(PluginType.GENERAL));
} }
private void createViewsForPlugins(LinearLayout parent, List<PluginBase> plugins) { private void createViewsForPlugins(LinearLayout parent, PluginType pluginType, List<PluginBase> plugins) {
for (PluginBase plugin: plugins) { for (PluginBase plugin: plugins) {
PluginView pluginView = new PluginView(plugin); PluginViewHolder pluginViewHolder = new PluginViewHolder(pluginType, plugin);
parent.addView(pluginView.getBaseView()); parent.addView(pluginViewHolder.getBaseView());
pluginViews.add(pluginView); pluginViewHolders.add(pluginViewHolder);
} }
} }
@ -200,9 +198,10 @@ public class ConfigBuilderFragment extends SubscriberFragment {
} }
} }
class PluginView { class PluginViewHolder {
private Unbinder unbinder; private Unbinder unbinder;
private PluginType pluginType;
private PluginBase plugin; private PluginBase plugin;
LinearLayout baseView; LinearLayout baseView;
@ -219,7 +218,8 @@ public class ConfigBuilderFragment extends SubscriberFragment {
@BindView(R.id.plugin_visibility) @BindView(R.id.plugin_visibility)
CheckBox pluginVisibility; CheckBox pluginVisibility;
public PluginView(PluginBase plugin) { public PluginViewHolder(PluginType pluginType, PluginBase plugin) {
this.pluginType = pluginType;
this.plugin = plugin; this.plugin = plugin;
baseView = (LinearLayout) getLayoutInflater().inflate(R.layout.configbuilder_single_plugin, null); baseView = (LinearLayout) getLayoutInflater().inflate(R.layout.configbuilder_single_plugin, null);
unbinder = ButterKnife.bind(this, baseView); unbinder = ButterKnife.bind(this, baseView);
@ -231,10 +231,10 @@ public class ConfigBuilderFragment extends SubscriberFragment {
} }
public void update() { public void update() {
enabledExclusive.setVisibility(areMultipleSelectionsAllowed(plugin.getType()) ? View.GONE : View.VISIBLE); enabledExclusive.setVisibility(areMultipleSelectionsAllowed(pluginType) ? View.GONE : View.VISIBLE);
enabledInclusive.setVisibility(areMultipleSelectionsAllowed(plugin.getType()) ? View.VISIBLE : View.GONE); enabledInclusive.setVisibility(areMultipleSelectionsAllowed(pluginType) ? View.VISIBLE : View.GONE);
enabledExclusive.setChecked(plugin.isEnabled(plugin.getType())); enabledExclusive.setChecked(plugin.isEnabled(pluginType));
enabledInclusive.setChecked(plugin.isEnabled(plugin.getType())); enabledInclusive.setChecked(plugin.isEnabled(pluginType));
enabledInclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled); enabledInclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled);
enabledExclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled); enabledExclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled);
pluginName.setText(plugin.getName()); pluginName.setText(plugin.getName());
@ -243,15 +243,15 @@ public class ConfigBuilderFragment extends SubscriberFragment {
pluginDescription.setVisibility(View.VISIBLE); pluginDescription.setVisibility(View.VISIBLE);
pluginDescription.setText(plugin.getDescription()); pluginDescription.setText(plugin.getDescription());
} }
pluginPreferences.setVisibility(plugin.getPreferencesId() == -1 || !plugin.isEnabled(plugin.getType()) ? View.INVISIBLE : View.VISIBLE); pluginPreferences.setVisibility(plugin.getPreferencesId() == -1 || !plugin.isEnabled(pluginType) ? View.INVISIBLE : View.VISIBLE);
pluginVisibility.setVisibility(plugin.hasFragment() ? View.VISIBLE : View.INVISIBLE); pluginVisibility.setVisibility(plugin.hasFragment() ? View.VISIBLE : View.INVISIBLE);
pluginVisibility.setEnabled(!(plugin.pluginDescription.neverVisible || plugin.pluginDescription.alwayVisible) && plugin.isEnabled(plugin.getType())); pluginVisibility.setEnabled(!(plugin.pluginDescription.neverVisible || plugin.pluginDescription.alwayVisible) && plugin.isEnabled(pluginType));
pluginVisibility.setChecked(plugin.isFragmentVisible()); pluginVisibility.setChecked(plugin.isFragmentVisible());
} }
@OnClick(R.id.plugin_visibility) @OnClick(R.id.plugin_visibility)
void onVisibilityChanged() { void onVisibilityChanged() {
plugin.setFragmentVisible(plugin.getType(), pluginVisibility.isChecked()); plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked());
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible"); ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
ConfigBuilderPlugin.getPlugin().logPluginStatus(); ConfigBuilderPlugin.getPlugin().logPluginStatus();
@ -260,9 +260,9 @@ public class ConfigBuilderFragment extends SubscriberFragment {
@OnClick({R.id.plugin_enabled_exclusive, R.id.plugin_enabled_inclusive}) @OnClick({R.id.plugin_enabled_exclusive, R.id.plugin_enabled_inclusive})
void onEnabledChanged() { void onEnabledChanged() {
boolean enabled = enabledExclusive.getVisibility() == View.VISIBLE ? enabledExclusive.isChecked() : enabledInclusive.isChecked(); boolean enabled = enabledExclusive.getVisibility() == View.VISIBLE ? enabledExclusive.isChecked() : enabledInclusive.isChecked();
plugin.setPluginEnabled(plugin.getType(), enabled); plugin.setPluginEnabled(pluginType, enabled);
plugin.setFragmentVisible(plugin.getType(), enabled); plugin.setFragmentVisible(pluginType, enabled);
processOnEnabledCategoryChanged(plugin, plugin.getType()); processOnEnabledCategoryChanged(plugin, pluginType);
updateGUI(); updateGUI();
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled"); ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());

View file

@ -354,6 +354,11 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
// trigger a connect, which will update state and check history // trigger a connect, which will update state and check history
CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState); CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState);
if (stateResult.invalidSetup) {
MainApp.bus().post(new EventNewNotification(
new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_invalid_setup), Notification.URGENT)));
return;
}
if (!stateResult.success) { if (!stateResult.success) {
return; return;
} }

View file

@ -5,10 +5,11 @@ import android.support.annotation.Nullable;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
public class CommandResult { public class CommandResult {
/** True if a condition indicating a broken pump setup/configuration is detected */
public boolean invalidSetup;
/** Whether the command was executed successfully. */ /** Whether the command was executed successfully. */
public boolean success; public boolean success;
/** State of the pump *after* command execution. */ /** State of the pump *after* command execution. */

View file

@ -281,10 +281,10 @@ public class RuffyScripter implements RuffyCommands {
log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms"); log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms");
} catch (CommandException e) { } catch (CommandException e) {
log.error("CommandException running command", e); log.error("CommandException running command", e);
activeCmd.getResult().success = false; cmd.getResult().success = false;
} catch (Exception e) { } catch (Exception e) {
log.error("Unexpected exception running cmd", e); log.error("Unexpected exception running cmd", e);
activeCmd.getResult().success = false; cmd.getResult().success = false;
} }
}, cmd.getClass().getSimpleName()); }, cmd.getClass().getSimpleName());
long executionStart = System.currentTimeMillis(); long executionStart = System.currentTimeMillis();
@ -328,6 +328,7 @@ public class RuffyScripter implements RuffyCommands {
if (unparsableMenuEncountered) { if (unparsableMenuEncountered) {
log.error("UnparsableMenuEncountered flagged, aborting command"); log.error("UnparsableMenuEncountered flagged, aborting command");
cmdThread.interrupt(); cmdThread.interrupt();
activeCmd.getResult().invalidSetup = true;
activeCmd.getResult().success = false; activeCmd.getResult().success = false;
} }

View file

@ -39,6 +39,7 @@ public class ReadQuickInfoCommand extends BaseCommand {
// read bolus records // read bolus records
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
if (record > 0) {
while (true) { while (true) {
bolusHistory.add(readBolusRecord()); bolusHistory.add(readBolusRecord());
if (bolusHistory.size() == numberOfBolusRecordsToRetrieve || record == totalRecords) { if (bolusHistory.size() == numberOfBolusRecordsToRetrieve || record == totalRecords) {
@ -51,6 +52,7 @@ public class ReadQuickInfoCommand extends BaseCommand {
} }
record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
} }
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
if (!result.history.bolusHistory.isEmpty()) { if (!result.history.bolusHistory.isEmpty()) {
log.debug("Read bolus history (" + result.history.bolusHistory.size() + "):"); log.debug("Read bolus history (" + result.history.bolusHistory.size() + "):");

View file

@ -1162,6 +1162,7 @@
<string name="nth_objective">%1$d. Objective</string> <string name="nth_objective">%1$d. Objective</string>
<string name="poctech">Poctech</string> <string name="poctech">Poctech</string>
<string name="description_source_poctech">Receive BG values from Poctech app</string> <string name="description_source_poctech">Receive BG values from Poctech app</string>
<string name="combo_invalid_setup">Invalid pump setup, check the docs and verify that the Quick Info menu is named "QUICK INFO" using the 360 configuration software.</string>
<plurals name="objective_days"> <plurals name="objective_days">
<item quantity="one">%d day</item> <item quantity="one">%d day</item>