Merge branch 'dev' into rs-sync-warn

This commit is contained in:
Milos Kozak 2018-06-24 11:45:33 +02:00 committed by GitHub
commit f7609317ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 257 additions and 88 deletions

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
@ -33,7 +34,7 @@ import info.nightscout.utils.T;
import info.nightscout.utils.Translator;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_CAREPORTALEVENTS)
public class CareportalEvent implements DataPointWithLabelInterface {
public class CareportalEvent implements DataPointWithLabelInterface, Interval {
private static Logger log = LoggerFactory.getLogger(CareportalEvent.class);
@DatabaseField(id = true)
@ -221,14 +222,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
@Override
public long getDuration() {
try {
JSONObject object = new JSONObject(json);
if (object.has("duration"))
return object.getInt("duration") * 60 * 1000L;
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
return end() - start();
}
@Override
@ -267,8 +261,79 @@ public class CareportalEvent implements DataPointWithLabelInterface {
if (eventType.equals(EXERCISE))
return Color.BLUE;
if (eventType.equals(OPENAPSOFFLINE))
return Color.GRAY;
return Color.GRAY & 0x80FFFFFF;
return Color.GRAY;
}
// Interval interface
Long cuttedEnd = null;
@Override
public long durationInMsec() {
try {
JSONObject object = new JSONObject(json);
if (object.has("duration"))
return object.getInt("duration") * 60 * 1000L;
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
}
@Override
public long start() {
return date;
}
@Override
public long originalEnd() {
return date + durationInMsec();
}
@Override
public long end() {
if (cuttedEnd != null)
return cuttedEnd;
return originalEnd();
}
@Override
public void cutEndTo(long end) {
cuttedEnd = end;
}
@Override
public boolean match(long time) {
if (start() <= time && end() >= time)
return true;
return false;
}
public boolean before(long time) {
if (end() < time)
return true;
return false;
}
public boolean after(long time) {
if (start() > time)
return true;
return false;
}
@Override
public boolean isInProgress() {
return match(System.currentTimeMillis());
}
@Override
public boolean isEndingEvent() {
return durationInMsec() == 0;
}
@Override
public boolean isValid() {
return eventType.equals(OPENAPSOFFLINE);
}
}

View file

@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.OverlappingIntervals;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventCareportalEventChange;
@ -1242,6 +1243,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
where.ge("date", mills);
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
preprocessOpenAPSOfflineEvents(careportalEvents);
return careportalEvents;
} catch (SQLException e) {
log.error("Unhandled exception", e);
@ -1249,6 +1251,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return new ArrayList<>();
}
public void preprocessOpenAPSOfflineEvents(List<CareportalEvent> list) {
OverlappingIntervals offlineEvents = new OverlappingIntervals();
for (int i = 0; i < list.size(); i++) {
CareportalEvent event = list.get(i);
if (!event.eventType.equals(CareportalEvent.OPENAPSOFFLINE)) continue;
offlineEvents.add(event);
}
}
public List<CareportalEvent> getCareportalEventsFromTime(long mills, String type, boolean ascending) {
try {
List<CareportalEvent> careportalEvents;
@ -1258,6 +1270,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
where.ge("date", mills).and().eq("eventType", type);
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
preprocessOpenAPSOfflineEvents(careportalEvents);
return careportalEvents;
} catch (SQLException e) {
log.error("Unhandled exception", e);
@ -1272,6 +1285,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
queryBuilder.orderBy("date", ascending);
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
preprocessOpenAPSOfflineEvents(careportalEvents);
return careportalEvents;
} catch (SQLException e) {
log.error("Unhandled exception", e);

View file

@ -1,5 +1,8 @@
package info.nightscout.androidaps.events;
import info.nightscout.utils.StringUtils;
public class EventNetworkChange extends Event {
public boolean mobileConnected = false;
@ -9,6 +12,6 @@ public class EventNetworkChange extends Event {
public boolean roaming = false;
public String getSsid() {
return ssid.replace("SSID: ","").replaceAll("\"","");
return StringUtils.removeSurroundingQuotes(ssid);
}
}

View file

@ -318,7 +318,7 @@ public class IobCobOref1Thread extends Thread {
// add an extra negative deviation if a high temptarget is running and exercise mode is set
if (SP.getBoolean(R.string.key_high_temptarget_raises_sensitivity, SMBDefaults.high_temptarget_raises_sensitivity)) {
TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(bgTime);
if (tempTarget != null && tempTarget.target() > 100) {
if (tempTarget != null && tempTarget.target() >= 100) {
autosensData.extraDeviation.add(-(tempTarget.target() - 100) / 20);
}
}

View file

@ -122,7 +122,8 @@ class NsClientReceiverDelegate {
boolean newAllowedState = true;
if (ev.wifiConnected) {
if (!allowedSSIDs.trim().isEmpty() && !allowedSSIDs.contains(ev.getSsid())) {
if (!allowedSSIDs.trim().isEmpty() &&
(!allowedSSIDs.contains(ev.getSsid()) && !allowedSSIDs.contains(ev.ssid))) {
newAllowedState = false;
}
} else {

View file

@ -312,20 +312,20 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStrokeWidth(5);
canvas.drawRect(px - 3, bounds.top + py - 3, xpluslength + 3, bounds.bottom + py + 3, mPaint);
}
} else if (value.getShape() == Shape.OPENAPSOFFLINE) {
} else if (value.getShape() == Shape.OPENAPSOFFLINE && value.getDuration() != 0) {
mPaint.setStrokeWidth(0);
if (value.getLabel() != null) {
mPaint.setStrokeWidth(0);
mPaint.setTextSize(scaledTextSize);
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
//mPaint.setStrokeWidth(0);
//mPaint.setTextSize(scaledTextSize);
//mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
mPaint.setStyle(Paint.Style.STROKE);
//mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
float px = endX;
float py = graphTop + 50;
canvas.drawText(value.getLabel(), px, py, mPaint);
//canvas.drawText(value.getLabel(), px, py, mPaint);
mPaint.setStrokeWidth(5);
canvas.drawRect(px - 3, bounds.top + py - 3, xpluslength + 3, bounds.bottom + py + 3, mPaint);
canvas.drawRect(px - 3, graphTop, xpluslength + 3, graphTop + graphHeight, mPaint);
}
} else if (value.getShape() == Shape.GENERALWITHDURATION) {
mPaint.setStrokeWidth(0);

View file

@ -107,16 +107,14 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(careportalEvent.date));
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
final String _id = careportalEvent._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(careportalEvent);
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
final String _id = careportalEvent._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(careportalEvent);
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
@ -142,6 +140,8 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
refreshFromNS = (Button) view.findViewById(R.id.careportal_refreshfromnightscout);
refreshFromNS.setOnClickListener(this);
view.findViewById(R.id.careportal_removeandroidapsstartedevents).setOnClickListener(this);
context = getContext();
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
@ -169,6 +169,16 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
case R.id.careportal_removeandroidapsstartedevents:
builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.careportal_removestartedevents));
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
removeAndroidAPSStatedEvents();
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
}
}
@ -189,4 +199,20 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
}
});
}
private void removeAndroidAPSStatedEvents() {
List<CareportalEvent> events = MainApp.getDbHelper().getCareportalEvents(false);
for (int i = 0; i < events.size(); i++) {
CareportalEvent careportalEvent = events.get(i);
if (careportalEvent.json.contains(MainApp.gs(R.string.androidaps_start))) {
final String _id = careportalEvent._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(careportalEvent);
}
}
}
}

