ns uploader status
This commit is contained in:
parent
87fb969d9f
commit
dbd721319e
|
@ -6,7 +6,9 @@ import android.text.Spanned;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
@ -86,13 +88,18 @@ public class NSDeviceStatus {
|
|||
this.data = obj;
|
||||
updatePumpData(obj);
|
||||
updateOpenApsData(obj);
|
||||
updateUploaderData(obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDevice() {
|
||||
try {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
|
@ -313,4 +320,68 @@ public class NSDeviceStatus {
|
|||
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 pumpDeviceStatusView;
|
||||
TextView openapsDeviceStatusView;
|
||||
TextView uploaderDeviceStatusView;
|
||||
LinearLayout loopStatusLayout;
|
||||
LinearLayout pumpStatusLayout;
|
||||
GraphView bgGraph;
|
||||
|
@ -242,6 +243,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
|
||||
pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump);
|
||||
openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps);
|
||||
uploaderDeviceStatusView = (TextView) view.findViewById(R.id.overview_uploader);
|
||||
loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
|
||||
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 *******
|
||||
//log.debug("updateGUI checkpoint 1");
|
||||
|
||||
|
|
|
@ -197,6 +197,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
if (!BuildConfig.NSCLIENTOLNY)
|
||||
NSUpload.uploadDeviceStatus();
|
||||
lastDataTime = new Date();
|
||||
}
|
||||
|
|
|
@ -501,6 +501,53 @@
|
|||
android:layout_marginTop="5dp"
|
||||
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>
|
||||
|
|
|
@ -649,4 +649,5 @@
|
|||
<string name="pump">Pump</string>
|
||||
<string name="openaps">OpenAPS</string>
|
||||
<string name="device">Device</string>
|
||||
<string name="uploader">Uploader</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue