Merge branch 'startupwizard' of https://github.com/MilosKozak/AndroidAPS into dev

This commit is contained in:
Roumen Georgiev 2018-05-10 12:51:12 +03:00
commit 06180e3bbd
28 changed files with 459 additions and 273 deletions

View file

@ -0,0 +1,4 @@
package info.nightscout.androidaps.events;
public class EventProfileStoreChanged extends Event {
}

View file

@ -4,7 +4,6 @@ package info.nightscout.androidaps.plugins.ProfileLocal;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
@ -23,7 +22,6 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.interfaces.PumpDescription;
@ -109,34 +107,25 @@ public class LocalProfileFragment extends SubscriberFragment {
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
mgdlView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl;
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
doEdit();
}
mgdlView.setOnClickListener(v -> {
LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl;
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
doEdit();
});
mmolView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked();
LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol;
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
doEdit();
}
mmolView.setOnClickListener(v -> {
LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked();
LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol;
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
doEdit();
});
profileswitchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT;
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
}
profileswitchButton.setOnClickListener(view -> {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT;
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
});
resetButton.setOnClickListener(view -> {

View file

@ -13,6 +13,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventProfileStoreChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
@ -81,6 +82,7 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
edited = false;
if (Config.logPrefsChange)
log.debug("Storing settings: " + getRawProfile().getData().toString());
MainApp.bus().post(new EventProfileStoreChanged());
}
public synchronized void loadSettings() {

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventProfileStoreChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
@ -43,7 +44,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
super(new PluginDescription()
.mainType(PluginType.PROFILE)
.fragmentClass(NSProfileFragment.class.getName())
.pluginName(R.string.profileviewer)
.pluginName(R.string.nsprofile)
.shortName(R.string.profileviewer_shortname)
.alwaysEnabled(Config.NSCLIENT)
.alwayVisible(Config.NSCLIENT)
@ -68,6 +69,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
profile = new ProfileStore(newProfile.getData());
storeNSProfile();
MainApp.bus().post(new EventNSProfileUpdateGUI());
MainApp.bus().post(new EventProfileStoreChanged());
}
private void storeNSProfile() {

View file

@ -73,34 +73,25 @@ public class SimpleProfileFragment extends SubscriberFragment {
targetlowView.setText(SimpleProfilePlugin.getPlugin().targetLow.toString());
targethighView.setText(SimpleProfilePlugin.getPlugin().targetHigh.toString());
mgdlView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
SimpleProfilePlugin.getPlugin().mmol = !SimpleProfilePlugin.getPlugin().mgdl;
mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol);
SimpleProfilePlugin.getPlugin().storeSettings();
}
mgdlView.setOnClickListener(v -> {
SimpleProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
SimpleProfilePlugin.getPlugin().mmol = !SimpleProfilePlugin.getPlugin().mgdl;
mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol);
SimpleProfilePlugin.getPlugin().storeSettings();
});
mmolView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleProfilePlugin.getPlugin().mmol = mmolView.isChecked();
SimpleProfilePlugin.getPlugin().mgdl = !SimpleProfilePlugin.getPlugin().mmol;
mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl);
SimpleProfilePlugin.getPlugin().storeSettings();
}
mmolView.setOnClickListener(v -> {
SimpleProfilePlugin.getPlugin().mmol = mmolView.isChecked();
SimpleProfilePlugin.getPlugin().mgdl = !SimpleProfilePlugin.getPlugin().mmol;
mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl);
SimpleProfilePlugin.getPlugin().storeSettings();
});
profileswitchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH;
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
}
profileswitchButton.setOnClickListener(view -> {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH;
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
});
TextWatcher textWatch = new TextWatcher() {
@ -152,20 +143,17 @@ public class SimpleProfileFragment extends SubscriberFragment {
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
boolean isValid = SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile));
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended() || !isValid) {
profileswitchButton.setVisibility(View.GONE);
} else {
profileswitchButton.setVisibility(View.VISIBLE);
}
if (isValid)
invalidProfile.setVisibility(View.GONE);
else
invalidProfile.setVisibility(View.VISIBLE);
activity.runOnUiThread(() -> {
boolean isValid = SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile));
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended() || !isValid) {
profileswitchButton.setVisibility(View.GONE);
} else {
profileswitchButton.setVisibility(View.VISIBLE);
}
if (isValid)
invalidProfile.setVisibility(View.GONE);
else
invalidProfile.setVisibility(View.VISIBLE);
});
}

View file

@ -14,6 +14,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventProfileStoreChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
@ -73,6 +74,7 @@ public class SimpleProfilePlugin extends PluginBase implements ProfileInterface
createConvertedProfile();
if (Config.logPrefsChange)
log.debug("Storing settings: " + getRawProfile().getData().toString());
MainApp.bus().post(new EventProfileStoreChanged());
}
private void loadSettings() {

View file

@ -1,7 +1,9 @@
package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -13,13 +15,23 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.PreferencesActivity;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventConfigBuilderChange;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfileFragment;
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin;
import info.nightscout.androidaps.startupwizard.events.EventSWLabel;
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
import info.nightscout.utils.LocaleHelper;
import info.nightscout.utils.PasswordProtection;
@ -28,14 +40,18 @@ import info.nightscout.utils.SP;
public class SWDefinition {
private static Logger log = LoggerFactory.getLogger(SWDefinition.class);
private Context context;
static List<SWScreen> screens = new ArrayList<>();
private AppCompatActivity activity;
private List<SWScreen> screens = new ArrayList<>();
public void setContext(Context context) {
this.context = context;
public void setActivity(AppCompatActivity activity) {
this.activity = activity;
}
public static List<SWScreen> getScreens() {
public AppCompatActivity getActivity() {
return activity;
}
public List<SWScreen> getScreens() {
return screens;
}
@ -54,109 +70,162 @@ public class SWDefinition {
.add(new SWInfotext()
.label(R.string.welcometosetupwizard) )
)
.add(new SWScreen(R.string.language)
.add(new SWScreen(R.string.language)
.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(() -> {
String lang = SP.getString("language", "en");
LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang);
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))
.add(new SWButton()
.text(R.string.enable_nsclient)
.action(() -> {
NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true);
NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true);
ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL);
ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard");
MainApp.bus().post(new EventConfigBuilderChange());
MainApp.bus().post(new EventSWUpdate(true));
})
.visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL)))
.validator(() -> NSClientPlugin.getPlugin().nsClientService != null && 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))
)
.add(new SWScreen(R.string.configbuilder_insulin)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.INSULIN)
.label(R.string.configbuilder_insulin))
.validator(() -> MainApp.getConfigBuilder().getActiveInsulin() != null)
)
.add(new SWScreen(R.string.configbuilder_bgsource)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.BGSOURCE)
.label(R.string.configbuilder_bgsource))
.validator(() -> MainApp.getConfigBuilder().getActiveBgSource() != null)
)
.add(new SWScreen(R.string.configbuilder_profile)
.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(() -> {
String lang = SP.getString("language", "en");
LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang);
return SP.contains(R.string.key_language);
.add(new SWPlugin()
.option(PluginType.PROFILE)
.label(R.string.configbuilder_profile))
.validator(() -> MainApp.getConfigBuilder().getActiveProfileInterface() != null)
)
.add(new SWScreen(R.string.nsprofile)
.skippable(false)
.add(new SWInfotext()
.label(R.string.adjustprofileinns))
.add(new SWFragment(this)
.add(new NSProfileFragment()))
.validator(() -> NSProfilePlugin.getPlugin().getProfile() != null && NSProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard"))
.visibility(() -> NSProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE))
)
.add(new SWScreen(R.string.localprofile)
.skippable(false)
.add(new SWFragment(this)
.add(new LocalProfileFragment()))
.validator(() -> LocalProfilePlugin.getPlugin().getProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard"))
.visibility(() -> LocalProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE))
)
.add(new SWScreen(R.string.simpleprofile)
.skippable(false)
.add(new SWFragment(this)
.add(new SimpleProfileFragment()))
.validator(() -> SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard"))
.visibility(() -> SimpleProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE))
)
.add(new SWScreen(R.string.profileswitch)
.skippable(false)
.add(new SWInfotext()
.label(R.string.profileswitch_ismissing))
.add(new SWButton()
.text(R.string.profileswitch)
.action(() -> {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT;
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
newDialog.show(getActivity().getSupportFragmentManager(), "NewNSTreatmentDialog");
}))
.validator(() -> MainApp.getConfigBuilder().getProfile() != null)
.visibility(() -> MainApp.getConfigBuilder().getProfile() == null)
)
.add(new SWScreen(R.string.configbuilder_pump)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.PUMP)
.label(R.string.configbuilder_pump))
.add(new SWButton()
.text(R.string.pumpsetup)
.action(() -> {
final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActivePump();
PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> {
Intent i = new Intent(activity, PreferencesActivity.class);
i.putExtra("id", plugin.getPreferencesId());
activity.startActivity(i);
}, null);
})
.visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0))
.add(new SWButton()
.text(R.string.readstatus)
.action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null))
.visibility(() -> MainApp.getConfigBuilder().getActivePump() != null))
.add(new SWEventListener(this)
.listener(new Object() {
@Subscribe
public void onEventPumpStatusChanged(EventPumpStatusChanged event) {
MainApp.bus().post(new EventSWLabel(event.textStatus()));
}
})
)
.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))
.add(new SWButton()
.text(R.string.enable_nsclient)
.action(() -> {
NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true);
NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true);
ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL);
ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard");
MainApp.bus().post(new EventConfigBuilderChange());
MainApp.bus().post(new EventSWUpdate(true));
})
.visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL)))
.validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth)
)
.add(NSClientPlugin.getPlugin().nsClientService != null ? new SWScreen(R.string.nsclientinternal_title)
.skippable(true)
.add(new SWButton()
.text(R.string.nsclient_prefs)
.action(() -> {
final PluginBase plugin = (PluginBase) NSClientPlugin.getPlugin();
PasswordProtection.QueryPassword(context, R.string.settings_password, "settings_password", () -> {
Intent i = new Intent(context, PreferencesActivity.class);
i.putExtra("id", plugin.getPreferencesId());
context.startActivity(i);
}, null);
})
.visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0)): new SWScreen(R.string.nav_setupwizard)
.add(new SWInfotext()
.label(R.string.settings_incorrect) )
)
.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))
)
.add(new SWScreen(R.string.configbuilder_insulin)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.INSULIN)
.label(R.string.configbuilder_insulin))
.validator(() -> MainApp.getSpecificPluginsList(PluginType.INSULIN) != null)
)
.add(new SWScreen(R.string.configbuilder_bgsource)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.BGSOURCE)
.label(R.string.configbuilder_bgsource))
.validator(() -> MainApp.getSpecificPluginsList(PluginType.BGSOURCE) != null)
)
.add(new SWScreen(R.string.configbuilder_pump)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.PUMP)
.label(R.string.configbuilder_pump))
.add(new SWButton()
.text(R.string.pumpsetup)
.action(() -> {
final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActivePump();
PasswordProtection.QueryPassword(context, R.string.settings_password, "settings_password", () -> {
Intent i = new Intent(context, PreferencesActivity.class);
i.putExtra("id", plugin.getPreferencesId());
context.startActivity(i);
}, null);
})
.visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0))
.add(new SWButton()
.text(R.string.readstatus)
.action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null))
.visibility(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null))
.validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null && MainApp.getConfigBuilder().getActivePump().isInitialized())
)
.add(new SWScreen(R.string.configbuilder_aps)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.APS)
.label(R.string.configbuilder_aps))
.validator(() -> MainApp.getSpecificPluginsList(PluginType.APS) != null )
)
.validator(() -> MainApp.getConfigBuilder().getActivePump() != null && MainApp.getConfigBuilder().getActivePump().isInitialized())
)
.add(new SWScreen(R.string.configbuilder_aps)
.skippable(false)
.add(new SWPlugin()
.option(PluginType.APS)
.label(R.string.configbuilder_aps))
.validator(() -> MainApp.getConfigBuilder().getActiveAPS() != null)
)
.add(new SWScreen(R.string.configbuilder_loop)
.skippable(false)
.add(new SWButton()
.text(R.string.enableloop)
.action(() -> {
LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, true);
LoopPlugin.getPlugin().setFragmentVisible(PluginType.LOOP, true);
ConfigBuilderFragment.processOnEnabledCategoryChanged(LoopPlugin.getPlugin(), PluginType.LOOP);
ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard");
MainApp.bus().post(new EventConfigBuilderChange());
MainApp.bus().post(new EventSWUpdate(true));
}))
.validator(() -> LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))
.visibility(() -> !LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))
)
;
}

View file

@ -0,0 +1,55 @@
package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.startupwizard.events.EventSWLabel;
public class SWEventListener extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWEventListener.class);
TextView textView;
Object listener;
SWDefinition definition;
SWEventListener(SWDefinition definition) {
super(Type.LISTENER);
this.definition = definition;
MainApp.bus().register(this);
}
public SWEventListener listener(Object listener) {
this.listener = listener;
return this;
}
@Override
public void generateDialog(View view, LinearLayout layout) {
Context context = view.getContext();
textView = new TextView(context);
textView.setId(view.generateViewId());
layout.addView(textView);
if (listener != null)
MainApp.bus().register(listener);
}
@Subscribe
public void onEventSWLabel(final EventSWLabel l) {
if (definition != null && definition.getActivity() != null)
definition.getActivity().runOnUiThread(() -> {
if (textView != null)
textView.setText(l.label);
});
}
}

View file

@ -0,0 +1,32 @@
package info.nightscout.androidaps.startupwizard;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.LinearLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SWFragment extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWFragment.class);
SWDefinition definition;
Fragment fragment;
public SWFragment(SWDefinition definition) {
super(Type.FRAGMENT);
this.definition = definition;
}
public SWFragment add(Fragment fragment) {
this.fragment = fragment;
return this;
}
@Override
public void generateDialog(View view, LinearLayout layout) {
definition.getActivity().getSupportFragmentManager().beginTransaction().add(layout.getId(), fragment, fragment.getTag()).commit();
}
}

View file

@ -17,6 +17,7 @@ public class SWItem {
enum Type {
NONE,
TEXT,
LISTENER,
URL,
STRING,
NUMBER,
@ -24,7 +25,8 @@ public class SWItem {
CHECKBOX,
RADIOBUTTON,
PLUGIN,
BUTTON
BUTTON,
FRAGMENT
}
Type type;

View file

@ -10,6 +10,7 @@ public class SWScreen {
int header;
List<SWItem> items = new ArrayList<>();
SWValidator validator;
SWValidator visibility;
boolean skippable = false;
public SWScreen(int header) {
@ -35,6 +36,11 @@ public class SWScreen {
return this;
}
public SWScreen visibility(SWValidator visibility) {
this.visibility = visibility;
return this;
}
public void processVisibility() {
for (SWItem i : items)
i.processVisibility();

View file

@ -17,19 +17,19 @@ import java.util.List;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventProfileStoreChanged;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
import info.nightscout.utils.LocaleHelper;
import info.nightscout.utils.OKDialog;
public class SetupWizardActivity extends AppCompatActivity {
//logging
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
private TextView screenName;
SWDefinition swDefinition = new SWDefinition();
List<SWScreen> screens = swDefinition.getScreens();
private SWDefinition swDefinition = new SWDefinition();
private List<SWScreen> screens = swDefinition.getScreens();
private int currentWizardPage = 0;
public static final String INTENT_MESSAGE = "WIZZARDPAGE";
@ -44,15 +44,21 @@ public class SetupWizardActivity extends AppCompatActivity {
SWScreen currentScreen = screens.get(currentWizardPage);
//Set screen name
screenName = (TextView) findViewById(R.id.sw_content);
TextView screenName = (TextView) findViewById(R.id.sw_content);
screenName.setText(currentScreen.getHeader());
swDefinition.setActivity(this);
//Generate layout first
generateLayout();
updateButtons();
}
}
@Override
public void onBackPressed() {
OKDialog.showConfirmation(this, MainApp.gs(R.string.exitwizard), this::finish);
}
@Override
public void onPause() {
super.onPause();
@ -63,7 +69,7 @@ public class SetupWizardActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
MainApp.bus().register(this);
swDefinition.setContext(this);
swDefinition.setActivity(this);
}
@Subscribe
@ -83,6 +89,11 @@ public class SetupWizardActivity extends AppCompatActivity {
updateButtons();
}
@Subscribe
public void onEventProfileStoreChanged(EventProfileStoreChanged ignored) {
updateButtons();
}
private void generateLayout() {
SWScreen currentScreen = screens.get(currentWizardPage);
LinearLayout layout = SWItem.generateLayout(this.findViewById(R.id.sw_content_fields));
@ -93,40 +104,39 @@ public class SetupWizardActivity extends AppCompatActivity {
}
private void updateButtons() {
SWScreen currentScreen = screens.get(currentWizardPage);
if (currentScreen.validator == null || currentScreen.validator.isValid() || currentScreen.skippable) {
if (currentWizardPage == screens.size() - 1) {
findViewById(R.id.finish_button).setVisibility(View.VISIBLE);
findViewById(R.id.next_button).setVisibility(View.GONE);
runOnUiThread(() -> {
SWScreen currentScreen = screens.get(currentWizardPage);
if (currentScreen.validator == null || currentScreen.validator.isValid() || currentScreen.skippable) {
if (currentWizardPage == nextPage()) {
findViewById(R.id.finish_button).setVisibility(View.VISIBLE);
findViewById(R.id.next_button).setVisibility(View.GONE);
} else {
findViewById(R.id.finish_button).setVisibility(View.GONE);
findViewById(R.id.next_button).setVisibility(View.VISIBLE);
}
} else {
findViewById(R.id.finish_button).setVisibility(View.GONE);
findViewById(R.id.next_button).setVisibility(View.VISIBLE);
findViewById(R.id.next_button).setVisibility(View.GONE);
}
} else {
findViewById(R.id.finish_button).setVisibility(View.GONE);
findViewById(R.id.next_button).setVisibility(View.GONE);
}
if (currentWizardPage == 0)
findViewById(R.id.previous_button).setVisibility(View.GONE);
else
findViewById(R.id.previous_button).setVisibility(View.VISIBLE);
currentScreen.processVisibility();
if (currentWizardPage == 0)
findViewById(R.id.previous_button).setVisibility(View.GONE);
else
findViewById(R.id.previous_button).setVisibility(View.VISIBLE);
currentScreen.processVisibility();
});
}
public void showNextPage(View view) {
this.finish();
Intent intent = new Intent(this, SetupWizardActivity.class);
intent.putExtra(INTENT_MESSAGE, currentWizardPage + 1);
intent.putExtra(INTENT_MESSAGE, nextPage());
startActivity(intent);
}
public void showPreviousPage(View view) {
this.finish();
Intent intent = new Intent(this, SetupWizardActivity.class);
if (currentWizardPage > 0)
intent.putExtra(INTENT_MESSAGE, currentWizardPage - 1);
else
intent.putExtra(INTENT_MESSAGE, 0);
intent.putExtra(INTENT_MESSAGE, previousPage());
startActivity(intent);
}
@ -136,4 +146,23 @@ public class SetupWizardActivity extends AppCompatActivity {
startActivity(intent);
}
private int nextPage() {
int page = currentWizardPage + 1;
while (page < screens.size()) {
if (screens.get(page).visibility == null || screens.get(page).visibility.isValid())
return page;
page++;
}
return currentWizardPage;
}
private int previousPage() {
int page = currentWizardPage - 1;
while (page > 0) {
if (screens.get(page).visibility == null || screens.get(page).visibility.isValid())
return page;
page--;
}
return currentWizardPage;
}
}

View file

@ -0,0 +1,11 @@
package info.nightscout.androidaps.startupwizard.events;
import info.nightscout.androidaps.events.Event;
public class EventSWLabel extends Event {
public String label;
public EventSWLabel(String label) {
this.label = label;
}
}

View file

@ -1,79 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
android:orientation="vertical"
tools:context=".startupwizard.SetupWizardActivity">
<TextView
android:id="@+id/sw_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:keepScreenOn="true"
android:text="@string/dummy_content"
android:textColor="#33b5e5"
android:textSize="20dp"
android:textStyle="bold" />
<FrameLayout
<LinearLayout
android:id="@+id/sw_content_fields"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<LinearLayout
android:id="@+id/sw_content_fields"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/sw_content_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/sw_content_controls"
android:layout_width="match_parent"
<Button
android:id="@+id/previous_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:orientation="horizontal">
android:layout_weight="1"
android:onClick="showPreviousPage"
android:text="@string/setupwizard_previous" />
<Button
android:id="@+id/previous_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showPreviousPage"
android:text="@string/setupwizard_previous" />
<Button
android:id="@+id/skip_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showNextPage"
android:text="@string/setupwizard_skip"
android:visibility="invisible" />
<Button
android:id="@+id/skip_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showNextPage"
android:text="@string/setupwizard_skip"
android:visibility="invisible" />
<Button
android:id="@+id/next_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showNextPage"
android:text="@string/setupwizard_next"
android:visibility="gone" />
<Button
android:id="@+id/next_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showNextPage"
android:text="@string/setupwizard_next"
android:visibility="gone" />
<Button
android:id="@+id/finish_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="finishSetupWizard"
android:text="@string/setupwizard_finish"
android:visibility="gone" />
<Button
android:id="@+id/finish_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="finishSetupWizard"
android:text="@string/setupwizard_finish"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</FrameLayout>
</LinearLayout>

View file

@ -71,7 +71,7 @@
<string name="objectives">Цели</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Общ</string>
<string name="profileviewer">NS Профил</string>
<string name="nsprofile">NS Профил</string>
<string name="simpleprofile">Обикновен профил</string>
<string name="tempbasal">TempBasal</string>
<string name="treatments">Лечения</string>

View file

@ -110,7 +110,7 @@
<string name="overview_newtempbasal_basalpercent">Hodnota bazálu [%]</string>
<string name="overview_newtempbasal_percent_label">% (100% = současný)</string>
<string name="overview_treatment_label">Bolus</string>
<string name="profileviewer">NS profil</string>
<string name="nsprofile">NS profil</string>
<string name="objectives_pumpstatusavailableinns">Stav pumpy dostupný v NS</string>
<string name="rate">Hodnota</string>
<string name="reason">Zdůvodnění</string>

View file

@ -16,7 +16,7 @@
<string name="days">Tage</string>
<string name="ok">OK</string>
<string name="openapsma_profile_label">Profil</string>
<string name="profileviewer">Nightscout-Profil</string>
<string name="nsprofile">Nightscout-Profil</string>
<string name="tempbasals_iob_label_string">IOB:</string>
<string name="tempbasals_iobtotal_label_string">Gesamt-IOB:</string>
<string name="tempbasals_netinsulin_label_string">Ins:</string>

View file

@ -72,7 +72,7 @@
<string name="objectives">Στόχοι</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Επισκόπηση</string>
<string name="profileviewer">Προφίλ NS</string>
<string name="nsprofile">Προφίλ NS</string>
<string name="simpleprofile">Απλό Προφίλ</string>
<string name="tempbasal">Προσ.Ρυθμός</string>
<string name="treatments">Θεραπείες</string>

View file

@ -71,7 +71,7 @@
<string name="objectives">Objetivos</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Sinopsis</string>
<string name="profileviewer">Perfil NS</string>
<string name="nsprofile">Perfil NS</string>
<string name="simpleprofile">Perfil simple</string>
<string name="tempbasal">Basal temporal</string>
<string name="treatments">Tratamientos</string>

View file

@ -67,7 +67,7 @@
<string name="objectives">Objectifs</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Aperçu</string>
<string name="profileviewer">Profil NS</string>
<string name="nsprofile">Profil NS</string>
<string name="simpleprofile">Profil simple</string>
<string name="tempbasal">Basal Tempo</string>
<string name="treatments">Traitements</string>

View file

@ -454,7 +454,7 @@
<string name="simpleprofile_shortname">SP</string>
<string name="quickwizard">QuickWizard</string>
<string name="quickwizardsettings">Impostazioni QuickWizard</string>
<string name="profileviewer">Profilo NS</string>
<string name="nsprofile">Profilo NS</string>
<string name="profile_set_ok">Profilo Basale aggiornato nel Micro</string>
<string name="profile_set_failed">Impostazione Profilo Basale fallito</string>
</resources>

View file

@ -71,7 +71,7 @@
<string name="objectives">목표</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">개요</string>
<string name="profileviewer">NS 프로파일</string>
<string name="nsprofile">NS 프로파일</string>
<string name="simpleprofile">Simple 프로파일</string>
<string name="tempbasal">임시기초</string>
<string name="treatments">관리</string>

View file

@ -426,7 +426,7 @@
<string name="openapsma_inputparameters_label">Berekende gegevens</string>
<string name="openapsma_iobdata_label">IOB gegevens</string>
<string name="openapsma_maxbasal_summary">DIt is de maximale waarde waarop het basaal door OpenAPS ingesteld kan worden</string>
<string name="profileviewer">NS Profiel</string>
<string name="nsprofile">NS Profiel</string>
<string name="profileviewer_shortname">NSPROFIEL</string>
<string name="pump">Pomp</string>
<string name="overview_tempbasal_button">Tijdelijk basaal</string>

View file

@ -75,7 +75,7 @@
<string name="objectives">Zadania</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Przegląd</string>
<string name="profileviewer">NS Profil</string>
<string name="nsprofile">NS Profil</string>
<string name="simpleprofile">Prosty profil</string>
<string name="tempbasal">TymczasowaBaza</string>
<string name="treatments">Leczenie</string>

View file

@ -69,7 +69,7 @@
<string name="objectives">Obiective</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Privire ansamblu</string>
<string name="profileviewer">Profil NS</string>
<string name="nsprofile">Profil NS</string>
<string name="simpleprofile">Profil simplu</string>
<string name="treatments">Tratamente</string>
<string name="virtualpump">Pompă virtuală</string>

View file

@ -374,7 +374,7 @@
<string name="profile">профиль</string>
<string name="profile_set_failed">настройка базального профиля не состоялась</string>
<string name="profile_set_ok">базальный профиль помпы обновлен</string>
<string name="profileviewer">профиль NS</string>
<string name="nsprofile">профиль NS</string>
<string name="profileviewer_shortname">профильNS</string>
<string name="pumpNotInitialized">помпа не инициализирована</string>
<string name="pumpNotInitializedProfileNotSet">помпа не инициализирована, профиль не установлен</string>

View file

@ -430,7 +430,7 @@
<string name="pumpNotInitialized">Pump inte initierad</string>
<string name="pump">Pump</string>
<string name="profileviewer_shortname">NSProfil</string>
<string name="profileviewer">NS-profil</string>
<string name="nsprofile">NS-profil</string>
<string name="profileswitch">Profilbyte</string>
<string name="profile_set_ok">Basalprofilen uppdaterad i pumpen</string>
<string name="profile_set_failed">Lyckades inte sätta basalprofilen</string>

View file

@ -74,7 +74,7 @@
<string name="objectives">Objectives</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Overview</string>
<string name="profileviewer">NS Profile</string>
<string name="nsprofile">NS Profile</string>
<string name="simpleprofile">Simple profile</string>
<string name="tempbasal">TempBasal</string>
<string name="treatments">Treatments</string>
@ -1059,13 +1059,14 @@
<string name="wear_wizard_settings_summary">Calculations included in the Wizard result:</string>
<string name="wear_display_settings">Display Settings</string>
<string name="wear_general_settings">General Settings</string>
<string name="dummy_content">DUMMY\nCONTENT</string>
<string name="enable_nsclient">Connect to NightScout</string>
<string name="nsclient_prefs">Additional NSClient options</string>
<string name="settings_incorrect">Incorrect settings! Press \'BACK\' and try again</string>
<string name="enable_nsclient">Enable NSClient</string>
<string name="welcometosetupwizard">Welcome to setup wizard. It will guide you through the setup process</string>
<string name="pumpsetup">Pump setup</string>
<string name="readstatus">Read status</string>
<string name="settings_incorrect">Incorrect settings! Press \'BACK\' and try again</string>
<string name="adjustprofileinns">Changes must be done in NS</string>
<string name="exitwizard">Exit setup wizard?</string>
</resources>