SWButton
This commit is contained in:
parent
88d964f135
commit
55661ca7a0
|
@ -0,0 +1,52 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SWButton extends SWItem {
|
||||
private static Logger log = LoggerFactory.getLogger(SWButton.class);
|
||||
|
||||
Runnable buttonRunnable;
|
||||
int buttonText;
|
||||
SWValidator buttonValidator;
|
||||
|
||||
public SWButton() {
|
||||
super(Type.BUTTON);
|
||||
}
|
||||
|
||||
public SWButton option(int buttonText) {
|
||||
this.buttonText = buttonText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWButton action(Runnable buttonRunnable) {
|
||||
this.buttonRunnable = buttonRunnable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWButton visibility(SWValidator buttonValidator) {
|
||||
this.buttonValidator = buttonValidator;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(View view, LinearLayout layout) {
|
||||
Context context = view.getContext();
|
||||
|
||||
Button button = new Button(context);
|
||||
button.setText(buttonText);
|
||||
button.setOnClickListener((v) -> {
|
||||
if (buttonRunnable != null)
|
||||
buttonRunnable.run();
|
||||
});
|
||||
if (buttonValidator != null && !buttonValidator.isValid())
|
||||
return;
|
||||
layout.addView(button);
|
||||
super.generateDialog(view, layout);
|
||||
}
|
||||
}
|
|
@ -8,8 +8,13 @@ import java.util.List;
|
|||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
|
||||
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
|
||||
import info.nightscout.utils.LocaleHelper;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
@ -39,7 +44,10 @@ public class SWDefinition {
|
|||
// List all the screens here
|
||||
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))
|
||||
.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);
|
||||
|
@ -48,28 +56,58 @@ public class SWDefinition {
|
|||
)
|
||||
.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 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()
|
||||
.option(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))
|
||||
.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).comment(R.string.configbuilder_insulin))
|
||||
.add(new SWPlugin()
|
||||
.option(PluginType.INSULIN)
|
||||
.label(R.string.configbuilder_insulin)
|
||||
.comment(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).comment(R.string.configbuilder_bgsource))
|
||||
.add(new SWPlugin()
|
||||
.option(PluginType.BGSOURCE)
|
||||
.label(R.string.configbuilder_bgsource)
|
||||
.comment(R.string.configbuilder_bgsource))
|
||||
.validator(() -> MainApp.getSpecificPluginsList(PluginType.BGSOURCE) != null)
|
||||
)
|
||||
.add(new SWScreen(R.string.configbuilder_aps)
|
||||
.skippable(false)
|
||||
.add(new SWPlugin().option(PluginType.APS).label(R.string.configbuilder_aps).comment(R.string.configbuilder_aps))
|
||||
.add(new SWPlugin()
|
||||
.option(PluginType.APS)
|
||||
.label(R.string.configbuilder_aps)
|
||||
.comment(R.string.configbuilder_aps))
|
||||
.validator(() -> MainApp.getSpecificPluginsList(PluginType.APS) != null)
|
||||
)
|
||||
;
|
||||
|
|
|
@ -22,7 +22,8 @@ public class SWItem {
|
|||
DECIMALNUMBER,
|
||||
CHECKBOX,
|
||||
RADIOBUTTON,
|
||||
PLUGIN
|
||||
PLUGIN,
|
||||
BUTTON
|
||||
}
|
||||
|
||||
Type type;
|
||||
|
@ -79,4 +80,5 @@ public class SWItem {
|
|||
|
||||
public void generateDialog(View view, LinearLayout layout) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,5 +67,6 @@ public class SWPlugin extends SWItem {
|
|||
MainApp.bus().post(new EventSWUpdate());
|
||||
});
|
||||
layout.addView(radioGroup);
|
||||
super.generateDialog(view, layout);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,5 +62,6 @@ public class SWRadioButton extends SWItem {
|
|||
save(values()[i]);
|
||||
});
|
||||
layout.addView(radioGroup);
|
||||
super.generateDialog(view, layout);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ public class SWString extends SWItem {
|
|||
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
editText.setMaxLines(1);
|
||||
layout.addView(editText);
|
||||
super.generateDialog(view, layout);
|
||||
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
|
|
|
@ -38,6 +38,7 @@ public class SWUrl extends SWItem {
|
|||
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
editText.setMaxLines(1);
|
||||
layout.addView(editText);
|
||||
super.generateDialog(view, layout);
|
||||
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
|
|
|
@ -48,12 +48,7 @@ public class SetupWizardActivity extends AppCompatActivity {
|
|||
screenName.setText(currentScreen.getHeader());
|
||||
|
||||
//Generate layout first
|
||||
LinearLayout layout = SWItem.generateLayout(this.findViewById(R.id.sw_content_fields));
|
||||
for (int i = 0; i < currentScreen.items.size(); i++) {
|
||||
SWItem currentItem = currentScreen.items.get(i);
|
||||
currentItem.generateDialog(this.findViewById(R.id.sw_content_fields), layout);
|
||||
}
|
||||
|
||||
generateLayout();
|
||||
updateButtons();
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +67,8 @@ public class SetupWizardActivity extends AppCompatActivity {
|
|||
|
||||
@Subscribe
|
||||
public void onContentUpdate(EventSWUpdate ev) {
|
||||
if (ev.redraw)
|
||||
generateLayout();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
|
@ -80,6 +77,15 @@ public class SetupWizardActivity extends AppCompatActivity {
|
|||
updateButtons();
|
||||
}
|
||||
|
||||
private void generateLayout() {
|
||||
SWScreen currentScreen = screens.get(currentWizardPage);
|
||||
LinearLayout layout = SWItem.generateLayout(this.findViewById(R.id.sw_content_fields));
|
||||
for (int i = 0; i < currentScreen.items.size(); i++) {
|
||||
SWItem currentItem = currentScreen.items.get(i);
|
||||
currentItem.generateDialog(this.findViewById(R.id.sw_content_fields), layout);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
SWScreen currentScreen = screens.get(currentWizardPage);
|
||||
if (currentScreen.validator.isValid() || currentScreen.skippable) {
|
||||
|
|
|
@ -3,4 +3,12 @@ package info.nightscout.androidaps.startupwizard.events;
|
|||
import info.nightscout.androidaps.events.Event;
|
||||
|
||||
public class EventSWUpdate extends Event {
|
||||
public boolean redraw = false;
|
||||
|
||||
public EventSWUpdate() {
|
||||
}
|
||||
|
||||
public EventSWUpdate(boolean redraw) {
|
||||
this.redraw = redraw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1057,5 +1057,6 @@
|
|||
<string name="wear_general_settings">General Settings</string>
|
||||
|
||||
<string name="dummy_content">DUMMY\nCONTENT</string>
|
||||
<string name="enable_nsclient">Enable NSClient</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue