nsclient gui and pausing tweaking
This commit is contained in:
parent
31364ff07b
commit
14e37246c2
8 changed files with 75 additions and 46 deletions
|
@ -11,6 +11,10 @@ public class EventPreferenceChange {
|
|||
changedKey = key;
|
||||
}
|
||||
|
||||
public EventPreferenceChange(int resourceID) {
|
||||
changedKey = MainApp.sResources.getString(resourceID);
|
||||
}
|
||||
|
||||
public boolean isChanged(int id) {
|
||||
return changedKey.equals(MainApp.sResources.getString(id));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.app.Activity;
|
|||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -20,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
||||
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);
|
||||
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
|
||||
autoscrollCheckbox.setChecked(getPlugin().autoscroll);
|
||||
autoscrollCheckbox.setOnCheckedChangeListener(this);
|
||||
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
|
||||
pausedCheckbox.setChecked(getPlugin().paused);
|
||||
pausedCheckbox.setOnCheckedChangeListener(this);
|
||||
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
|
||||
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) {
|
||||
switch (buttonView.getId()) {
|
||||
case R.id.nsclientinternal_paused:
|
||||
SP.putBoolean("nsclientinternal_paused", isChecked);
|
||||
SP.putBoolean(R.string.key_nsclientinternal_paused, isChecked);
|
||||
getPlugin().paused = isChecked;
|
||||
// TODO
|
||||
MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||
updateGUI();
|
||||
break;
|
||||
case R.id.nsclientinternal_autoscroll:
|
||||
SP.putBoolean("nsclientinternal_autoscroll", isChecked);
|
||||
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
|
||||
getPlugin().autoscroll = isChecked;
|
||||
updateGUI();
|
||||
break;
|
||||
}
|
||||
|
@ -153,8 +159,9 @@ public class NSClientInternalFragment extends Fragment implements FragmentBase,
|
|||
if (getPlugin().autoscroll) {
|
||||
logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
}
|
||||
urlTextView.setText(getPlugin().url);
|
||||
queueTextView.setText(((Integer)getPlugin().queue().size()).toString());
|
||||
urlTextView.setText(getPlugin().url());
|
||||
Spanned queuetext = Html.fromHtml(MainApp.sResources.getString(R.string.queue) + " <b>" + getPlugin().queue().size() + "</b>");
|
||||
queueTextView.setText(queuetext);
|
||||
statusTextView.setText(getPlugin().status);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -52,7 +52,6 @@ public class NSClientInternalPlugin implements PluginBase {
|
|||
|
||||
public boolean paused = false;
|
||||
public boolean autoscroll = true;
|
||||
public String url = "";
|
||||
|
||||
public String status = "";
|
||||
|
||||
|
@ -60,9 +59,8 @@ public class NSClientInternalPlugin implements PluginBase {
|
|||
|
||||
public NSClientInternalPlugin() {
|
||||
MainApp.bus().register(this);
|
||||
paused = SP.getBoolean("nsclientinternal_paused", false);
|
||||
autoscroll = SP.getBoolean("nsclientinternal_autoscroll", true);
|
||||
url = SP.getString("nsclientinternal_url", "");
|
||||
paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false);
|
||||
autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true);
|
||||
|
||||
if (handler == null) {
|
||||
handlerThread = new HandlerThread(NSClientInternalPlugin.class.getSimpleName() + "Handler");
|
||||
|
@ -212,4 +210,8 @@ public class NSClientInternalPlugin implements PluginBase {
|
|||
public UploadQueue queue() {
|
||||
return NSClientService.uploadQueue;
|
||||
}
|
||||
|
||||
public String url() {
|
||||
return NSClientService.nsURL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
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 io.socket.client.Ack;
|
||||
|
||||
|
@ -38,7 +40,7 @@ public class NSAddAck implements Ack {
|
|||
synchronized(this) {
|
||||
this.notify();
|
||||
}
|
||||
NSClientService.forcerestart = true;
|
||||
MainApp.bus().post(new EventNSClientRestart());
|
||||
return;
|
||||
}
|
||||
log.debug("DBACCESS " + response.getString("result"));
|
||||
|
|
|
@ -66,7 +66,6 @@ public class NSClientService extends Service {
|
|||
private static Logger log = LoggerFactory.getLogger(ExecutionService.class);
|
||||
|
||||
static public PowerManager.WakeLock mWakeLock;
|
||||
public static boolean forcerestart = false;
|
||||
private IBinder mBinder = new NSClientService.LocalBinder();
|
||||
|
||||
static NSProfile nsProfile;
|
||||
|
@ -83,7 +82,7 @@ public class NSClientService extends Service {
|
|||
public static Integer nightscoutVersionCode = 0;
|
||||
|
||||
private boolean nsEnabled = false;
|
||||
private String nsURL = "";
|
||||
static public String nsURL = "";
|
||||
private String nsAPISecret = "";
|
||||
private String nsDevice = "";
|
||||
private Integer nsHours = 3;
|
||||
|
@ -151,7 +150,8 @@ public class NSClientService extends Service {
|
|||
public void onStatusEvent(EventPreferenceChange ev) {
|
||||
if (ev.isChanged(R.string.key_nsclientinternal_url) ||
|
||||
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();
|
||||
initialize();
|
||||
|
@ -185,7 +185,10 @@ public class NSClientService extends Service {
|
|||
nsAPIhashCode = Hashing.sha1().hashString(nsAPISecret, Charsets.UTF_8).toString();
|
||||
|
||||
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 EventNSClientStatus("Disabled"));
|
||||
} else if (!nsURL.equals("")) {
|
||||
|
|
|
@ -69,4 +69,10 @@ public class SP {
|
|||
editor.putBoolean(key, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
static public void putBoolean(int resourceID, boolean value) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean(MainApp.sResources.getString(resourceID), value);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,35 +13,34 @@
|
|||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/nsclientinternal_url"
|
||||
android:textSize="16dp" />
|
||||
android:text="@string/nsclientinternal_url" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nsclientinternal_url"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:autoLink="web"
|
||||
android:gravity="center_vertical|end"
|
||||
android:textSize="16dp" />
|
||||
android:layout_marginLeft="5dp"
|
||||
android:autoLink="web" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/nsclientinternal_paused"
|
||||
|
@ -57,18 +56,6 @@
|
|||
android:layout_marginRight="10dp"
|
||||
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
|
||||
|
@ -87,7 +74,17 @@
|
|||
<TextView
|
||||
android:id="@+id/nsclientinternal_status"
|
||||
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
|
||||
|
@ -95,7 +92,9 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nsclientinternal_clearlog"
|
||||
|
@ -104,7 +103,8 @@
|
|||
android:layout_weight="1"
|
||||
android:text="@string/clearlog"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_orange_light" />
|
||||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nsclientinternal_restart"
|
||||
|
@ -113,7 +113,8 @@
|
|||
android:layout_weight="1"
|
||||
android:text="@string/restart"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_orange_light" />
|
||||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nsclientinternal_delivernow"
|
||||
|
@ -122,7 +123,8 @@
|
|||
android:layout_weight="1"
|
||||
android:text="@string/deliver_now"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_orange_light" />
|
||||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nsclientinternal_clearqueue"
|
||||
|
@ -131,7 +133,8 @@
|
|||
android:layout_weight="1"
|
||||
android:text="@string/clear_queue"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_orange_light" />
|
||||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nsclientinternal_showqueue"
|
||||
|
@ -140,7 +143,8 @@
|
|||
android:layout_weight="1"
|
||||
android:text="@string/show_queue"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_orange_light" />
|
||||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -149,8 +153,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginTop="10dp">
|
||||
android:layout_marginRight="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nsclientinternal_log"
|
||||
|
|
|
@ -537,4 +537,6 @@
|
|||
<string name="key_danar_useextended" translatable="false">danar_useextended</string>
|
||||
<string name="key_danarprofile_dia" translatable="false">danarprofile_dia</string>
|
||||
<string name="clearlog">Clear log</string>
|
||||
<string name="key_nsclientinternal_autoscroll">nsclientinternal_autoscroll</string>
|
||||
<string name="key_nsclientinternal_paused">nsclientinternal_paused</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue