Skip to content
This repository has been archived by the owner on Oct 19, 2019. It is now read-only.

Commit

Permalink
- reduced a bit the calls to completionhandler in nightscoutservice, …
Browse files Browse the repository at this point in the history
…assuming this was causing problems

- in modellocator adding log in database when app goes to fore or background
  • Loading branch information
Jozefien Degraeve authored and Jozefien Degraeve committed Dec 6, 2016
1 parent 68780c5 commit a43159c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
10 changes: 9 additions & 1 deletion src/model/ModelLocator.as
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ package model

public static function set isInForeground(value:Boolean):void
{
if (_isInForeground == value)
return;

_isInForeground = value;
if (_loggingList != null) {
_loggingList.addItem((new BlueToothServiceEvent(BlueToothServiceEvent.BLUETOOTH_SERVICE_INFORMATION_EVENT)).getTimeStampAsString() + " ML : " + "app is " + (_isInForeground ? "":"not") + " in foreground");
_loggingList.refresh();
Database.insertLogging(Utilities.UniqueId.createEventId(), (new BlueToothServiceEvent(BlueToothServiceEvent.BLUETOOTH_SERVICE_INFORMATION_EVENT)).getTimeStampAsString() + " ML : " + "app is " + (_isInForeground ? "":"not") + " in foreground", (new Date()).valueOf(), (new Date()).valueOf(),null);
}
}


Expand Down Expand Up @@ -227,7 +235,7 @@ package model
Database.getBgReadings(_appStartTimestamp);

//for an unknown reasy _isInForeground is back to value false here, so setting it to true.
_isInForeground = true;
isInForeground = true;
}

function bgReadingReceivedFromDatabase(de:DatabaseEvent):void {
Expand Down
26 changes: 14 additions & 12 deletions src/services/NightScoutService.as
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,14 @@ package services

private static function nightScoutUploadSuccess(event:Event):void {
BackGroundFetchService.callCompletionHandler(BackGroundFetchService.NEW_DATA);
functionToCallAtUpOrDownloadSuccess = null;
functionToCallAtUpOrDownloadFailure = null;

dispatchInformation("upload_to_nightscout_successfull");
CommonSettings.setCommonSetting(CommonSettings.COMMON_SETTING_NIGHTSCOUT_SYNC_TIMESTAMP, (new Date()).valueOf().toString());
trace("NightScoutService.as setting syncRunning = false");
syncRunning = false;
syncFinished(true);
}

private static function nightScoutUploadFailed(event:BackGroundFetchServiceEvent):void {
BackGroundFetchService.callCompletionHandler(BackGroundFetchService.FETCH_FAILED);
functionToCallAtUpOrDownloadSuccess = null;
functionToCallAtUpOrDownloadFailure = null;

var errorMessage:String;
if (event.data) {
Expand All @@ -364,19 +359,26 @@ package services
}

dispatchInformation("upload_to_nightscout_unsuccessfull", errorMessage);
trace("NightScoutService.as setting syncRunning = false");
syncRunning = false;
syncFinished(false);
}

private static function defaultErrorFunction(event:BackGroundFetchServiceEvent):void {
if(functionToCallAtUpOrDownloadFailure != null)
functionToCallAtUpOrDownloadFailure(event);
BackGroundFetchService.callCompletionHandler(BackGroundFetchService.FETCH_FAILED);
else
BackGroundFetchService.callCompletionHandler(BackGroundFetchService.FETCH_FAILED);

functionToCallAtUpOrDownloadSuccess = null;
functionToCallAtUpOrDownloadFailure = null;
}
private static function defaultSuccessFunction(event:BackGroundFetchServiceEvent):void {
if(functionToCallAtUpOrDownloadSuccess != null)
functionToCallAtUpOrDownloadSuccess(event);
BackGroundFetchService.callCompletionHandler(BackGroundFetchService.NEW_DATA);
else
BackGroundFetchService.callCompletionHandler(BackGroundFetchService.NEW_DATA);

functionToCallAtUpOrDownloadSuccess = null;
functionToCallAtUpOrDownloadFailure = null;
}

/**
Expand All @@ -399,7 +401,7 @@ package services
Trace.myTrace("xdrip-NightScoutService.as", log);
}

private static function nightScoutAPICallFailed(event:IOErrorEvent):void {
/*private static function nightScoutAPICallFailed(event:IOErrorEvent):void {
var errorMessage:String = "NightScoutAPICallFailed event.target.data = ";
if (event.target.data)
if (event.target.data is String)
Expand All @@ -415,7 +417,7 @@ package services
syncRunning = false;
functionToCallAtUpOrDownloadSuccess = null;
functionToCallAtUpOrDownloadFailure = null;
}
}*/

private static function syncFinished(result:Boolean):void {
trace("syncfinished still to be implemented");
Expand Down

0 comments on commit a43159c

Please sign in to comment.