From 791502d82b93a38d9e027779f14fac6b3ed7c534 Mon Sep 17 00:00:00 2001 From: "Chris J. Karr" Date: Thu, 1 Dec 2016 07:27:35 -0600 Subject: [PATCH] Cleaned up conditions for uploading. * Bumped dependency version numbers. * Added method for dynamically setting user ID. --- build.gradle | 10 +++++----- .../transmitters/HttpTransmitter.java | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index e3e915d..308c884 100755 --- a/build.gradle +++ b/build.gradle @@ -48,11 +48,11 @@ android { compile 'com.android.support:appcompat-v7:25.0.1' compile 'com.android.support:recyclerview-v7:25.0.1' compile 'com.android.support:cardview-v7:25.0.1' - compile 'com.google.android.gms:play-services-location:10.0.0' - compile 'com.google.android.gms:play-services-maps:10.0.0' - compile 'com.google.android.gms:play-services-nearby:10.0.0' - compile 'com.google.android.gms:play-services-places:10.0.0' - compile 'com.google.android.gms:play-services-awareness:10.0.0' + compile 'com.google.android.gms:play-services-location:10.0.1' + compile 'com.google.android.gms:play-services-maps:10.0.1' + compile 'com.google.android.gms:play-services-nearby:10.0.1' + compile 'com.google.android.gms:play-services-places:10.0.1' + compile 'com.google.android.gms:play-services-awareness:10.0.1' compile 'com.squareup.okhttp3:okhttp:3.2.0' compile 'commons-io:commons-io:2.4' compile 'commons-codec:commons-codec:1.10' diff --git a/src/com/audacious_software/passive_data_kit/transmitters/HttpTransmitter.java b/src/com/audacious_software/passive_data_kit/transmitters/HttpTransmitter.java index 93f74d3..ab65bc8 100755 --- a/src/com/audacious_software/passive_data_kit/transmitters/HttpTransmitter.java +++ b/src/com/audacious_software/passive_data_kit/transmitters/HttpTransmitter.java @@ -136,13 +136,20 @@ else if (!options.containsKey(HttpTransmitter.USER_ID)) { Generators.getInstance(this.mContext).addNewDataPointListener(this); } - private boolean shouldAttemptUpload() { + private boolean shouldAttemptUpload(boolean force) { + if (force) { + return true; + } if (this.mWifiOnly) { - return DeviceInformation.wifiAvailable(this.mContext); + if (DeviceInformation.wifiAvailable(this.mContext) == false) { + return false; + } } if (this.mChargingOnly) { - return DeviceInformation.isPluggedIn(this.mContext); + if (DeviceInformation.isPluggedIn(this.mContext) == false) { + return false; + } } return true; @@ -156,7 +163,7 @@ public void transmit(boolean force) { this.mLastAttempt = 0; } - if (now - this.mLastAttempt < this.mUploadInterval || !this.shouldAttemptUpload()) { + if (now - this.mLastAttempt < this.mUploadInterval || !this.shouldAttemptUpload(force)) { return; } @@ -314,7 +321,6 @@ private int transmitHttpPayload(String payload) { builder = builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"payload\""), RequestBody.create(null, payload)); - RequestBody requestBody = builder.build(); if (this.mUserAgent == null) { @@ -591,6 +597,10 @@ else if (value instanceof Bundle) { } } + public void setUserId(String userId) { + this.mUserId = userId; + } + public static class IncompleteConfigurationException extends RuntimeException { public IncompleteConfigurationException(String message) { super(message);