From a43159c1642b82aabb735a1991635c6a4a9f5541 Mon Sep 17 00:00:00 2001 From: Jozefien Degraeve Date: Tue, 6 Dec 2016 22:54:47 +0100 Subject: [PATCH] - reduced a bit the calls to completionhandler in nightscoutservice, assuming this was causing problems - in modellocator adding log in database when app goes to fore or background --- src/model/ModelLocator.as | 10 +++++++++- src/services/NightScoutService.as | 26 ++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/model/ModelLocator.as b/src/model/ModelLocator.as index 0f562c3..d4fdcd6 100644 --- a/src/model/ModelLocator.as +++ b/src/model/ModelLocator.as @@ -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); + } } @@ -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 { diff --git a/src/services/NightScoutService.as b/src/services/NightScoutService.as index 797db1d..8375508 100644 --- a/src/services/NightScoutService.as +++ b/src/services/NightScoutService.as @@ -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) { @@ -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; } /** @@ -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) @@ -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");