Skip to content

Commit

Permalink
Add setSurveyedDefault method
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Serrano committed Jun 29, 2021
1 parent 740ce1c commit 3118305
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.20.0 (2021-06-29)

- Add setSurveyedDefault method

## 2.19.0 (2021-04-19)

- Reskin
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ If you use Maven, you can include this library as a dependency:
<dependency>
<groupId>com.wootric</groupId>
<artifactId>wootric-sdk-android</artifactId>
<version>2.19.0</version>
<version>2.20.0</version>
</dependency>
```

### Using Gradle

```xml
implementation 'com.wootric:wootric-sdk-android:2.19.0'
implementation 'com.wootric:wootric-sdk-android:2.20.0'
```

## Initializing Wootric
Expand Down
4 changes: 2 additions & 2 deletions androidsdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=2.19.0
VERSION_CODE=2190
VERSION_NAME=2.20.0
VERSION_CODE=2200
GROUP=com.wootric

POM_DESCRIPTION=WootricSDK Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void setOnSurveyValidatedListener(OnSurveyValidatedListener onSurveyValid

public void validate() {
Boolean immediate = settings.isSurveyImmediately();
Boolean surveyedDefault = settings.isSurveyedDefault();
Boolean recently = preferencesUtils.wasRecentlySurveyed();
Boolean firstDelay = firstSurveyDelayPassed();
Boolean lastSeen = lastSeenDelayPassed();
Expand All @@ -82,10 +83,14 @@ public void validate() {
Log.d(Constants.TAG, "WAS RECENTLY SURVEYED: " + recently);
Log.d(Constants.TAG, "FIRST SURVEY DELAY PASSED: " + firstDelay);
Log.d(Constants.TAG, "LAST SEEN DELAY PASSED: " + lastSeen);
Log.d(Constants.TAG, "SURVEYED DEFAULT: " + surveyedDefault);

if (immediate) {
Log.d(Constants.TAG, "Needs survey. Will check with server.");
checkEligibility();
} else if (!surveyedDefault) {
Log.d(Constants.TAG, "surveyedDefault is false. Will check with server.");
checkEligibility();
} else if (recently) {
Log.d(Constants.TAG, "Doesn't need survey. Recently surveyed.");
notifyShouldNotShowSurvey();
Expand Down
9 changes: 9 additions & 0 deletions androidsdk/src/main/java/com/wootric/androidsdk/Wootric.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ public void setProductName(String productName) {
settings.setProductName(productName);
}

/**
* If surveyedDefault is set to false the SDK will always check with the server
* to see if the end user is eligible
* @param surveyedDefault A boolean to set if the SDK should check with the eligibility server.
*/
public void setSurveyedDefault(Boolean surveyedDefault) {
settings.setSurveyedDefault(surveyedDefault);
}

/**
* It sets the audience of the survey.
* <br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Settings implements Parcelable {

private int timeDelay = Constants.NOT_SET;

private boolean surveyedDefault = true;
private boolean surveyImmediately;
private boolean showOptOut;
private boolean skipFollowupScreenForPromoters;
Expand Down Expand Up @@ -97,6 +98,7 @@ public Settings(Settings settings) {
this.localCustomThankYou = new WootricCustomThankYou(settings.localCustomThankYou);
this.adminPanelCustomThankYou = new WootricCustomThankYou(settings.adminPanelCustomThankYou);
this.timeDelay = settings.timeDelay;
this.surveyedDefault = settings.surveyedDefault;
this.surveyImmediately = settings.surveyImmediately;
this.showOptOut = settings.showOptOut;
this.skipFollowupScreenForPromoters = settings.skipFollowupScreenForPromoters;
Expand Down Expand Up @@ -159,6 +161,10 @@ public void setSurveyImmediately(boolean surveyImmediately) {
this.surveyImmediately = surveyImmediately;
}

public void setSurveyedDefault(boolean surveyedDefault) {
this.surveyedDefault = surveyedDefault;
}

public void setShowOptOut(boolean showOptOut) {
this.showOptOut = showOptOut;
}
Expand All @@ -169,6 +175,10 @@ public boolean isSurveyImmediately() {
return surveyImmediately;
}

public boolean isSurveyedDefault() {
return surveyedDefault;
}

public void setSkipFollowupScreenForPromoters(boolean skipFollowupScreenForPromoters) {
this.skipFollowupScreenForPromoters = skipFollowupScreenForPromoters;
}
Expand Down Expand Up @@ -728,6 +738,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(this.localCustomMessage, 0);
dest.writeInt(this.timeDelay);
dest.writeByte(surveyImmediately ? (byte) 1 : (byte) 0);
dest.writeByte(surveyedDefault ? (byte) 1 : (byte) 0);
dest.writeValue(this.dailyResponseCap);
dest.writeValue(this.registeredPercent);
dest.writeValue(this.visitorPercent);
Expand Down Expand Up @@ -755,6 +766,7 @@ private Settings(Parcel in) {
this.localCustomMessage = in.readParcelable(WootricCustomMessage.class.getClassLoader());
this.timeDelay = in.readInt();
this.surveyImmediately = in.readByte() != 0;
this.surveyedDefault = in.readByte() != 0;
this.dailyResponseCap = (Integer) in.readValue(Integer.class.getClassLoader());
this.registeredPercent = (Integer) in.readValue(Integer.class.getClassLoader());
this.visitorPercent = (Integer) in.readValue(Integer.class.getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,46 @@ public void checksEligibility_whenNotRecentlySurveyed() throws Exception {
verify(wootricRemoteClient, times(1)).checkEligibility(user, endUser, settings, preferencesUtils, surveyValidator);
}

@Test
public void checksEligibility_whenSurveyedDefaultIsFalse() throws Exception {
User user = testUser();
EndUser endUser = testEndUser();
Settings settings = new Settings();
settings.setSurveyedDefault(false);

SurveyValidator surveyValidator = new SurveyValidator(user, endUser, settings,
wootricRemoteClient, preferencesUtils);

surveyValidator.validate();

verify(wootricRemoteClient, times(1)).checkEligibility(user, endUser, settings, preferencesUtils, surveyValidator);
}

@Test
public void doesNotCheckEligibility_whenSurveyedDefaultIsTrue() throws Exception {
User user = testUser();
EndUser endUser = testEndUser();
long createdAtJustNow = new Date().getTime();
endUser.setCreatedAt(createdAtJustNow);

Settings settings = new Settings();

SurveyValidator surveyValidator = new SurveyValidator(user, endUser, settings,
wootricRemoteClient, preferencesUtils);

surveyValidator.validate();

verify(wootricRemoteClient, times(0)).checkEligibility(user, endUser, settings, preferencesUtils, surveyValidator);

settings.setSurveyedDefault(true);
surveyValidator = new SurveyValidator(user, endUser, settings,
wootricRemoteClient, preferencesUtils);

surveyValidator.validate();

verify(wootricRemoteClient, times(0)).checkEligibility(user, endUser, settings, preferencesUtils, surveyValidator);
}

@Test
public void doesNotCheckEligibility_whenRecentlySurveyed() throws Exception {
User user = testUser();
Expand Down

0 comments on commit 3118305

Please sign in to comment.