Skip to content

Commit

Permalink
Add Driver Picklist
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Serrano committed Feb 10, 2023
1 parent 0cd3ec7 commit 218405d
Show file tree
Hide file tree
Showing 34 changed files with 1,479 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## 2.23.0 (2023-02-09)

- Add support for Driver Picklist feature
- Add language to response

## 2.22.1 (2023-02-03)

- Fix thank you dialog button color
Expand Down
4 changes: 2 additions & 2 deletions README.md
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.22.1</version>
<version>2.23.0</version>
</dependency>
```

### Using Gradle

```xml
implementation 'com.wootric:wootric-sdk-android:2.22.1'
implementation 'com.wootric:wootric-sdk-android:2.23.0'
```

## Initializing Wootric
Expand Down
1 change: 1 addition & 0 deletions androidsdk/build.gradle
Expand Up @@ -52,6 +52,7 @@ dependencies {
testImplementation 'org.mockito:mockito-core:1.9.5'
testImplementation 'org.robolectric:robolectric:4.1'
testImplementation 'org.json:json:20190722'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.fragment:fragment:1.2.4'
implementation 'androidx.lifecycle:lifecycle-runtime:2.2.0'
Expand Down
4 changes: 2 additions & 2 deletions androidsdk/gradle.properties
@@ -1,5 +1,5 @@
VERSION_NAME=2.22.1
VERSION_CODE=2221
VERSION_NAME=2.23.0
VERSION_CODE=2230
GROUP=com.wootric

POM_DESCRIPTION=WootricSDK Android
Expand Down
Expand Up @@ -30,6 +30,9 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;

/**
* Created by maciejwitowski on 10/30/15.
*/
Expand All @@ -46,6 +49,7 @@ public class OfflineDataHandler {
private static final String KEY_TEXT = "text";
private static final String KEY_UNIQUE_LINK = "survey[unique_link]";
private static final String KEY_LANGUAGE = "survey[language]";
private static final String KEY_DRIVER_PICKLIST = "driver_picklist";

private final PreferencesUtils preferencesUtils;

Expand All @@ -64,6 +68,12 @@ private void processResponse(WootricRemoteClient wootricRemoteClient, String acc

try {
JSONObject jsonResponse = new JSONObject(preferencesUtils.getResponse());
HashMap<String, String>driverPicklist = new HashMap<>();
JSONObject driverPicklistObject = jsonResponse.getJSONObject(KEY_DRIVER_PICKLIST);
for (Iterator<String> it = driverPicklistObject.keys(); it.hasNext(); ) {
String entry = it.next();
driverPicklist.put(entry, driverPicklistObject.getString(entry));
}
wootricRemoteClient.createResponse(
jsonResponse.getLong(KEY_END_USER_ID),
jsonResponse.getLong(KEY_USER_ID),
Expand All @@ -74,7 +84,8 @@ private void processResponse(WootricRemoteClient wootricRemoteClient, String acc
jsonResponse.getInt(KEY_PRIORITY),
jsonResponse.getString(KEY_TEXT),
jsonResponse.getString(KEY_UNIQUE_LINK),
jsonResponse.getString(KEY_LANGUAGE)
jsonResponse.getString(KEY_LANGUAGE),
driverPicklist
);

Log.d(LOG_TAG, "Processed offline Response with data: " + offlineResponse);
Expand Down
Expand Up @@ -27,6 +27,7 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.util.Log;

import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
Expand All @@ -35,8 +36,6 @@
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ProcessLifecycleOwner;

import android.util.Log;

import com.wootric.androidsdk.network.WootricApiCallback;
import com.wootric.androidsdk.network.WootricRemoteClient;
import com.wootric.androidsdk.objects.EndUser;
Expand Down
4 changes: 2 additions & 2 deletions androidsdk/src/main/java/com/wootric/androidsdk/Wootric.java
Expand Up @@ -22,6 +22,8 @@

package com.wootric.androidsdk;

import static com.wootric.androidsdk.utils.Utils.checkNotNull;

import android.app.Activity;
import android.content.Context;
import android.view.WindowManager;
Expand All @@ -41,8 +43,6 @@
import java.lang.ref.WeakReference;
import java.util.HashMap;

import static com.wootric.androidsdk.utils.Utils.checkNotNull;

/**
* Created by maciejwitowski on 4/10/15.
*/
Expand Down
Expand Up @@ -36,6 +36,8 @@
import com.wootric.androidsdk.objects.User;
import com.wootric.androidsdk.utils.PreferencesUtils;

import java.util.HashMap;

/**
* Created by maciejwitowski on 9/11/15.
*/
Expand Down Expand Up @@ -72,8 +74,8 @@ public void createDecline(long endUserId, long userId, long accountId, int prior
new CreateDeclineTask(endUserId, userId, accountId, priority, originUrl, accessToken, this.accountToken, offlineDataHandler, uniqueLink).execute();
}

public void createResponse(long endUserId, long userId, long accountId, String accessToken, String originUrl, int score, int priority, String text, String uniqueLink, String language) {
new CreateResponseTask(endUserId, userId, accountId, originUrl, score, priority, text, accessToken, this.accountToken, offlineDataHandler, uniqueLink, language).execute();
public void createResponse(long endUserId, long userId, long accountId, String accessToken, String originUrl, int score, int priority, String text, String uniqueLink, String language, HashMap<String, String>driverPicklist) {
new CreateResponseTask(endUserId, userId, accountId, originUrl, score, priority, text, accessToken, this.accountToken, offlineDataHandler, uniqueLink, language, driverPicklist).execute();
}

public void getRegisteredEvents(User user, final GetRegisteredEventsTask.Callback surveyCallback) {
Expand Down
Expand Up @@ -25,6 +25,8 @@
import com.wootric.androidsdk.Constants;
import com.wootric.androidsdk.OfflineDataHandler;

import java.util.HashMap;

/**
* Created by maciejwitowski on 10/13/15.
*/
Expand All @@ -39,10 +41,11 @@ public class CreateResponseTask extends WootricRemoteRequestTask {
private final String text;
private final String uniqueLink;
private final String language;
private final HashMap<String, String> driverPicklist;

private final OfflineDataHandler offlineDataHandler;

public CreateResponseTask(long endUserId, long userId, long accountId, String originUrl, int score, int priority, String text, String accessToken, String accountToken, OfflineDataHandler offlineDataHandler, String uniqueLink, String language) {
public CreateResponseTask(long endUserId, long userId, long accountId, String originUrl, int score, int priority, String text, String accessToken, String accountToken, OfflineDataHandler offlineDataHandler, String uniqueLink, String language, HashMap<String, String> driverPicklist) {
super(REQUEST_TYPE_POST, accessToken, accountToken, null);

this.endUserId = endUserId;
Expand All @@ -55,6 +58,7 @@ public CreateResponseTask(long endUserId, long userId, long accountId, String or
this.offlineDataHandler = offlineDataHandler;
this.uniqueLink = uniqueLink;
this.language = language;
this.driverPicklist = driverPicklist;
}

@Override
Expand All @@ -79,6 +83,12 @@ protected void buildParams() {
if (accountId != (long) Constants.NOT_SET) {
paramsMap.put("account_id", String.valueOf(accountId));
}

if (driverPicklist != null) {
for (HashMap.Entry<String,String> entry : driverPicklist.entrySet()) {
paramsMap.put("driver_picklist[" + entry.getKey() + "]", entry.getValue());
}
}
if (!text.equals("")) {
addOptionalParam("text", text);
}
Expand All @@ -89,4 +99,4 @@ protected void onError(Exception e) {
super.onError(e);
offlineDataHandler.saveOfflineResponse(endUserId, userId, accountId, originUrl, score, priority, text, uniqueLink, language);
}
}
}
Expand Up @@ -22,8 +22,6 @@

package com.wootric.androidsdk.objects;

import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;

Expand Down
Expand Up @@ -22,6 +22,8 @@

package com.wootric.androidsdk.objects;

import static com.wootric.androidsdk.utils.Utils.isBlank;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
Expand All @@ -34,8 +36,6 @@

import java.util.Date;

import static com.wootric.androidsdk.utils.Utils.isBlank;

/**
* Created by maciejwitowski on 5/5/15.
*/
Expand All @@ -56,6 +56,8 @@ public class Settings implements Parcelable {
private WootricCustomThankYou localCustomThankYou;
private WootricCustomThankYou adminPanelCustomThankYou;

private JSONObject driverPicklist;

private int timeDelay = Constants.NOT_SET;

private boolean surveyedDefault = true;
Expand Down Expand Up @@ -136,6 +138,7 @@ public void mergeWithSurveyServerSettings(Settings settings) {
this.adminPanelTimeDelay = settings.adminPanelTimeDelay;
this.adminPanelCustomThankYou = settings.adminPanelCustomThankYou;
this.adminPanelSocial = settings.adminPanelSocial;
this.driverPicklist = settings.driverPicklist;
this.localizedTexts = settings.localizedTexts;
this.userID = settings.userID;
this.accountID = settings.accountID;
Expand Down Expand Up @@ -242,6 +245,22 @@ public String getBtnEditScore() {

public String getBtnOptOut() { return localizedTexts.getOptOut().toUpperCase(); }

public JSONObject getDriverPicklist(int score) throws JSONException {
JSONObject dpl = new JSONObject();
if (adminPanelCustomMessage != null) {
dpl = adminPanelCustomMessage.getDriverPicklistForScore(score, surveyType, surveyTypeScale);
}
return dpl;
}

public JSONObject getDriverPicklistSettings(int score) throws JSONException {
JSONObject dplSettings = new JSONObject();
if (adminPanelCustomMessage != null) {
dplSettings = adminPanelCustomMessage.getDriverPicklistSettingsForScore(score, surveyType, surveyTypeScale);
}
return dplSettings;
}

public String getFollowupQuestion(int score) {
String followupQuestion = null;

Expand Down
Expand Up @@ -46,6 +46,11 @@ public class WootricCustomMessage implements Parcelable {
private String placeholderText;
private HashMap<String, String> placeholderTextsList;

private JSONObject driverPicklist;
private JSONObject driverPicklistObject;
private JSONObject driverPicklistSettings;
private JSONObject driverPicklistSettingsList;

public WootricCustomMessage() {
this.followupQuestionsList = new HashMap<>();
this.placeholderTextsList = new HashMap<>();
Expand Down Expand Up @@ -95,6 +100,48 @@ String getPromoterPlaceholder() {
return placeholderTextsList.get(PROMOTER_TEXT_KEY);
}

JSONObject getDetractorPicklist() throws JSONException {
if (driverPicklistObject != null && driverPicklistObject.has("detractor_picklist")) {
return driverPicklistObject.getJSONObject("detractor_picklist");
}
return null;
}

JSONObject getPassivePicklist() throws JSONException {
if (driverPicklistObject != null && driverPicklistObject.has("passive_picklist")) {
return driverPicklistObject.getJSONObject("passive_picklist");
}
return null;
}

JSONObject getPromoterPicklist() throws JSONException {
if (driverPicklistObject != null && driverPicklistObject.has("promoter_picklist")) {
return driverPicklistObject.getJSONObject("promoter_picklist");
}
return null;
}

JSONObject getDetractorPicklistSettings() throws JSONException {
if (driverPicklistSettingsList != null && driverPicklistSettingsList.has("detractor")) {
return driverPicklistSettingsList.getJSONObject("detractor");
}
return null;
}

JSONObject getPassivePicklistSettings() throws JSONException {
if (driverPicklistSettingsList != null && driverPicklistSettingsList.has("passive")) {
return driverPicklistSettingsList.getJSONObject("passive");
}
return null;
}

JSONObject getPromoterPicklistSettings() throws JSONException {
if (driverPicklistSettingsList != null && driverPicklistSettingsList.has("promoter")) {
return driverPicklistSettingsList.getJSONObject("promoter");
}
return null;
}

public void setFollowupQuestion(String followupQuestion) {
this.followupQuestion = followupQuestion;
}
Expand Down Expand Up @@ -155,6 +202,34 @@ public String getPlaceholderForScore(int scoreValue, String surveyType, int surv
}
}

public JSONObject getDriverPicklistForScore(int scoreValue, String surveyType, int surveyTypeScale) throws JSONException{
final Score score = new Score(scoreValue, surveyType, surveyTypeScale);

if(score.isDetractor() && getDetractorPicklist() != null) {
return getDetractorPicklist();
} else if(score.isPassive() && getPassivePicklist() != null) {
return getPassivePicklist();
} else if(score.isPromoter() && getPromoterPicklist() != null) {
return getPromoterPicklist();
} else {
return driverPicklist;
}
}

public JSONObject getDriverPicklistSettingsForScore(int scoreValue, String surveyType, int surveyTypeScale) throws JSONException{
final Score score = new Score(scoreValue, surveyType, surveyTypeScale);

if(score.isDetractor() && getDetractorPicklistSettings() != null) {
return getDetractorPicklistSettings();
} else if(score.isPassive() && getPassivePicklistSettings() != null) {
return getPassivePicklistSettings();
} else if(score.isPromoter() && getPromoterPicklistSettings() != null) {
return getPromoterPicklistSettings();
} else {
return driverPicklistSettings;
}
}

public void setFollowupQuestionsList(HashMap<String, String> followupQuestionsList) {
this.followupQuestionsList = followupQuestionsList;
}
Expand Down Expand Up @@ -197,6 +272,8 @@ public static WootricCustomMessage fromJson(JSONObject customMessagesJson) throw

wootricCustomMessage.followupQuestion = customMessagesJson.optString("followup_question");
wootricCustomMessage.placeholderText = customMessagesJson.optString("placeholder_text");
wootricCustomMessage.driverPicklist = customMessagesJson.optJSONObject("picklist");
wootricCustomMessage.driverPicklistSettings = customMessagesJson.optJSONObject("driver_picklist_settings");

wootricCustomMessage.followupQuestionsList = new HashMap<>();
JSONObject followupQuestionListJson = customMessagesJson.optJSONObject("followup_questions_list");
Expand All @@ -213,6 +290,9 @@ public static WootricCustomMessage fromJson(JSONObject customMessagesJson) throw
wootricCustomMessage.placeholderTextsList.put(PASSIVE_TEXT_KEY, placeholderTextsListJson.optString(PASSIVE_TEXT_KEY));
wootricCustomMessage.placeholderTextsList.put(PROMOTER_TEXT_KEY, placeholderTextsListJson.optString(PROMOTER_TEXT_KEY));
}

wootricCustomMessage.driverPicklistObject = customMessagesJson.optJSONObject("driver_picklist");
wootricCustomMessage.driverPicklistSettingsList = customMessagesJson.optJSONObject("driver_picklist_settings_list");
return wootricCustomMessage;
}
}

0 comments on commit 218405d

Please sign in to comment.