Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change apikey site slug #9

Open
wants to merge 10 commits into
base: change_apikey
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions app/src/main/java/com/talkable/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static com.talkable.sdk.Talkable.UUID_KEY;
import static com.talkable.sdk.Talkable.VISITOR_OFFER_KEY;
import static com.talkable.sdk.Talkable.DEFAULT_SERVER;

public class MainActivity extends Activity {

Expand All @@ -37,11 +38,12 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

Talkable.trackAppOpen(this);
Talkable.setServer(DEFAULT_SERVER);
dgtv marked this conversation as resolved.
Show resolved Hide resolved
}

public void onAffiliateMemberClick(View view) {
Talkable.setServer("https://www.talkable.com");
Talkable.setSiteSlug("android");
dgtv marked this conversation as resolved.
Show resolved Hide resolved
updateTalkableCredentials();

AffiliateMember affiliateMember = new AffiliateMember(getCustomer());
affiliateMember.setCampaignTag("android-fragments");
Expand All @@ -59,6 +61,7 @@ public void run() {
}

public void onPurchaseClick(View view) {
updateTalkableCredentials();
TalkableApi.createOrigin(buildPurchase(), new Callback2<Origin, Offer>() {
@Override
public void onSuccess(Origin purchase, Offer offer) {
Expand Down Expand Up @@ -102,6 +105,8 @@ public void onEventClick(View view) {
Event event = new Event(eventNumber, eventCategory, subtotal, coupons);
event.setCustomer(getCustomer());

updateTalkableCredentials();

TalkableApi.createOrigin(event, new Callback2<Origin, Offer>() {
@Override
public void onSuccess(Origin origin, Offer offer) {
Expand All @@ -119,6 +124,8 @@ public void onAffiliateMemberViaApiClick(View view) {
AffiliateMember affiliateMember = new AffiliateMember();
affiliateMember.setCustomer(getCustomer());

updateTalkableCredentials();

TalkableApi.createOrigin(affiliateMember, new Callback2<Origin, Offer>() {
@Override
public void onSuccess(Origin origin, Offer offer) {
Expand All @@ -133,6 +140,8 @@ public void onError(ApiError error) {
}

public void getRewardsClick(View view) {
updateTalkableCredentials();

TalkableApi.retrieveRewards(new Callback1<Reward[]>() {
@Override
public void onSuccess(Reward[] rewards) {
Expand Down Expand Up @@ -201,8 +210,8 @@ public void run() {
}

public void onPostPurchaseClick(View view) {
Talkable.setServer("https://www.talkable.com");
Talkable.setSiteSlug("android");
dgtv marked this conversation as resolved.
Show resolved Hide resolved
setApiKeyAndSiteSlugIfNeeded();
dgtv marked this conversation as resolved.
Show resolved Hide resolved

Talkable.showOffer(MainActivity.this, buildPurchase(), new TalkableErrorCallback<TalkableOfferLoadException>() {
@Override
Expand All @@ -229,6 +238,34 @@ public void onDeepLinkingClick(View view) {
if (offerId.length() > 0) {
paramsMap.put(VISITOR_OFFER_KEY, offerId);
}

updateTalkableCredentials();

TalkableDeepLinking.track(paramsMap);
}

private void updateTalkableCredentials() {
setServerIfNeeded();
setApiKeyAndSiteSlugIfNeeded();
}

private void setApiKeyAndSiteSlugIfNeeded() {
EditText siteSlugText = findViewById(R.id.siteSlugText);
String siteSlug = siteSlugText.getText().toString();
EditText apiKeyText = findViewById(R.id.apiKeyText);
String apiKey = apiKeyText.getText().toString();

if (siteSlug.length() > 0 && apiKey.length() > 0) {
dgtv marked this conversation as resolved.
Show resolved Hide resolved
Talkable.updateCredentials(apiKey, siteSlug);
}
}

private void setServerIfNeeded() {
EditText serverText = findViewById(R.id.serverText);
dgtv marked this conversation as resolved.
Show resolved Hide resolved
String server = serverText.getText().toString();

if (server.length() > 0 && server != DEFAULT_SERVER) {
dgtv marked this conversation as resolved.
Show resolved Hide resolved
Talkable.setServer(server);
}
}
}
49 changes: 48 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,61 @@
android:text="" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:id="@+id/siteSlugTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/offerIDTextLayout"
android:hint="Site Slug">

<android.support.design.widget.TextInputEditText
android:id="@+id/siteSlugText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:id="@+id/apiKeyTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/siteSlugTextLayout"
android:hint="Api Key">

<android.support.design.widget.TextInputEditText
android:id="@+id/apiKeyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:id="@+id/serverTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/apiKeyTextLayout"
android:hint="Server">

<android.support.design.widget.TextInputEditText
android:id="@+id/serverText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="https://www.talkable.com" />
</android.support.design.widget.TextInputLayout>

<Button
android:id="@+id/eventBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/offerIDTextLayout"
android:layout_below="@+id/serverTextLayout"
android:layout_marginTop="5pt"
android:onClick="onEventClick"
android:text="@string/eventBtnLabel" />
Expand Down