This commit is contained in:
Milos Kozak 2018-05-03 18:41:47 +02:00
parent d025b4b03d
commit 36265ab1c6
6 changed files with 106 additions and 156 deletions

View file

@ -285,7 +285,7 @@ public class ConfigBuilderFragment extends SubscriberFragment {
holder.checkboxEnabled.setEnabled(false); holder.checkboxEnabled.setEnabled(false);
} }
if (plugin.pluginDescription.alwayVisible) { if (plugin.pluginDescription.alwayVisible) {
holder.checkboxEnabled.setEnabled(false); holder.checkboxEnabled.setEnabled(false);
} }
@ -339,7 +339,7 @@ public class ConfigBuilderFragment extends SubscriberFragment {
} }
void onEnabledCategoryChanged(PluginBase changedPlugin, PluginType type) { public static void processOnEnabledCategoryChanged(PluginBase changedPlugin, PluginType type) {
ArrayList<PluginBase> pluginsInCategory = null; ArrayList<PluginBase> pluginsInCategory = null;
switch (type) { switch (type) {
// Multiple selection allowed // Multiple selection allowed
@ -391,10 +391,14 @@ public class ConfigBuilderFragment extends SubscriberFragment {
else else
pluginsInCategory.get(0).setPluginEnabled(type, true); pluginsInCategory.get(0).setPluginEnabled(type, true);
} }
updateGUI();
} }
} }
void onEnabledCategoryChanged(PluginBase changedPlugin, PluginType type) {
processOnEnabledCategoryChanged(changedPlugin, type);
updateGUI();
}
/**** /****
* Method for Setting the Height of the ListView dynamically. * Method for Setting the Height of the ListView dynamically.
* *** Hack to fix the issue of not showing all the items of the ListView * *** Hack to fix the issue of not showing all the items of the ListView

View file

@ -57,8 +57,6 @@ public class SWDefinition {
if(!SP.getString(R.string.key_language, "en").equals(LocaleHelper.getLanguage(context))) { if(!SP.getString(R.string.key_language, "en").equals(LocaleHelper.getLanguage(context))) {
Intent intent = new Intent(MainApp.instance().getApplicationContext(), SetupWizardActivity.class); Intent intent = new Intent(MainApp.instance().getApplicationContext(), SetupWizardActivity.class);
intent.putExtra("WIZZARDPAGE", 0); intent.putExtra("WIZZARDPAGE", 0);
// SetupWizardActivity.instance().finish();
// SetupWizardActivity.instance().startActivity(intent);
} }
return SP.contains(R.string.key_language);} return SP.contains(R.string.key_language);}
)) ))
@ -79,111 +77,27 @@ public class SWDefinition {
) )
.add(new SWScreen(R.string.configbuilder_insulin) .add(new SWScreen(R.string.configbuilder_insulin)
.skippable(false) .skippable(false)
.add(new SWRadioButton().option(R.array.insulinArray, R.array.insulinValues).preferenceId(R.string.configbuilder_insulin).label(R.string.configbuilder_insulin).comment(R.string.configbuilder_insulin)) .add(new SWPlugin().option(PluginType.INSULIN).label(R.string.configbuilder_insulin).comment(R.string.configbuilder_insulin))
.validator(() -> { .validator(() -> {
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.INSULIN); ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.INSULIN);
ConfigBuilderPlugin configBuilder = ConfigBuilderPlugin.getPlugin(); return pluginsInCategory != null;
BgSourceInterface activeSource = configBuilder.getActiveBgSource();
if (activeSource == null) {
activeSource = SourceNSClientPlugin.getPlugin();
configBuilder.setPluginEnabled(PluginType.INSULIN, true);
}
// new plugin selected -> disable others
for (PluginBase p : pluginsInCategory) {
log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_insulin, "InsulinOrefRapidActingPlugin"));
if (p.getClass().getSimpleName().equals(SP.getString(R.string.configbuilder_insulin, "InsulinOrefRapidActingPlugin"))) {
// this is new selected
p.setPluginEnabled(PluginType.INSULIN, true);
p.setFragmentVisible(PluginType.INSULIN, true);
String settingVisible = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + p.getClass().getSimpleName() + "_Visible";
String settingEnabled = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
log.debug("Setting to: "+settingEnabled);
SP.putBoolean(settingEnabled, true);
SP.putBoolean(settingVisible, true);
} else {
String settingEnabled = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + p.getName() + "_Enabled";
log.debug("Disable: "+settingEnabled);
p.setPluginEnabled(PluginType.INSULIN, false);
p.setFragmentVisible(PluginType.INSULIN, false);
}
}
String settingVisible = "ConfigBuilder_" + PluginType.INSULIN.name() + "_" + SP.getString(R.string.configbuilder_insulin,"InsulinOrefRapidActingPlugin") + "_Visible";
SP.putBoolean(settingVisible, true);
return SP.contains(R.string.configbuilder_insulin);
}) })
) )
.add(new SWScreen(R.string.configbuilder_aps)
.skippable(false)
.add(new SWRadioButton().option(R.array.apsArray, R.array.apsValues).preferenceId(R.string.configbuilder_aps).label(R.string.configbuilder_aps).comment(R.string.configbuilder_aps))
.validator(() -> {
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.APS);
ConfigBuilderPlugin configBuilder = ConfigBuilderPlugin.getPlugin();
BgSourceInterface activeSource = configBuilder.getActiveBgSource();
if (activeSource == null) {
activeSource = SourceNSClientPlugin.getPlugin();
configBuilder.setPluginEnabled(PluginType.APS, true);
}
// new plugin selected -> disable others
for (PluginBase p : pluginsInCategory) {
log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_aps, "OpenAPSMA"));
if (p.getClass().getSimpleName().equals(SP.getString(R.string.configbuilder_aps, "OpenAPSMA"))) {
// this is new selected
p.setPluginEnabled(PluginType.APS, true);
p.setFragmentVisible(PluginType.APS, true);
String settingVisible = "ConfigBuilder_" + PluginType.APS.name() + "_" + p.getClass().getSimpleName() + "_Visible";
String settingEnabled = "ConfigBuilder_" + PluginType.APS.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
log.debug("Setting to: "+settingEnabled);
SP.putBoolean(settingEnabled, true);
SP.putBoolean(settingVisible, true);
} else {
String settingEnabled = "ConfigBuilder_" + PluginType.APS.name() + "_" + p.getName() + "_Enabled";
log.debug("Disable: "+settingEnabled);
p.setPluginEnabled(PluginType.APS, false);
p.setFragmentVisible(PluginType.APS, false);
}
}
String settingVisible = "ConfigBuilder_" + PluginType.APS.name() + "_" + SP.getString(R.string.configbuilder_aps,"OpenAPSMA") + "_Visible";
SP.putBoolean(settingVisible, true);
return SP.contains(settingVisible);
})
)
.add(new SWScreen(R.string.configbuilder_bgsource) .add(new SWScreen(R.string.configbuilder_bgsource)
.skippable(false) .skippable(false)
.add(new SWRadioButton().option(R.array.BGSourceArray, R.array.BGSourceValues).preferenceId(R.string.configbuilder_bgsource).label(R.string.configbuilder_bgsource).comment(R.string.configbuilder_bgsource)) .add(new SWPlugin().option(PluginType.BGSOURCE).label(R.string.configbuilder_bgsource).comment(R.string.configbuilder_bgsource))
.validator(() -> { .validator(() -> {
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.BGSOURCE); ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.BGSOURCE);
ConfigBuilderPlugin configBuilder = ConfigBuilderPlugin.getPlugin(); return pluginsInCategory != null;
BgSourceInterface activeSource = configBuilder.getActiveBgSource(); })
if (activeSource == null) { )
activeSource = SourceNSClientPlugin.getPlugin(); .add(new SWScreen(R.string.configbuilder_aps)
configBuilder.setPluginEnabled(PluginType.BGSOURCE, true); .skippable(false)
} .add(new SWPlugin().option(PluginType.APS).label(R.string.configbuilder_aps).comment(R.string.configbuilder_aps))
// new plugin selected -> disable others .validator(() -> {
for (PluginBase p : pluginsInCategory) { ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.APS);
log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_bgsource, "SourceNSClient")); return pluginsInCategory != null;
if (p.getClass().getSimpleName().equals(SP.getString(R.string.configbuilder_bgsource, "SourceNSClient"))) { })
// this is new selected
p.setPluginEnabled(PluginType.BGSOURCE, true);
p.setFragmentVisible(PluginType.BGSOURCE, true);
String settingVisible = "ConfigBuilder_" + PluginType.BGSOURCE.name() + "_" + p.getClass().getSimpleName() + "_Visible";
String settingEnabled = "ConfigBuilder_" + PluginType.BGSOURCE.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
log.debug("Setting to: "+settingEnabled);
SP.putBoolean(settingEnabled, true);
SP.putBoolean(settingVisible, true);
} else {
String settingEnabled = "ConfigBuilder_" + PluginType.BGSOURCE.name() + "_" + p.getName() + "_Enabled";
log.debug("Disable: "+settingEnabled);
p.setPluginEnabled(PluginType.BGSOURCE, false);
p.setFragmentVisible(PluginType.BGSOURCE, false);
}
}
String settingVisible = "ConfigBuilder_" + PluginType.BGSOURCE.name() + "_" + SP.getString(R.string.configbuilder_bgsource,"SourceNSClientPlugin") + "_Visible";
SP.putBoolean(settingVisible, true);
return SP.contains(R.string.configbuilder_bgsource);
})
) )
; ;
} }

View file

@ -22,7 +22,8 @@ public class SWItem {
NUMBER, NUMBER,
DECIMALNUMBER, DECIMALNUMBER,
CHECKBOX, CHECKBOX,
RADIOBUTTON RADIOBUTTON,
PLUGIN
} }
Type type; Type type;

View file

@ -0,0 +1,71 @@
package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventConfigBuilderChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
public class SWPlugin extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWPlugin.class);
private PluginType pType;
private RadioGroup radioGroup;
public SWPlugin() {
super(Type.PLUGIN);
}
public SWPlugin option(PluginType pType) {
this.pType = pType;
return this;
}
@Override
public void generateDialog(View view, LinearLayout layout) {
Context context = view.getContext();
radioGroup = new RadioGroup(context);
radioGroup.clearCheck();
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(pType);
for (int row = 0; row < 1; row++) {
radioGroup.setOrientation(LinearLayout.VERTICAL);
radioGroup.setVisibility(View.VISIBLE);
for (int i = 0; i < pluginsInCategory.size(); i++) {
RadioButton rdbtn = new RadioButton(context);
PluginBase p = pluginsInCategory.get(i);
rdbtn.setId(View.generateViewId());
rdbtn.setText(p.getName());
if (p.isEnabled(pType))
rdbtn.setChecked(true);
rdbtn.setTag(p);
radioGroup.addView(rdbtn);
}
}
radioGroup.setOnCheckedChangeListener((group, checkedId) -> {
RadioButton rb = group.findViewById(checkedId);
PluginBase plugin1 = (PluginBase) rb.getTag();
plugin1.setPluginEnabled(pType, rb.isChecked());
plugin1.setFragmentVisible(pType, rb.isChecked());
ConfigBuilderFragment.processOnEnabledCategoryChanged(plugin1, pType);
ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard");
MainApp.bus().post(new EventConfigBuilderChange());
});
layout.addView(radioGroup);
}
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.startupwizard; package info.nightscout.androidaps.startupwizard;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
@ -10,13 +9,9 @@ import android.widget.RadioGroup;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class SWRadioButton extends SWItem { public class SWRadioButton extends SWItem {
@ -32,7 +27,6 @@ public class SWRadioButton extends SWItem {
} }
public SWRadioButton option(int labels, int values) { public SWRadioButton option(int labels, int values) {
this.labelsArray = labels; this.labelsArray = labels;
this.valuesArray = values; this.valuesArray = values;
return this; return this;
@ -47,7 +41,7 @@ public class SWRadioButton extends SWItem {
} }
@Override @Override
public void generateDialog(View view, LinearLayout layout){ public void generateDialog(View view, LinearLayout layout) {
Context context = view.getContext(); Context context = view.getContext();
String[] labels = context.getResources().getStringArray(labelsArray); String[] labels = context.getResources().getStringArray(labelsArray);
String[] values = context.getResources().getStringArray(valuesArray); String[] values = context.getResources().getStringArray(valuesArray);
@ -66,13 +60,13 @@ public class SWRadioButton extends SWItem {
RadioButton rdbtn = new RadioButton(context); RadioButton rdbtn = new RadioButton(context);
rdbtn.setId((row * 2) + i); rdbtn.setId((row * 2) + i);
rdbtn.setText(labels[i]); rdbtn.setText(labels[i]);
if(previousValue.equals(values[i])) if (previousValue.equals(values[i]))
rdbtn.setChecked(true); rdbtn.setChecked(true);
radioGroup.addView(rdbtn); radioGroup.addView(rdbtn);
} }
} }
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onCheckedChanged(RadioGroup group, int checkedId) {
save(); save();
@ -84,12 +78,12 @@ public class SWRadioButton extends SWItem {
} }
public RadioGroup getRadioGroup(){ public RadioGroup getRadioGroup() {
return this.radioGroup; return this.radioGroup;
} }
public String getCheckedValue(){ public String getCheckedValue() {
if(radioGroup != null && radioGroup.getCheckedRadioButtonId() > -1){ if (radioGroup != null && radioGroup.getCheckedRadioButtonId() > -1) {
Context context = radioGroup.getRootView().getContext(); Context context = radioGroup.getRootView().getContext();
String[] values = context.getResources().getStringArray(valuesArray); String[] values = context.getResources().getStringArray(valuesArray);
return values[radioGroup.getCheckedRadioButtonId()]; return values[radioGroup.getCheckedRadioButtonId()];
@ -98,18 +92,18 @@ public class SWRadioButton extends SWItem {
} }
} }
public boolean isSomethingChecked(){ public boolean isSomethingChecked() {
return this.somethingChecked; return this.somethingChecked;
} }
public void save(){ public void save() {
if(!getCheckedValue().equals("none")) { if (!getCheckedValue().equals("none")) {
SP.putString(preferenceId, getCheckedValue()); SP.putString(preferenceId, getCheckedValue());
MainApp.bus().post(new EventPreferenceChange(preferenceId)); MainApp.bus().post(new EventPreferenceChange(preferenceId));
} }
} }
public String preferenceSet(){ public String preferenceSet() {
return SP.getString(preferenceId, "none"); return SP.getString(preferenceId, "none");
} }

View file

@ -105,38 +105,4 @@
<item>@string/no</item> <item>@string/no</item>
<item>@string/yes</item> <item>@string/yes</item>
</string-array> </string-array>
<string-array name="BGSourceArray">
<item>@string/xdrip</item>
<item>@string/DexcomG5</item>
<item>@string/nsclientbg</item>
<item>@string/MM640g</item>
<item>@string/Glimp</item>
</string-array>
<string-array name="BGSourceValues" translatable="false">
<item>SourceXdripPlugin</item>
<item>SourceDexcomG5Plugin</item>
<item>SourceNSClientPlugin</item>
<item>SourceMM640gPlugin</item>
<item>SourceGlimpPlugin</item>
</string-array>
<string-array name="insulinArray">
<item>@string/fastactinginsulincomment</item>
<item>@string/ultrafastactinginsulincomment</item>
<item>@string/free_peak_oref</item>
</string-array>
<string-array name="insulinValues" translatable="false">
<item>InsulinOrefRapidActingPlugin</item>
<item>InsulinOrefUltraRapidActingPlugin</item>
<item>InsulinOrefFreePeakPlugin</item>
</string-array>
<string-array name="apsArray">
<item>@string/openapsma</item>
<item>@string/openapsama</item>
<item>@string/openapssmb</item>
</string-array>
<string-array name="apsValues" translatable="false">
<item>OpenAPSMAPlugin</item>
<item>OpenAPSAMAPlugin</item>
<item>OpenAPSSMBPlugin</item>
</string-array>
</resources> </resources>