View file

@ -0,0 +1,20 @@
package info.nightscout.utils;
/**
* class contains useful String functions
*/
public class StringUtils {
private StringUtils() {
// this constructor is private, since this class should not get instantiated
}
public static String removeSurroundingQuotes(String string) {
if (string.length() >= 2 && string.charAt(0) == '"'
&& string.charAt(string.length() - 1) == '"') {
string = string.substring(1, string.length() - 1);
}
return string;
}
}

View file

@ -62,9 +62,9 @@
android:layout_gravity="right"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="TempTarget"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text="TempTarget"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/mdtp_white" />
@ -83,9 +83,9 @@
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|center_horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:gravity="center_vertical|center_horizontal"
android:text="@string/initializing"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
@ -100,71 +100,61 @@
android:id="@+id/overview_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:text="00.0"
android:textSize="70dp"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/overview_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_gravity="center_vertical"
android:layout_marginTop="-15dp"
android:gravity="center_vertical"
android:paddingLeft="-5dp"
android:paddingRight="-5dp"
android:text="→"
android:textSize="70dp"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
<TextView
android:id="@+id/overview_deltashort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="top"
android:orientation="vertical">
android:layout_gravity="center_vertical"
android:text="-0.5"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/overview_timeago"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0.5"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/overview_delta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0.5"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
<TextView
android:id="@+id/overview_sensitivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:gravity="center_vertical|center_horizontal"
android:text="100%"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/overview_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:layout_marginTop="10dp"
android:maxWidth="150dp"
android:paddingLeft="10dp"
android:text="8:00 PM"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/overview_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="8:00 PM"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/overview_timeagoshort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="(-5)"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
@ -513,8 +503,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:paddingRight="5dp">
<info.nightscout.utils.SingleClickButton
android:id="@+id/overview_treatmentbutton"

