From 311830564230ed3a49a60aaf6468c29860947494 Mon Sep 17 00:00:00 2001 From: Diego Serrano Date: Mon, 28 Jun 2021 12:41:29 -0500 Subject: [PATCH] Add setSurveyedDefault method --- CHANGELOG.md | 4 ++ README.md | 4 +- androidsdk/gradle.properties | 4 +- .../wootric/androidsdk/SurveyValidator.java | 5 +++ .../java/com/wootric/androidsdk/Wootric.java | 9 +++++ .../wootric/androidsdk/objects/Settings.java | 12 ++++++ .../androidsdk/SurveyValidatorTest.java | 40 +++++++++++++++++++ 7 files changed, 74 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff5d29dd..06408de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.20.0 (2021-06-29) + +- Add setSurveyedDefault method + ## 2.19.0 (2021-04-19) - Reskin diff --git a/README.md b/README.md index da659940..b0db9a78 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,14 @@ If you use Maven, you can include this library as a dependency: com.wootric wootric-sdk-android - 2.19.0 + 2.20.0 ``` ### Using Gradle ```xml -implementation 'com.wootric:wootric-sdk-android:2.19.0' +implementation 'com.wootric:wootric-sdk-android:2.20.0' ``` ## Initializing Wootric diff --git a/androidsdk/gradle.properties b/androidsdk/gradle.properties index ec4e6def..6c547750 100644 --- a/androidsdk/gradle.properties +++ b/androidsdk/gradle.properties @@ -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 diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/SurveyValidator.java b/androidsdk/src/main/java/com/wootric/androidsdk/SurveyValidator.java index 65fb1377..6f213903 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/SurveyValidator.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/SurveyValidator.java @@ -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(); @@ -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(); diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/Wootric.java b/androidsdk/src/main/java/com/wootric/androidsdk/Wootric.java index 450a6be4..a2a82563 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/Wootric.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/Wootric.java @@ -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. *
diff --git a/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java b/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java index 7b02baa4..93cf65e8 100644 --- a/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java +++ b/androidsdk/src/main/java/com/wootric/androidsdk/objects/Settings.java @@ -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; @@ -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; @@ -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; } @@ -169,6 +175,10 @@ public boolean isSurveyImmediately() { return surveyImmediately; } + public boolean isSurveyedDefault() { + return surveyedDefault; + } + public void setSkipFollowupScreenForPromoters(boolean skipFollowupScreenForPromoters) { this.skipFollowupScreenForPromoters = skipFollowupScreenForPromoters; } @@ -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); @@ -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()); diff --git a/androidsdk/src/test/java/com/wootric/androidsdk/SurveyValidatorTest.java b/androidsdk/src/test/java/com/wootric/androidsdk/SurveyValidatorTest.java index 3efefcfe..7a34d4ff 100644 --- a/androidsdk/src/test/java/com/wootric/androidsdk/SurveyValidatorTest.java +++ b/androidsdk/src/test/java/com/wootric/androidsdk/SurveyValidatorTest.java @@ -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();