diff --git a/app/src/main/java/com/talkable/demo/DemoApp.java b/app/src/main/java/com/talkable/demo/DemoApp.java index 7ea2b14..068bdd0 100644 --- a/app/src/main/java/com/talkable/demo/DemoApp.java +++ b/app/src/main/java/com/talkable/demo/DemoApp.java @@ -8,6 +8,6 @@ public class DemoApp extends Application { @Override public void onCreate() { super.onCreate(); - Talkable.initialize(this); + Talkable.initialize(this,null,true,null); } } diff --git a/app/src/main/java/com/talkable/demo/MainActivity.java b/app/src/main/java/com/talkable/demo/MainActivity.java index 150d018..fb3a583 100644 --- a/app/src/main/java/com/talkable/demo/MainActivity.java +++ b/app/src/main/java/com/talkable/demo/MainActivity.java @@ -36,15 +36,16 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + ((EditText)findViewById(R.id.apiKeyText)).setText(Talkable.getApiKey()); + Talkable.trackAppOpen(this); } public void onAffiliateMemberClick(View view) { - Talkable.setServer("https://www.talkable.com"); - Talkable.setSiteSlug("android"); + updateTalkableCredentials(); AffiliateMember affiliateMember = new AffiliateMember(getCustomer()); - affiliateMember.setCampaignTag("android-fragments"); + affiliateMember.setCampaignTag(getCampaignTag()); Talkable.showOffer(this, affiliateMember, OverridenTalkableOfferFragment.class, new TalkableErrorCallback() { @Override public void onError(final TalkableOfferLoadException error) { @@ -59,6 +60,8 @@ public void run() { } public void onPurchaseClick(View view) { + updateTalkableCredentials(); + TalkableApi.createOrigin(buildPurchase(), new Callback2() { @Override public void onSuccess(Origin purchase, Offer offer) { @@ -88,12 +91,14 @@ private Purchase buildPurchase() { item.setUrl("http://test.com/product.html"); purchase.addItem(item); - purchase.setCampaignTag("post-purchase-fragments"); + purchase.setCampaignTag(getCampaignTag()); return purchase; } public void onEventClick(View view) { + updateTalkableCredentials(); + String eventNumber = getOrderNumber(); String eventCategory = getEventCategory(); Double subtotal = getSubtotal(); @@ -116,6 +121,8 @@ public void onError(ApiError error) { } public void onAffiliateMemberViaApiClick(View view) { + updateTalkableCredentials(); + AffiliateMember affiliateMember = new AffiliateMember(); affiliateMember.setCustomer(getCustomer()); @@ -133,6 +140,8 @@ public void onError(ApiError error) { } public void getRewardsClick(View view) { + updateTalkableCredentials(); + TalkableApi.retrieveRewards(new Callback1() { @Override public void onSuccess(Reward[] rewards) { @@ -190,6 +199,11 @@ private String getEventCategory() { return text.getText().toString(); } + private String getCampaignTag() { + EditText text = findViewById(R.id.campaignTagText); + return text.getText().toString(); + } + private void showToast(final String text) { final Activity activity = this; runOnUiThread(new Runnable() { @@ -201,8 +215,7 @@ public void run() { } public void onPostPurchaseClick(View view) { - Talkable.setServer("https://www.talkable.com"); - Talkable.setSiteSlug("android"); + updateTalkableCredentials(); Talkable.showOffer(MainActivity.this, buildPurchase(), new TalkableErrorCallback() { @Override @@ -218,6 +231,8 @@ public void run() { } public void onDeepLinkingClick(View view) { + updateTalkableCredentials(); + EditText webUuidText = findViewById(R.id.webUUIDText); String webUuid = webUuidText.getText().toString(); EditText offerIdText = findViewById(R.id.offerIDText); @@ -229,6 +244,21 @@ public void onDeepLinkingClick(View view) { if (offerId.length() > 0) { paramsMap.put(VISITOR_OFFER_KEY, offerId); } + TalkableDeepLinking.track(paramsMap); } + + private void updateTalkableCredentials() { + String siteSlug = ((EditText)findViewById(R.id.siteSlugText)).getText().toString(); + String apiKey = ((EditText)findViewById(R.id.apiKeyText)).getText().toString(); + String server = ((EditText)findViewById(R.id.serverText)).getText().toString(); + + if (siteSlug.length() > 0 && apiKey.length() > 0) { + Talkable.updateCredentials(apiKey, siteSlug); + } + + if (server.length() > 0) { + Talkable.setServer(server); + } + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ee404c2..1b72113 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -20,13 +20,78 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +