SW nsclient screen finalizing
This commit is contained in:
parent
52a4f9af14
commit
f24d296836
8 changed files with 91 additions and 18 deletions
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragme
|
|||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
||||
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
||||
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment;
|
||||
|
@ -100,14 +101,9 @@ public class SWDefinition {
|
|||
)
|
||||
.add(new SWScreen(R.string.nsclientinternal_title)
|
||||
.skippable(true)
|
||||
.add(new SWEditUrl()
|
||||
.preferenceId(R.string.key_nsclientinternal_url)
|
||||
.label(R.string.nsclientinternal_url_title)
|
||||
.comment(R.string.nsclientinternal_url_dialogmessage))
|
||||
.add(new SWEditString()
|
||||
.preferenceId(R.string.key_nsclientinternal_api_secret)
|
||||
.label(R.string.nsclientinternal_secret_dialogtitle)
|
||||
.comment(R.string.nsclientinternal_secret_dialogmessage))
|
||||
.add(new SWInfotext()
|
||||
.label(R.string.nsclientinfotext))
|
||||
.add(new SWBreak())
|
||||
.add(new SWButton()
|
||||
.text(R.string.enable_nsclient)
|
||||
.action(() -> {
|
||||
|
@ -119,7 +115,29 @@ public class SWDefinition {
|
|||
MainApp.bus().post(new EventSWUpdate(true));
|
||||
})
|
||||
.visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL)))
|
||||
.add(new SWEditUrl()
|
||||
.preferenceId(R.string.key_nsclientinternal_url)
|
||||
.label(R.string.nsclientinternal_url_title)
|
||||
.comment(R.string.nsclientinternal_url_dialogmessage))
|
||||
.add(new SWEditString()
|
||||
.validator(text -> text.length() >= 12)
|
||||
.preferenceId(R.string.key_nsclientinternal_api_secret)
|
||||
.label(R.string.nsclientinternal_secret_dialogtitle)
|
||||
.comment(R.string.nsclientinternal_secret_dialogmessage))
|
||||
.add(new SWBreak())
|
||||
.add(new SWEventListener(this)
|
||||
.label(R.string.status)
|
||||
.initialStatus(NSClientPlugin.getPlugin().status)
|
||||
.listener(new Object() {
|
||||
@Subscribe
|
||||
public void onEventNSClientStatus(EventNSClientStatus event) {
|
||||
MainApp.bus().post(new EventSWLabel(event.status));
|
||||
}
|
||||
})
|
||||
)
|
||||
.add(new SWBreak())
|
||||
.validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth)
|
||||
.visibility(() -> !(NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth))
|
||||
)
|
||||
.add(new SWScreen(R.string.patientage)
|
||||
.skippable(false)
|
||||
|
|
|
@ -18,6 +18,8 @@ import info.nightscout.androidaps.startupwizard.events.EventSWLabel;
|
|||
public class SWEventListener extends SWItem {
|
||||
private static Logger log = LoggerFactory.getLogger(SWEventListener.class);
|
||||
|
||||
private int textLabel = 0;
|
||||
private String status = "";
|
||||
TextView textView;
|
||||
Object listener;
|
||||
SWDefinition definition;
|
||||
|
@ -28,6 +30,16 @@ public class SWEventListener extends SWItem {
|
|||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
public SWEventListener label(int newLabel) {
|
||||
this.textLabel = newLabel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWEventListener initialStatus(String status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWEventListener listener(Object listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
|
@ -39,17 +51,21 @@ public class SWEventListener extends SWItem {
|
|||
|
||||
textView = new TextView(context);
|
||||
textView.setId(view.generateViewId());
|
||||
textView.setText((textLabel != 0 ? MainApp.gs(textLabel) : "") + " " + status);
|
||||
layout.addView(textView);
|
||||
if (listener != null)
|
||||
try {
|
||||
MainApp.bus().register(listener);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEventSWLabel(final EventSWLabel l) {
|
||||
status = l.label;
|
||||
if (definition != null && definition.getActivity() != null)
|
||||
definition.getActivity().runOnUiThread(() -> {
|
||||
if (textView != null)
|
||||
textView.setText(l.label);
|
||||
textView.setText((textLabel != 0 ? MainApp.gs(textLabel) : "") + " " + status);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
public interface SWTextValidator {
|
||||
boolean isValid(String text);
|
||||
}
|
|
@ -13,10 +13,15 @@ import android.widget.TextView;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.startupwizard.SWTextValidator;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
||||
public class SWEditString extends SWItem {
|
||||
private static Logger log = LoggerFactory.getLogger(SWEditString.class);
|
||||
|
||||
private SWTextValidator validator = null;
|
||||
|
||||
public SWEditString() {
|
||||
super(Type.STRING);
|
||||
}
|
||||
|
@ -41,6 +46,7 @@ public class SWEditString extends SWItem {
|
|||
editText.setId(view.generateViewId());
|
||||
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
editText.setMaxLines(1);
|
||||
editText.setText(SP.getString(preferenceId, ""));
|
||||
layout.addView(editText);
|
||||
super.generateDialog(view, layout);
|
||||
|
||||
|
@ -51,6 +57,7 @@ public class SWEditString extends SWItem {
|
|||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (validator != null && validator.isValid(s.toString()))
|
||||
save(s.toString());
|
||||
}
|
||||
|
||||
|
@ -60,4 +67,13 @@ public class SWEditString extends SWItem {
|
|||
});
|
||||
}
|
||||
|
||||
public SWEditString preferenceId(int preferenceId) {
|
||||
this.preferenceId = preferenceId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWEditString validator(SWTextValidator validator) {
|
||||
this.validator = validator;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.graphics.Typeface;
|
|||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -13,6 +14,11 @@ import android.widget.TextView;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.startupwizard.events.EventSWLabel;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class SWEditUrl extends SWItem {
|
||||
private static Logger log = LoggerFactory.getLogger(SWEditUrl.class);
|
||||
|
||||
|
@ -40,6 +46,7 @@ public class SWEditUrl extends SWItem {
|
|||
editText.setId(View.generateViewId());
|
||||
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
editText.setMaxLines(1);
|
||||
editText.setText(SP.getString(preferenceId, ""));
|
||||
layout.addView(editText);
|
||||
super.generateDialog(view, layout);
|
||||
|
||||
|
@ -50,7 +57,10 @@ public class SWEditUrl extends SWItem {
|
|||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (Patterns.WEB_URL.matcher(s).matches())
|
||||
save(s.toString());
|
||||
else
|
||||
MainApp.bus().post(new EventSWLabel(MainApp.gs(R.string.error_url_not_valid)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,4 +68,10 @@ public class SWEditUrl extends SWItem {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public SWEditUrl preferenceId(int preferenceId) {
|
||||
this.preferenceId = preferenceId;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,11 +66,6 @@ public class SWItem {
|
|||
return this;
|
||||
}
|
||||
|
||||
public SWItem preferenceId(int preferenceId) {
|
||||
this.preferenceId = preferenceId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void save(String value) {
|
||||
SP.putString(preferenceId, value);
|
||||
MainApp.bus().post(new EventPreferenceChange(preferenceId));
|
||||
|
|
|
@ -64,4 +64,10 @@ public class SWRadioButton extends SWItem {
|
|||
layout.addView(radioGroup);
|
||||
super.generateDialog(view, layout);
|
||||
}
|
||||
|
||||
public SWRadioButton preferenceId(int preferenceId) {
|
||||
this.preferenceId = preferenceId;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1074,4 +1074,5 @@
|
|||
<string name="sensitivitysetup">Configure Sensitivity plugin</string>
|
||||
<string name="setupwizard_sensitivity_description">Sensitivity plugin is used for sensitivity detection and COB calculation. For more info visit:</string>
|
||||
<string name="setupwizard_sensitivity_url">https://github.com/MilosKozak/AndroidAPS/wiki/Sensitivity-detection-and-COB</string>
|
||||
<string name="nsclientinfotext">NSClient handles connection to Nightscout. You can skip this part now but you will not be able to pass objectives.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue