Merge pull request #82 from AdrianLxM/wear-nullprofile-fix

Wear nullprofile fix
This commit is contained in:
Milos Kozak 2016-12-01 13:16:59 +01:00 committed by GitHub
commit e430a0a06b
2 changed files with 23 additions and 6 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
public class WatchUpdaterService extends WearableListenerService implements
GoogleApiClient.ConnectionCallbacks,
@ -139,7 +140,7 @@ public class WatchUpdaterService extends WearableListenerService implements
}
}
public void sendData() {
private void sendData() {
BgReading lastBG = MainApp.getDbHelper().lastBg();
if (lastBG != null) {
@ -147,14 +148,21 @@ public class WatchUpdaterService extends WearableListenerService implements
if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
if (wear_integration) {
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMapSingleBG(lastBG, glucoseStatus));
final DataMap dataMap = dataMapSingleBG(lastBG, glucoseStatus);
if(dataMap==null) {
ToastUtils.showToastInUiThread(this, getString(R.string.noprofile));
return;
}
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMap);
}
}
}
private DataMap dataMapSingleBG(BgReading lastBG, DatabaseHelper.GlucoseStatus glucoseStatus) {
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if(profile == null) return null;
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0"));
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0"));
@ -251,9 +259,16 @@ public class WatchUpdaterService extends WearableListenerService implements
if (!graph_bgs.isEmpty()) {
DataMap entries = dataMapSingleBG(last_bg, glucoseStatus);
if(entries==null) {
ToastUtils.showToastInUiThread(this, getString(R.string.noprofile));
return;
}
final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
for (BgReading bg : graph_bgs) {
dataMaps.add(dataMapSingleBG(bg, glucoseStatus));
DataMap dataMap = dataMapSingleBG(bg, glucoseStatus);
if(dataMap != null) {
dataMaps.add(dataMap);
}
}
entries.putDataMapArrayList("entries", dataMaps);
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(entries);
@ -276,7 +291,9 @@ public class WatchUpdaterService extends WearableListenerService implements
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if( profile == null) return;
if(profile==null) {
return;
}
long beginBasalSegmentTime = startTimeWindow;
long runningTime = startTimeWindow;