Skip to content
Snippets Groups Projects
Commit 3156be4d authored by Lennart Goedhart's avatar Lennart Goedhart
Browse files
parents 688016d7 9dcbf1ca
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,9 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<!-- allow to disable battery optimization -->
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<application
android:name=".UploaderApplication"
android:allowBackup="true"
......@@ -26,8 +29,6 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- allow to disable battery optimization -->
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<!-- I have set screenOrientation to "portrait" to avoid the restart of AsyncTasks when you rotate the phone -->
<activity
......
......@@ -10,6 +10,8 @@ import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
......@@ -169,22 +171,22 @@ public class NightscoutUploadIntentService extends IntentService {
addMbgEntry(entriesBody, record);
}
uploadToNightscout(new URL(baseURL + "/entries"), secret, entriesBody);
boolean isUploaded = uploadToNightscout(new URL(baseURL + "/entries"), secret, entriesBody);
for(int i = 0; i < devicestatusBody.length(); i++) {
uploadToNightscout(new URL(baseURL + "/devicestatus"), secret, devicestatusBody.getJSONObject(i));
for(int i = 0; isUploaded && i < devicestatusBody.length(); i++) {
isUploaded &= uploadToNightscout(new URL(baseURL + "/devicestatus"), secret, devicestatusBody.getJSONObject(i));
}
// Yay! We uploaded. Tell Realm
// FIXME - check the upload succeeded!
mRealm.beginTransaction();
for (PumpStatusEvent updateRecord : records) {
updateRecord.setUploaded(true);
if (isUploaded) {
// Yay! We uploaded. Tell Realm
// FIXME - check the upload succeeded!
mRealm.beginTransaction();
for (PumpStatusEvent updateRecord : records) {
updateRecord.setUploaded(true);
}
mRealm.commitTransaction();
}
mRealm.commitTransaction();
} catch (Exception e) {
Log.e(TAG, "Unable to post data", e);
}
......@@ -236,6 +238,7 @@ public class NightscoutUploadIntentService extends IntentService {
httpclient.execute(post, responseHandler);
} catch (Exception e) {
Log.w(TAG, "Unable to post data to: '" + post.getURI().toString() + "'", e);
return false;
}
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment