Skip to content

Commit

Permalink
patched some minor bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Feb 2, 2015
1 parent 1416f3d commit adaa08a
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 25 deletions.
1 change: 1 addition & 0 deletions gen/com/nightscout/android/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static final class string {
public static final int hello_world=0x7f060002;
public static final int self_destruct=0x7f060007;
public static final int sgv_id=0x7f060004;
public static final int version=0x7f06000c;
}
public static final class style {
/**
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="eula_title">Disclaimer</string>
<string name="eula_accept">Accept</string>
<string name="eula_refuse">Refuse</string>
<string name="version">Version: 29.01.15</string>
<style name="ButtonText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
31 changes: 17 additions & 14 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Monitor">
<SwitchPreference
<com.nightscout.android.utils.CustomSwitchPreference
android:title="mmol/l"
android:key="mmolxl"
android:disableDependentsState="false"
android:switchTextOn="mmol/l"
android:switchTextOff="mg/dl"
android:summaryOn="mmol/l. Values are shown and setted in mmol/l"
android:summaryOff="mg/dl. Values are shown and setted in mg/dl">
</SwitchPreference>
</com.nightscout.android.utils.CustomSwitchPreference>
<ListPreference
android:key="monitor_type"
android:disableDependentsState="false"
Expand Down Expand Up @@ -78,12 +78,12 @@
/>
</PreferenceCategory>
<PreferenceCategory android:title="Sharing">
<SwitchPreference
<com.nightscout.android.utils.CustomSwitchPreference
android:title="API Upload (REST)"
android:key="EnableRESTUpload"
android:disableDependentsState="false"
android:summary="The REST API is an alternative to direct mongodb upload">
</SwitchPreference>
</com.nightscout.android.utils.CustomSwitchPreference>
<EditTextPreference
android:dependency="EnableRESTUpload"
android:title="API Base URL"
Expand All @@ -92,12 +92,12 @@
android:defaultValue="http://{YOUR-API-SERVER}/api"
android:dialogMessage="This only the base URL, the uploader will automatically append /entries for the POST of CGM data and /gdentries for the POST of glucometer data values">
</EditTextPreference>
<SwitchPreference
<com.nightscout.android.utils.CustomSwitchPreference
android:title="MongoDB Upload"
android:key="EnableMongoUpload"
android:disableDependentsState="false"
android:summary="If you're using MongoLab and Azure this should be enabled">
</SwitchPreference>
</com.nightscout.android.utils.CustomSwitchPreference>
<EditTextPreference
android:dependency="EnableMongoUpload"
android:title="MongoDB URI"
Expand All @@ -120,36 +120,39 @@
android:dialogTitle="Enter Collection Name"
android:dialogMessage="This is the name of the collection where the glucometer data will be stored">
</EditTextPreference>
<SwitchPreference
<com.nightscout.android.utils.CustomSwitchPreference
android:title="Wifi Hack"
android:key="EnableWifiHack"
android:disableDependentsState="false"
android:defaultValue="false"
android:summaryOn="Wifi will be disabled if there is a timeout (poor wifi signal/access point), this will allow mobile data to be used instead"
android:summaryOff="The uploader won't try to disable Wifi even if there is a timeout"
>
</SwitchPreference>
<SwitchPreference
</com.nightscout.android.utils.CustomSwitchPreference>
<com.nightscout.android.utils.CustomSwitchPreference
android:title="2 Days at Startup"
android:key="InitialTwoDayUpload"
android:disableDependentsState="false"
android:defaultValue="true"
android:summaryOn="When the upload application first starts it will upload ~2.5 days of data"
android:summaryOff="The uploader won't try upload old data"
>
</SwitchPreference>
</com.nightscout.android.utils.CustomSwitchPreference>
</PreferenceCategory>
<PreferenceCategory android:title="Disclaimer">
<SwitchPreference
<com.nightscout.android.utils.CustomSwitchPreference
android:title="I UNDERSTAND"
android:key="IUNDERSTAND"
android:disableDependentsState="false"
android:switchTextOn="YES"
android:switchTextOff="NO"
android:summaryOn="Activated. Nightscout should not be used to make medical decisions. There is no support or any warranty of any kind. The quality and performance of the project is with you. This is a project that was created and is supported completely by volunteers"
android:summaryOff="Deactivated. Nightscout should not be used to make medical decisions. There is no support or any warranty of any kind. The quality and performance of the project is with you. This is a project that was created and is supported completely by volunteers">
</SwitchPreference>
</PreferenceCategory>
</com.nightscout.android.utils.CustomSwitchPreference>
<Preference
android:key="version"
android:title="@string/version" />
</PreferenceCategory>
<PreferenceCategory android:title="Debug">
<ListPreference
android:key="logLevel"
Expand All @@ -158,7 +161,7 @@
android:summary="Select item from array"
android:entries="@array/levelList"
android:entryValues="@array/calib_types_values"
android:defaultValue="1"
android:defaultValue="3"
/>
</PreferenceCategory>
</PreferenceScreen>
4 changes: 2 additions & 2 deletions src/com/nightscout/android/dexcom/DexcomG4Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void run() {
}
}
calib+= ""+ lastCal + tail;
if (prefs.getInt("isWarmingUp",-1) == 0){
if (prefs.getBoolean("isWarmingUp",false)){
calib = "";
record.bGValue = "W_Up";
record.trendArrow="---";
Expand Down Expand Up @@ -482,7 +482,7 @@ protected void onResume() {
calib+= ""+ lastCal + tail;
}

if (prefs.getInt("isWarmingUp",-1) == 0){
if (prefs.getBoolean("isWarmingUp",false)){
calib = "";
record.bGValue = "W_Up";
record.trendArrow="---";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import android.os.Handler;
import android.os.Messenger;
import android.util.Log;

import ch.qos.logback.core.pattern.PostCompileProcessor;

import com.nightscout.android.dexcom.USB.HexDump;
import com.physicaloid.lib.Physicaloid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void onCreate() {
//Debug.startMethodTracing();

super.onCreate();
if (android.os.Build.VERSION.SDK_INT > 9)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
Expand All @@ -447,6 +447,7 @@ public void onCreate() {

settings = getSharedPreferences(MedtronicConstants.PREFS_NAME, 0);
prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
prefs.edit().remove("isCheckedWUP").commit();
prefs.registerOnSharedPreferenceChangeListener(this);
String level = prefs.getString("logLevel", "1");
if ("2".equalsIgnoreCase(level))
Expand Down
18 changes: 15 additions & 3 deletions src/com/nightscout/android/medtronic/MedtronicReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ public String processBufferedMessages(ArrayList<byte[]> bufferedMessages) {
editor.remove("expectedSensorSortNumber");
editor.remove("expectedSensorSortNumberForCalibration0");
editor.remove("expectedSensorSortNumberForCalibration1");
editor.remove("isCheckedWUP");
if (!prefs.getBoolean("isWarmingUp", false)){
if (lastMedtronicPumpRecord == null) {
lastMedtronicPumpRecord = new MedtronicPumpRecord();
Expand All @@ -702,14 +703,25 @@ public String processBufferedMessages(ArrayList<byte[]> bufferedMessages) {
writeLocalCSV(previousRecord, context);
}
sendMessageToUI("sensor data wUp.", false);
editor.commit();
break;
}case MedtronicConstants.MEDTRONIC_SENSOR2:
SharedPreferences.Editor editor1 = settings.edit();
editor1.putBoolean("isWarmingUp", false);
editor1.commit();

if (lastMedtronicPumpRecord != null)
lastMedtronicPumpRecord.isWarmingUp = false;
if (prefs.getString("glucSrcTypes","1").equals("2")){
if (prefs.getBoolean("isWarmingUp", false)){
if (lastMedtronicPumpRecord == null) {
lastMedtronicPumpRecord = new MedtronicPumpRecord();
calculateDate(lastMedtronicPumpRecord,
new Date(), 0);
lastMedtronicPumpRecord.deviceId = prefs.getString("medtronic_cgm_id", "");
}
lastMedtronicPumpRecord.isWarmingUp = false;
SharedPreferences.Editor editor1 = prefs.edit();
editor1.putBoolean("isWarmingUp", false);
editor1.commit();
}
log.debug("Sensor value received, but value is took only by pump logs");
break;
}
Expand Down
39 changes: 38 additions & 1 deletion src/com/nightscout/android/upload/UploadHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.util.Log;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.core.status.WarnStatus;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
Expand Down Expand Up @@ -628,6 +629,8 @@ private void doMongoUpload(SharedPreferences prefs, Record... records) {
if (atLeastOne)
dexcomData.save(testData, WriteConcern.UNACKNOWLEDGED);
}
}catch(IllegalArgumentException ex){
Log.e("UploaderHelper", "Illegal record");
}catch (Exception e){
Log.e("UploaderHelper", "The retried can't be uploaded");
log.error("The retried record can't be uploaded ", e);
Expand All @@ -642,6 +645,7 @@ private void doMongoUpload(SharedPreferences prefs, Record... records) {
}
Log.i(TAG, "The number of EGV records being sent to MongoDB is " + records.length);
log.info("The number of EGV records being sent to MongoDB is " + records.length);
Boolean isWarmingUp = false;
for (Record oRecord : records) {
recordsTry = true;
try{
Expand All @@ -665,6 +669,28 @@ private void doMongoUpload(SharedPreferences prefs, Record... records) {
testData.put("calibrationStatus", ((MedtronicSensorRecord)record).calibrationStatus);
testData.put("unfilteredGlucose", ((MedtronicSensorRecord)record).unfilteredGlucose);
testData.put("isCalibrating", ((MedtronicSensorRecord)record).isCalibrating);
log.info("Testing isCheckedWUP -->", prefs.getBoolean("isCheckedWUP", false));
if (!prefs.getBoolean("isCheckedWUP", false) && deviceData != null){
log.info("Testing isCheckedWUP -->GET INTO");
MedtronicPumpRecord pumpRecord = new MedtronicPumpRecord();
HashMap<String, Object> filter = new HashMap<String, Object>();
filter.put("deviceId", prefs.getString("medtronic_cgm_id", ""));
cursor = deviceData.find(new BasicDBObject(filter));
if (cursor.hasNext()){
DBObject previousRecord = cursor.next();
previousRecord.put("date", testData.get("date"));
previousRecord.put("dateString", testData.get("dateString"));
JSONObject job = new JSONObject(previousRecord.toMap());
isWarmingUp = job.getBoolean("isWarmingUp");
log.info("Testing isCheckedWUP -->NEXT -->ISWUP?? "+ isWarmingUp);
if (isWarmingUp){
pumpRecord.mergeCurrentWithDBObject(previousRecord);
log.info("Uploading a DeviceRecord");
deviceData.save(previousRecord, WriteConcern.ACKNOWLEDGED);
prefs.edit().putBoolean("isCheckedWUP", true).commit();
}
}
}
}
log.info("Uploading a EGVRecord");
dexcomData.save(testData, WriteConcern.UNACKNOWLEDGED);
Expand Down Expand Up @@ -693,6 +719,7 @@ private void doMongoUpload(SharedPreferences prefs, Record... records) {
DBObject previousRecord = cursor.next();
previousRecord.put("date", testData.get("date"));
previousRecord.put("dateString", testData.get("dateString"));
isWarmingUp = pumpRecord.isWarmingUp;
pumpRecord.mergeCurrentWithDBObject(previousRecord);
log.info("Uploading a DeviceRecord");
deviceData.save(previousRecord, WriteConcern.ACKNOWLEDGED);
Expand All @@ -705,24 +732,34 @@ private void doMongoUpload(SharedPreferences prefs, Record... records) {
testData.put("temporaryBasal", pumpRecord.temporaryBasal);
testData.put("batteryStatus", pumpRecord.batteryStatus);
testData.put("batteryVoltage", pumpRecord.batteryVoltage);
isWarmingUp = pumpRecord.isWarmingUp;
testData.put("isWarmingUp", pumpRecord.isWarmingUp);
log.info("Uploading a DeviceRecord");
deviceData.save(testData, WriteConcern.UNACKNOWLEDGED);
}
if (cursor != null)
cursor.close();
}
}catch(Exception ex2){
}catch(IllegalArgumentException ex){
Log.e("UploaderHelper", "Illegal record");
if (cursor != null)
cursor.close();
}catch(Exception ex2){
if (cursor != null)
cursor.close();
if ((typeSaved != null && (typeSaved == 0 ||typeSaved == 1 ))){//Only EGV records are important enough.
if (isWarmingUp){
prefs.edit().putBoolean("isCheckedWUP", false);
}
log.warn("added to records not uploaded");
if (recordsNotUploadedList.size() > 49){
recordsNotUploadedList.remove(0);
recordsNotUploadedList.add(49, new JSONObject(testData.toMap()));
}else{
recordsNotUploadedList.add(new JSONObject(testData.toMap()));
}
}else if (typeSaved == 3){
prefs.edit().putBoolean("isWarmingUp", isWarmingUp);
}
Log.w(TAG, "Unable to upload data to mongo in loop");
log.warn("Unable to upload data to mongo in loop");
Expand Down
74 changes: 74 additions & 0 deletions src/com/nightscout/android/utils/CustomSwitchPreference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.nightscout.android.utils;

import android.content.Context;
import android.preference.SwitchPreference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;

public class CustomSwitchPreference extends SwitchPreference {

/**
* Construct a new SwitchPreference with the given style options.
*
* @param context The Context that will style this preference
* @param attrs Style attributes that differ from the default
* @param defStyle Theme attribute defining the default style options
*/
public CustomSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

/**
* Construct a new SwitchPreference with the given style options.
*
* @param context The Context that will style this preference
* @param attrs Style attributes that differ from the default
*/
public CustomSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}

