Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleaned up conditions for uploading.
* Bumped dependency version numbers.
* Added method for dynamically setting user ID.
  • Loading branch information
audaciouscode committed Dec 1, 2016
1 parent 4e05dbb commit 791502d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Expand Up @@ -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'
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 791502d

Please sign in to comment.