View file

@ -9,13 +9,30 @@
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/careportal_refreshfromnightscout"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/refresheventsfromnightscout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/careportal_refreshfromnightscout"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/refresheventsfromnightscout" />
<Button
android:id="@+id/careportal_removeandroidapsstartedevents"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/careportal_removestartedevents" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/careportal_recyclerview"

View file

@ -1167,13 +1167,16 @@
<string name="description_source_poctech">Receive BG values from Poctech app</string>
<string translatable="false" name="key_high_temptarget_raises_sensitivity">high_temptarget_raises_sensitivity</string>
<string translatable="false" name="key_low_temptarget_lowers_sensitivity">low_temptarget_lowers_sensitivity</string>
<string name="high_temptarget_raises_sensitivity_title">High temptarget raises sensitivity</string>
<string name="high_temptarget_raises_sensitivity_summary"><![CDATA[Raise sensitivity for temptargets >= 100]]></string>
<string name="low_temptarget_lowers_sensitivity_title">Low temptarget lowers sensitivity</string>
<string name="low_temptarget_lowers_sensitivity_summary"><![CDATA[Lower sensitivity for temptargets < 100]]></string>
<string name="combo_invalid_setup">Invalid pump setup, check the docs and verify that the Quick Info menu is named "QUICK INFO" using the 360 configuration software.</string>
<string name="custom">Custom</string>
<string name="key_lockscreen" translatable="false">lockscreen</string>
<string name="largetimedifftitle">Large Time Difference</string>
<string name="largetimediff">Large time difference: Time in pump was adjuted for more than 1.5 hours. Make sure that reading the history from the pump does not cause unexpected behaviour.</string>
<string name="careportal_removestartedevents">Clean AndroidAPS started</string>
<plurals name="objective_days">
<item quantity="one">%d day</item>

View file

@ -89,13 +89,13 @@
android:defaultValue="false"
android:key="@string/key_high_temptarget_raises_sensitivity"
android:summary="@string/high_temptarget_raises_sensitivity_summary"
android:title="@string/key_high_temptarget_raises_sensitivity" />
android:title="@string/high_temptarget_raises_sensitivity_title" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_low_temptarget_lowers_sensitivity"
android:summary="@string/low_temptarget_lowers_sensitivity_summary"
android:title="@string/key_low_temptarget_lowers_sensitivity" />
android:title="@string/low_temptarget_lowers_sensitivity_title" />
<PreferenceScreen android:title="@string/advancedsettings_title">

View file

@ -70,6 +70,14 @@ public class NsClientReceiverDelegateTest {
ev.mobileConnected = true;
ev.wifiConnected = true;
assertTrue(sut.calculateStatus(ev));
ev.ssid = "test";
when(SP.getString(anyInt(), anyString())).thenReturn("\"test\"");
assertTrue(sut.calculateStatus(ev));
ev.ssid = "\"test\"";
assertTrue(sut.calculateStatus(ev));
ev.wifiConnected = false;
assertTrue(sut.calculateStatus(ev));

View file

@ -0,0 +1,22 @@
package info.nightscout.utils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class StringUtilsTest {
@Test
public void removeSurroundingQuotesTest() {
String compareString = "test";
assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString));
assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""));
assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString));
compareString = "te\"st";
assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString));
assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\""));
assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString));
}
}