nsclient gui and pausing tweaking

This commit is contained in:
Milos Kozak 2017-02-17 18:14:33 +01:00
parent 31364ff07b
commit 14e37246c2
8 changed files with 75 additions and 46 deletions

View file

@ -11,6 +11,10 @@ public class EventPreferenceChange {
changedKey = key; changedKey = key;
} }
public EventPreferenceChange(int resourceID) {
changedKey = MainApp.sResources.getString(resourceID);
}
public boolean isChanged(int id) { public boolean isChanged(int id) {
return changedKey.equals(MainApp.sResources.getString(id)); return changedKey.equals(MainApp.sResources.getString(id));
} }

View file

@ -5,6 +5,8 @@ import android.app.Activity;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -20,6 +22,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
@ -60,8 +63,10 @@ public class NSClientInternalFragment extends Fragment implements FragmentBase,
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview); logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll); autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
autoscrollCheckbox.setChecked(getPlugin().autoscroll);
autoscrollCheckbox.setOnCheckedChangeListener(this); autoscrollCheckbox.setOnCheckedChangeListener(this);
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused); pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
pausedCheckbox.setChecked(getPlugin().paused);
pausedCheckbox.setOnCheckedChangeListener(this); pausedCheckbox.setOnCheckedChangeListener(this);
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log); logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue); queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
@ -113,13 +118,14 @@ public class NSClientInternalFragment extends Fragment implements FragmentBase,
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch (buttonView.getId()) { switch (buttonView.getId()) {
case R.id.nsclientinternal_paused: case R.id.nsclientinternal_paused:
SP.putBoolean("nsclientinternal_paused", isChecked); SP.putBoolean(R.string.key_nsclientinternal_paused, isChecked);
getPlugin().paused = isChecked; getPlugin().paused = isChecked;
// TODO MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
updateGUI(); updateGUI();
break; break;
case R.id.nsclientinternal_autoscroll: case R.id.nsclientinternal_autoscroll:
SP.putBoolean("nsclientinternal_autoscroll", isChecked); SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
getPlugin().autoscroll = isChecked;
updateGUI(); updateGUI();
break; break;
} }
@ -153,8 +159,9 @@ public class NSClientInternalFragment extends Fragment implements FragmentBase,
if (getPlugin().autoscroll) { if (getPlugin().autoscroll) {
logScrollview.fullScroll(ScrollView.FOCUS_DOWN); logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
} }
urlTextView.setText(getPlugin().url); urlTextView.setText(getPlugin().url());
queueTextView.setText(((Integer)getPlugin().queue().size()).toString()); Spanned queuetext = Html.fromHtml(MainApp.sResources.getString(R.string.queue) + " <b>" + getPlugin().queue().size() + "</b>");
queueTextView.setText(queuetext);
statusTextView.setText(getPlugin().status); statusTextView.setText(getPlugin().status);
} }
}); });

View file