/**
* Construct a new SwitchPreference with default style options.
*
* @param context The Context that will style this preference
*/
public CustomSwitchPreference(Context context) {
super(context, null);
}

@Override
protected void onBindView(View view) {
// Clean listener before invoke SwitchPreference.onBindView
ViewGroup viewGroup= (ViewGroup)view;
clearListenerInViewGroup(viewGroup);
super.onBindView(view);
}

/**
* Clear listener in Switch for specify ViewGroup.
*
* @param viewGroup The ViewGroup that will need to clear the listener.
*/
private void clearListenerInViewGroup(ViewGroup viewGroup) {
if (null == viewGroup) {
return;
}

int count = viewGroup.getChildCount();
for(int n = 0; n < count; ++n) {
View childView = viewGroup.getChildAt(n);
if(childView instanceof Switch) {
final Switch switchView = (Switch) childView;
switchView.setOnCheckedChangeListener(null);
return;
} else if (childView instanceof ViewGroup){
ViewGroup childGroup = (ViewGroup)childView;
clearListenerInViewGroup(childGroup);
}
}
}

}
2 changes: 1 addition & 1 deletion src/com/nightscout/android/widget/CGMWidgetUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void updateValues(Record auxRecord, RemoteViews views){
calib = "*";
else
calib = MedtronicConstants.getWidgetCalAppend(record.calibrationStatus);
if (prefs.getInt("isWarmingUp",-1) == 0){
if (prefs.getBoolean("isWarmingUp",false)){
calib = "";
record.bGValue = "W._Up";
record.trendArrow="---";
Expand Down

0 comments on commit adaa08a

Please sign in to comment.