Merge pull request #988 from PoweRGbg/dev
added insulin, APS, BGSOURCEscreens
This commit is contained in:
commit
d025b4b03d
5 changed files with 188 additions and 9 deletions
|
@ -1,19 +1,30 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
|
||||
import info.nightscout.utils.LocaleHelper;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class SWDefinition {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(SWDefinition.class);
|
||||
private static SWDefinition swDefinition = null;
|
||||
|
||||
public static SWDefinition getInstance() {
|
||||
if (swDefinition == null)
|
||||
swDefinition = new SWDefinition();
|
||||
|
@ -32,6 +43,8 @@ public class SWDefinition {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
SWDefinition() {
|
||||
// List all the screens here
|
||||
// todo: SWValidator ?!?
|
||||
|
@ -39,23 +52,139 @@ public class SWDefinition {
|
|||
.skippable(false)
|
||||
.add(new SWRadioButton().option(R.array.languagesArray, R.array.languagesValues).preferenceId(R.string.key_language).label(R.string.language).comment(R.string.setupwizard_language_prompt))
|
||||
.validator(() -> {
|
||||
context = MainApp.instance().getApplicationContext();
|
||||
LocaleHelper.setLocale(context, SP.getString(R.string.key_language, "en"));
|
||||
MainApp.bus().post(new EventRefreshGui(true));
|
||||
if(!SP.getString(R.string.key_language, "en").equals(LocaleHelper.getLanguage(context))) {
|
||||
Intent intent = new Intent(MainApp.instance().getApplicationContext(), SetupWizardActivity.class);
|
||||
intent.putExtra("WIZZARDPAGE", 0);
|
||||
// SetupWizardActivity.instance().finish();
|
||||
// SetupWizardActivity.instance().startActivity(intent);
|
||||
}
|
||||
return SP.contains(R.string.key_language);}
|
||||
))
|
||||
.add(new SWScreen(R.string.nsclientinternal_title)
|
||||
.skippable(true)
|
||||
.add(new SWUrl().preferenceId(R.string.key_nsclientinternal_url).label(R.string.nsclientinternal_url_title).comment(R.string.nsclientinternal_url_dialogmessage))
|
||||
.add(new SWString().preferenceId(R.string.key_nsclientinternal_api_secret).label(R.string.nsclientinternal_secret_dialogtitle).comment(R.string.nsclientinternal_secret_dialogmessage))
|
||||
.validator(() -> NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth)
|
||||
.validator(() -> {
|
||||
return NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth;
|
||||
})
|
||||
)
|
||||
.add(new SWScreen(R.string.patientage)
|
||||
.skippable(false)
|
||||
.add(new SWRadioButton().option(R.array.ageArray, R.array.ageValues).preferenceId(R.string.key_age).label(R.string.patientage).comment(R.string.patientage_summary))
|
||||
.validator(() -> SP.contains(R.string.key_age))
|
||||
.validator(() -> {
|
||||
return SP.contains(R.string.key_age);
|
||||
})
|
||||
)
|
||||
.add(new SWScreen(R.string.configbuilder_insulin)
|
||||
.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))
|
||||
.validator(() -> {
|
||||
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.INSULIN);
|
||||
ConfigBuilderPlugin configBuilder = ConfigBuilderPlugin.getPlugin();
|
||||
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)
|
||||
.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))
|
||||
.validator(() -> {
|
||||
ArrayList<PluginBase> pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.BGSOURCE);
|
||||
ConfigBuilderPlugin configBuilder = ConfigBuilderPlugin.getPlugin();
|
||||
BgSourceInterface activeSource = configBuilder.getActiveBgSource();
|
||||
if (activeSource == null) {
|
||||
activeSource = SourceNSClientPlugin.getPlugin();
|
||||
configBuilder.setPluginEnabled(PluginType.BGSOURCE, true);
|
||||
}
|
||||
// new plugin selected -> disable others
|
||||
for (PluginBase p : pluginsInCategory) {
|
||||
log.debug("Name is: "+ p.getClass().getSimpleName() + " setting is: "+SP.getString(R.string.configbuilder_bgsource, "SourceNSClient"));
|
||||
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);
|
||||
})
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
|
@ -9,8 +10,13 @@ import android.widget.RadioGroup;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class SWRadioButton extends SWItem {
|
||||
|
@ -26,6 +32,7 @@ public class SWRadioButton extends SWItem {
|
|||
}
|
||||
|
||||
public SWRadioButton option(int labels, int values) {
|
||||
|
||||
this.labelsArray = labels;
|
||||
this.valuesArray = values;
|
||||
return this;
|
||||
|
@ -42,8 +49,6 @@ public class SWRadioButton extends SWItem {
|
|||
@Override
|
||||
public void generateDialog(View view, LinearLayout layout){
|
||||
Context context = view.getContext();
|
||||
// LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
|
||||
// layout.removeAllViews();
|
||||
String[] labels = context.getResources().getStringArray(labelsArray);
|
||||
String[] values = context.getResources().getStringArray(valuesArray);
|
||||
// Get if there is already value in SP
|
||||
|
@ -71,6 +76,7 @@ public class SWRadioButton extends SWItem {
|
|||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
save();
|
||||
MainApp.bus().post(new EventRefreshGui(true));
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.utils.LocaleHelper;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class SWScreen {
|
||||
|
||||
|
@ -40,4 +50,5 @@ public class SWScreen {
|
|||
return validator.isValid();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -105,5 +105,38 @@
|
|||
<item>@string/no</item>
|
||||
<item>@string/yes</item>
|
||||
</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>
|
Loading…
Reference in a new issue