@ -52,7 +52,6 @@ public class NSClientInternalPlugin implements PluginBase {
public boolean paused = false; public boolean paused = false;
public boolean autoscroll = true; public boolean autoscroll = true;
public String url = "";
public String status = ""; public String status = "";
@ -60,9 +59,8 @@ public class NSClientInternalPlugin implements PluginBase {
public NSClientInternalPlugin() { public NSClientInternalPlugin() {
MainApp.bus().register(this); MainApp.bus().register(this);
paused = SP.getBoolean("nsclientinternal_paused", false); paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false);
autoscroll = SP.getBoolean("nsclientinternal_autoscroll", true); autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true);
url = SP.getString("nsclientinternal_url", "");
if (handler == null) { if (handler == null) {
handlerThread = new HandlerThread(NSClientInternalPlugin.class.getSimpleName() + "Handler"); handlerThread = new HandlerThread(NSClientInternalPlugin.class.getSimpleName() + "Handler");
@ -212,4 +210,8 @@ public class NSClientInternalPlugin implements PluginBase {
public UploadQueue queue() { public UploadQueue queue() {
return NSClientService.uploadQueue; return NSClientService.uploadQueue;
} }
public String url() {
return NSClientService.nsURL;
}
} }

View file

@ -5,6 +5,8 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
import io.socket.client.Ack; import io.socket.client.Ack;
@ -38,7 +40,7 @@ public class NSAddAck implements Ack {
synchronized(this) { synchronized(this) {
this.notify(); this.notify();
} }
NSClientService.forcerestart = true; MainApp.bus().post(new EventNSClientRestart());
return; return;
} }
log.debug("DBACCESS " + response.getString("result")); log.debug("DBACCESS " + response.getString("result"));

View file

@ -66,7 +66,6 @@ public class NSClientService extends Service {
private static Logger log = LoggerFactory.getLogger(ExecutionService.class); private static Logger log = LoggerFactory.getLogger(ExecutionService.class);
static public PowerManager.WakeLock mWakeLock; static public PowerManager.WakeLock mWakeLock;
public static boolean forcerestart = false;
private IBinder mBinder = new NSClientService.LocalBinder(); private IBinder mBinder = new NSClientService.LocalBinder();
static NSProfile nsProfile; static NSProfile nsProfile;
@ -83,7 +82,7 @@ public class NSClientService extends Service {
public static Integer nightscoutVersionCode = 0; public static Integer nightscoutVersionCode = 0;
private boolean nsEnabled = false; private boolean nsEnabled = false;
private String nsURL = ""; static public String nsURL = "";
private String nsAPISecret = ""; private String nsAPISecret = "";
private String nsDevice = ""; private String nsDevice = "";
private Integer nsHours = 3; private Integer nsHours = 3;
@ -151,7 +150,8 @@ public class NSClientService extends Service {
public void onStatusEvent(EventPreferenceChange ev) { public void onStatusEvent(EventPreferenceChange ev) {
if (ev.isChanged(R.string.key_nsclientinternal_url) || if (ev.isChanged(R.string.key_nsclientinternal_url) ||
ev.isChanged(R.string.key_nsclientinternal_api_secret) || ev.isChanged(R.string.key_nsclientinternal_api_secret) ||
ev.isChanged(R.string.key_nsclientinternal_hours) ev.isChanged(R.string.key_nsclientinternal_hours) ||
ev.isChanged(R.string.key_nsclientinternal_paused)
) { ) {
destroy(); destroy();
initialize(); initialize();
@ -185,7 +185,10 @@ public class NSClientService extends Service {
nsAPIhashCode = Hashing.sha1().hashString(nsAPISecret, Charsets.UTF_8).toString(); nsAPIhashCode = Hashing.sha1().hashString(nsAPISecret, Charsets.UTF_8).toString();
MainApp.bus().post(new EventNSClientStatus("Initializing")); MainApp.bus().post(new EventNSClientStatus("Initializing"));
if (!nsEnabled) { if (((NSClientInternalPlugin)MainApp.getSpecificPlugin(NSClientInternalPlugin.class)).paused) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "paused"));
MainApp.bus().post(new EventNSClientStatus("Paused"));
} else if (!nsEnabled) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disabled")); MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disabled"));
MainApp.bus().post(new EventNSClientStatus("Disabled")); MainApp.bus().post(new EventNSClientStatus("Disabled"));
} else if (!nsURL.equals("")) { } else if (!nsURL.equals("")) {

View file

@ -69,4 +69,10 @@ public class SP {
editor.putBoolean(key, value); editor.putBoolean(key, value);
editor.apply(); editor.apply();
} }
static public void putBoolean(int resourceID, boolean value) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(MainApp.sResources.getString(resourceID), value);
editor.apply();
}
} }

View file

@ -13,35 +13,34 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="12dp" android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:orientation="horizontal"> android:orientation="horizontal"
android:gravity="center_horizontal">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/nsclientinternal_url" android:text="@string/nsclientinternal_url" />
android:textSize="16dp" />
<TextView <TextView
android:id="@+id/nsclientinternal_url" android:id="@+id/nsclientinternal_url"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="3" android:layout_marginLeft="5dp"
android:autoLink="web" android:autoLink="web" />
android:gravity="center_vertical|end"
android:textSize="16dp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="12dp" android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:orientation="horizontal"> android:orientation="horizontal"
android:gravity="center_horizontal">
<CheckBox <CheckBox
android:id="@+id/nsclientinternal_paused" android:id="@+id/nsclientinternal_paused"
@ -57,18 +56,6 @@
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:text="@string/nsclientinternal_autoscroll" /> android:text="@string/nsclientinternal_autoscroll" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="@string/queue" />
<TextView
android:id="@+id/nsclientinternal_queue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -87,7 +74,17 @@
<TextView <TextView
android:id="@+id/nsclientinternal_status" android:id="@+id/nsclientinternal_status"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:textStyle="normal|bold" />
<TextView
android:id="@+id/nsclientinternal_queue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="@string/queue"
android:textAlignment="viewEnd" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -95,7 +92,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:orientation="horizontal"> android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp">
<TextView <TextView
android:id="@+id/nsclientinternal_clearlog" android:id="@+id/nsclientinternal_clearlog"
@ -104,7 +103,8 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/clearlog" android:text="@string/clearlog"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" /> android:textColor="@android:color/holo_orange_light"
android:textStyle="normal|bold" />
<TextView <TextView
android:id="@+id/nsclientinternal_restart" android:id="@+id/nsclientinternal_restart"
@ -113,7 +113,8 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/restart" android:text="@string/restart"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" /> android:textColor="@android:color/holo_orange_light"
android:textStyle="normal|bold" />
<TextView <TextView
android:id="@+id/nsclientinternal_delivernow" android:id="@+id/nsclientinternal_delivernow"
@ -122,7 +123,8 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/deliver_now" android:text="@string/deliver_now"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" /> android:textColor="@android:color/holo_orange_light"
android:textStyle="normal|bold" />
<TextView <TextView
android:id="@+id/nsclientinternal_clearqueue" android:id="@+id/nsclientinternal_clearqueue"
@ -131,7 +133,8 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/clear_queue" android:text="@string/clear_queue"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" /> android:textColor="@android:color/holo_orange_light"
android:textStyle="normal|bold" />
<TextView <TextView
android:id="@+id/nsclientinternal_showqueue" android:id="@+id/nsclientinternal_showqueue"
@ -140,7 +143,8 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/show_queue" android:text="@string/show_queue"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" /> android:textColor="@android:color/holo_orange_light"
android:textStyle="normal|bold" />
</LinearLayout> </LinearLayout>
@ -149,8 +153,7 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp">
android:layout_marginTop="10dp">
<TextView <TextView
android:id="@+id/nsclientinternal_log" android:id="@+id/nsclientinternal_log"

View file

@ -537,4 +537,6 @@
<string name="key_danar_useextended" translatable="false">danar_useextended</string> <string name="key_danar_useextended" translatable="false">danar_useextended</string>
<string name="key_danarprofile_dia" translatable="false">danarprofile_dia</string> <string name="key_danarprofile_dia" translatable="false">danarprofile_dia</string>
<string name="clearlog">Clear log</string> <string name="clearlog">Clear log</string>
<string name="key_nsclientinternal_autoscroll">nsclientinternal_autoscroll</string>
<string name="key_nsclientinternal_paused">nsclientinternal_paused</string>
</resources> </resources>