ns uploader status
This commit is contained in:
parent
87fb969d9f
commit
dbd721319e
5 changed files with 135 additions and 2 deletions
|
@ -6,7 +6,9 @@ import android.text.Spanned;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -86,13 +88,18 @@ public class NSDeviceStatus {
|
||||||
this.data = obj;
|
this.data = obj;
|
||||||
updatePumpData(obj);
|
updatePumpData(obj);
|
||||||
updateOpenApsData(obj);
|
updateOpenApsData(obj);
|
||||||
|
updateUploaderData(obj);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDevice() {
|
public String getDevice() {
|
||||||
try {
|
try {
|
||||||
if (data.has("device")) {
|
if (data.has("device")) {
|
||||||
return data.getString("device");
|
String device = data.getString("device");
|
||||||
|
if (device.startsWith("openaps://")) {
|
||||||
|
device = device.substring(10);
|
||||||
|
return device;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -313,4 +320,68 @@ public class NSDeviceStatus {
|
||||||
return Html.fromHtml("");
|
return Html.fromHtml("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ********* Uploader data ***********
|
||||||
|
|
||||||
|
public static HashMap<String, Uploader> uploaders = new HashMap<>();
|
||||||
|
|
||||||
|
static class Uploader {
|
||||||
|
long clock = 0L;
|
||||||
|
int battery = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateUploaderData(JSONObject object) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
long clock = 0L;
|
||||||
|
if (object.has("created_at"))
|
||||||
|
clock = DateUtil.fromISODateString(object.getString("created_at")).getTime();
|
||||||
|
String device = getDevice();
|
||||||
|
Integer battery = null;
|
||||||
|
if (object.has("uploaderBattery"))
|
||||||
|
battery = object.getInt("uploaderBattery");
|
||||||
|
else if (object.has("uploader")) {
|
||||||
|
if (object.getJSONObject("uploader").has("battery"))
|
||||||
|
battery = object.getJSONObject("uploader").getInt("battery");
|
||||||
|
}
|
||||||
|
Uploader uploader = uploaders.get(device);
|
||||||
|
// check if this is new data
|
||||||
|
if (clock != 0 && (uploader != null && clock > uploader.clock || uploader == null)) {
|
||||||
|
if (uploader == null)
|
||||||
|
uploader = new Uploader();
|
||||||
|
uploader.battery = battery;
|
||||||
|
uploader.clock = clock;
|
||||||
|
uploaders.put(device, uploader);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUploaderStatus() {
|
||||||
|
Iterator iter = uploaders.entrySet().iterator();
|
||||||
|
int minBattery = 100;
|
||||||
|
while(iter.hasNext()) {
|
||||||
|
Map.Entry pair = (Map.Entry) iter.next();
|
||||||
|
Uploader uploader = (Uploader) pair.getValue();
|
||||||
|
if (minBattery > uploader.battery)
|
||||||
|
minBattery = uploader.battery;
|
||||||
|
}
|
||||||
|
|
||||||
|
return minBattery + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Spanned getExtendedUploaderStatus() {
|
||||||
|
StringBuilder string = new StringBuilder();
|
||||||
|
|
||||||
|
Iterator iter = uploaders.entrySet().iterator();
|
||||||
|
while(iter.hasNext()) {
|
||||||
|
Map.Entry pair = (Map.Entry) iter.next();
|
||||||
|
Uploader uploader = (Uploader) pair.getValue();
|
||||||
|
String device = (String) pair.getKey();
|
||||||
|
string.append("<b>").append(device).append(":</b> ").append(uploader.battery).append("%<br>");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Html.fromHtml(string.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
TextView pumpStatusView;
|
TextView pumpStatusView;
|
||||||
TextView pumpDeviceStatusView;
|
TextView pumpDeviceStatusView;
|
||||||
TextView openapsDeviceStatusView;
|
TextView openapsDeviceStatusView;
|
||||||
|
TextView uploaderDeviceStatusView;
|
||||||
LinearLayout loopStatusLayout;
|
LinearLayout loopStatusLayout;
|
||||||
LinearLayout pumpStatusLayout;
|
LinearLayout pumpStatusLayout;
|
||||||
GraphView bgGraph;
|
GraphView bgGraph;
|
||||||
|
@ -242,6 +243,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
|
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
|
||||||
pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump);
|
pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump);
|
||||||
openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps);
|
openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps);
|
||||||
|
uploaderDeviceStatusView = (TextView) view.findViewById(R.id.overview_uploader);
|
||||||
loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
|
loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
|
||||||
pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
|
pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
|
||||||
|
|
||||||
|
@ -1184,6 +1186,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uploader status from ns
|
||||||
|
if (uploaderDeviceStatusView != null) {
|
||||||
|
uploaderDeviceStatusView.setText(NSDeviceStatus.getInstance().getUploaderStatus());
|
||||||
|
uploaderDeviceStatusView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.uploader), NSDeviceStatus.getInstance().getExtendedUploaderStatus(), null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ****** GRAPH *******
|
// ****** GRAPH *******
|
||||||
//log.debug("updateGUI checkpoint 1");
|
//log.debug("updateGUI checkpoint 1");
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshDataFromPump(String reason) {
|
public void refreshDataFromPump(String reason) {
|
||||||
|
if (!BuildConfig.NSCLIENTOLNY)
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
lastDataTime = new Date();
|
lastDataTime = new Date();
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,6 +501,53 @@
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:background="@color/listdelimiter" />
|
android:background="@color/listdelimiter" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="end"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/uploader"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="5dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingEnd="2dp"
|
||||||
|
android:paddingStart="2dp"
|
||||||
|
android:text=":"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/overview_uploader"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.5"
|
||||||
|
android:gravity="start"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:text=""
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="2dip"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:background="@color/listdelimiter" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -649,4 +649,5 @@
|
||||||
<string name="pump">Pump</string>
|
<string name="pump">Pump</string>
|
||||||
<string name="openaps">OpenAPS</string>
|
<string name="openaps">OpenAPS</string>
|
||||||
<string name="device">Device</string>
|
<string name="device">Device</string>
|
||||||
|
<string name="uploader">Uploader</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue