Skip to content

Commit 70bc31b

Browse files
committed
[PR-10806] Debug mode improvements
* Added ability to use randomized or custom device ID in debug mode * Debug mode now initialized via `Talkable.initialize` method * Added missing getters to the Reward model
1 parent a6e7b8f commit 70bc31b

File tree

7 files changed

+73
-39
lines changed

7 files changed

+73
-39
lines changed

app/src/main/java/com/talkable/demo/MainActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ public void run() {
216216
}
217217

218218
public void onDeepLinkingClick(View view) {
219-
Talkable.setDebug(true);
220219
EditText webUuidText = findViewById(R.id.webUUIDText);
221220
String webUuid = webUuidText.getText().toString();
222221
EditText offerIdText = findViewById(R.id.offerIDText);
@@ -229,6 +228,5 @@ public void onDeepLinkingClick(View view) {
229228
paramsMap.put(VISITOR_OFFER_KEY, offerId);
230229
}
231230
TalkableDeepLinking.track(paramsMap);
232-
Talkable.setDebug(false);
233231
}
234232
}

sdk/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
defaultConfig {
1111
minSdkVersion 16
1212
targetSdkVersion 26
13-
versionCode 37
14-
versionName "0.5.6"
13+
versionCode 38
14+
versionName "0.5.7"
1515
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1616
}
1717
buildTypes {

sdk/src/main/java/com/talkable/sdk/Talkable.java

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,25 @@ public class Talkable {
6666
public static final String ERROR_REASON_SITE_NOT_FOUND = "SITE_NOT_FOUND";
6767

6868
private static OkHttpClient httpClient;
69-
private static String server, siteSlug, nativeFeatures, defaultUserAgent;
70-
private static boolean debug = false;
69+
private static String server, siteSlug, nativeFeatures, defaultUserAgent, debugDeviceId;
7170
private static Map<String, String> credentialsMap;
72-
private static Boolean initialized = false;
71+
private static Boolean initialized = false, debug = false;
7372

7473
//----------------+
7574
// Initialization |
7675
//----------------+
7776

7877
public static void initialize(Context context) throws IncorrectInstallationException {
79-
Context applicationContext = context.getApplicationContext();
78+
initialize(context, null);
79+
}
8080

81-
credentialsMap = ManifestInfo.getCredentialsConfiguration(context);
82-
if (credentialsMap.keySet().size() == 1) {
83-
String talkableSiteSlug = credentialsMap.keySet().iterator().next();
84-
initialize(applicationContext, talkableSiteSlug);
85-
} else {
86-
String defaultSiteSlug = ManifestInfo.getDefaultSiteSlug(applicationContext);
87-
if (defaultSiteSlug != null && !defaultSiteSlug.isEmpty()) {
88-
initialize(applicationContext, defaultSiteSlug);
89-
} else {
90-
throw new IncorrectInstallationException("Default site slug is not specified. " +
91-
"Set default site slug inside an element with `" + ManifestInfo.DEFAULT_SITE_SLUG_KEY+
92-
"` name");
93-
}
81+
public static void initialize(Context context, String initialSiteSlug, boolean debug, String debugDeviceId) throws IncorrectInstallationException {
82+
Talkable.debug = debug;
83+
if (debug) {
84+
Talkable.debugDeviceId = debugDeviceId == null ? UUID.randomUUID().toString() : debugDeviceId;
85+
Log.d(TAG, "Debug mode engaged. Device ID: " + debugDeviceId);
9486
}
87+
initialize(context, initialSiteSlug);
9588
}
9689

9790
public static void initialize(Context context, String initialSiteSlug) throws IncorrectInstallationException {
@@ -100,10 +93,24 @@ public static void initialize(Context context, String initialSiteSlug) throws In
10093
return;
10194
}
10295

103-
Log.d(TAG, "Initializing Talkable SDK with `" + initialSiteSlug + "` site slug");
104-
10596
Context applicationContext = context.getApplicationContext();
10697

98+
if (initialSiteSlug == null) {
99+
credentialsMap = ManifestInfo.getCredentialsConfiguration(context);
100+
if (credentialsMap.keySet().size() == 1) {
101+
initialSiteSlug = credentialsMap.keySet().iterator().next();
102+
} else {
103+
initialSiteSlug = ManifestInfo.getDefaultSiteSlug(applicationContext);
104+
}
105+
if (initialSiteSlug == null || initialSiteSlug.isEmpty()) {
106+
throw new IncorrectInstallationException("Default site slug is not specified. " +
107+
"Set default site slug inside an element with `" + ManifestInfo.DEFAULT_SITE_SLUG_KEY+
108+
"` name");
109+
}
110+
}
111+
112+
Log.d(TAG, "Initializing Talkable SDK with `" + initialSiteSlug + "` site slug");
113+
107114
loadConfig(applicationContext);
108115
setSiteSlug(initialSiteSlug);
109116
setHttpClient(applicationContext);
@@ -374,14 +381,14 @@ public static void setSiteSlug(String newSiteSlug) {
374381
siteSlug = newSiteSlug;
375382
}
376383

377-
public static void setDebug(boolean newDebug) {
378-
debug = newDebug;
379-
}
380-
381384
public static boolean getDebug() {
382385
return debug;
383386
}
384387

388+
public static String getDebugDeviceId() {
389+
return debugDeviceId;
390+
}
391+
385392
public static Boolean isInitialized() {
386393
return initialized;
387394
}
@@ -412,15 +419,11 @@ public static void trackAppOpen(Activity activity) {
412419
}
413420

414421
public static void trackAppInstall() {
415-
if (!getDebug() && TalkablePreferencesStore.isAppInstallTracked()) {
422+
if (!TalkablePreferencesStore.isAppInstallTracked()) {
416423
return;
417424
}
418425

419426
String eventId = TalkablePreferencesStore.getAndroidId();
420-
if (getDebug()) {
421-
eventId = UUID.randomUUID().toString();
422-
}
423-
424427
Event event = new Event(eventId, Origin.APP_INSTALL_EVENT_CATEGORY);
425428
TalkableApi.createOrigin(event, new Callback2<Origin, Offer>() {
426429
@Override

sdk/src/main/java/com/talkable/sdk/TalkableDeepLinking.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void track(Map<String, String> params) {
3737
return;
3838
}
3939
trackVisit(params.get(VISITOR_OFFER_KEY));
40-
if (Talkable.getDebug() || !TalkablePreferencesStore.isAppInstallTracked()) {
40+
if (!TalkablePreferencesStore.isAppInstallTracked()) {
4141
trackAppInstall(params.get(UUID_KEY));
4242
}
4343
}
@@ -99,9 +99,6 @@ private static void trackAppInstall(String uuid) {
9999
TalkablePreferencesStore.setAlternateUUID(uuid);
100100

101101
String eventId = TalkablePreferencesStore.getAndroidId();
102-
if (Talkable.getDebug()) {
103-
eventId = UUID.randomUUID().toString();
104-
}
105102
Event event = new Event(eventId, Origin.APP_INSTALL_EVENT_CATEGORY);
106103
TalkableApi.createOrigin(event, new Callback2<Origin, Offer>() {
107104
@Override

sdk/src/main/java/com/talkable/sdk/TalkablePreferencesStore.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.talkable.sdk.utils.PreferencesStore;
1212

1313
import java.util.Set;
14+
import java.util.UUID;
1415

1516
public class TalkablePreferencesStore {
1617
private static final String SHARED_PREFERENCES_NAME = "TKBL_PREFERENCES";
@@ -29,11 +30,15 @@ public static void initialize(Context context) {
2930
if (isInitialized()) {
3031
return;
3132
}
32-
33-
setAndroidId(context);
3433
setPreferencesStore(context);
34+
if (Talkable.getDebug()) {
35+
preferencesStore.putBoolean(APP_INSTALLED_KEY, false);
36+
setAndroidId(Talkable.getDebugDeviceId());
37+
} else {
38+
setAndroidId(context);
39+
}
3540
cleanupOfferWebData();
36-
if (getMainUUID() == null) {
41+
if (Talkable.getDebug() || getMainUUID() == null) {
3742
generateMainUuid();
3843
}
3944
}
@@ -59,6 +64,10 @@ private static void setAndroidId(Context context) {
5964
androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
6065
}
6166

67+
private static void setAndroidId(String customAndroidId) {
68+
androidId = customAndroidId;
69+
}
70+
6271
public static String getAndroidId() {
6372
return androidId;
6473
}

sdk/src/main/java/com/talkable/sdk/models/Reward.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,28 @@ public enum Status {
1616
Double amount;
1717
@SerializedName("coupon_code") String couponCode;
1818
Status status;
19+
20+
public String getReason() {
21+
return reason;
22+
}
23+
24+
public String getIncentiveType() {
25+
return incentiveType;
26+
}
27+
28+
public String getIncentiveDescription() {
29+
return incentiveDescription;
30+
}
31+
32+
public Double getAmount() {
33+
return amount;
34+
}
35+
36+
public String getCouponCode() {
37+
return couponCode;
38+
}
39+
40+
public Status getStatus() {
41+
return status;
42+
}
1943
}

sdk/src/test/java/com/talkable/sdk/TalkableApiUnitTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ public void onSuccess(final SocialOfferShare createdShare, Reward reward) {
285285
@Override
286286
public void onSuccess(Reward[] rewards) {
287287
assertEquals(rewards.length, 1);
288+
assertEquals(rewards[0].getCouponCode(), "AD_3_OFF");
289+
assertEquals(rewards[0].getAmount(), 3, 0);
290+
assertEquals(rewards[0].getReason(), "shared");
288291

289292
r.done();
290293
}

0 commit comments

Comments
 (0)