Skip to content

Commit

Permalink
make survey prompt optional via metadata flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Grayson Wendell committed Feb 8, 2016
1 parent c7c747f commit dff7f0d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/mixpanel/android/mpmetrics/MPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public synchronized void setSSLSocketFactory(SSLSocketFactory factory) {
mDisableAppOpenEvent = metaData.getBoolean("com.mixpanel.android.MPConfig.DisableAppOpenEvent", true);
mDisableViewCrawler = metaData.getBoolean("com.mixpanel.android.MPConfig.DisableViewCrawler", false);
mDisableDecideChecker = metaData.getBoolean("com.mixpanel.android.MPConfig.DisableDecideChecker", false);
mShouldPromptForSurvey = metaData.getBoolean("com.mixpanel.android.MPConfig.ShouldPromptForSurvey", true);

// Disable if EITHER of these is present and false, otherwise enable
final boolean surveysAutoCheck = metaData.getBoolean("com.mixpanel.android.MPConfig.AutoCheckForSurveys", true);
Expand Down Expand Up @@ -250,7 +251,8 @@ public synchronized void setSSLSocketFactory(SSLSocketFactory factory) {
" PeopleFallbackEndpoint " + getPeopleFallbackEndpoint() + "\n" +
" DecideFallbackEndpoint " + getDecideFallbackEndpoint() + "\n" +
" EditorUrl " + getEditorUrl() + "\n" +
" DisableDecideChecker " + getDisableDecideChecker() + "\n"
" DisableDecideChecker " + getDisableDecideChecker() + "\n" +
" ShouldPromptForSurvey " + getShouldPromptForSurvey() + "\n"
);
}
}
Expand Down Expand Up @@ -349,6 +351,10 @@ public boolean getDisableDecideChecker() {
return mDisableDecideChecker;
}

public boolean getShouldPromptForSurvey() {
return mShouldPromptForSurvey;
}

// Pre-configured package name for resources, if they differ from the application package name
//
// mContext.getPackageName() actually returns the "application id", which
Expand Down Expand Up @@ -408,6 +414,7 @@ public synchronized SSLSocketFactory getSSLSocketFactory() {
private final String mEditorUrl;
private final String mResourcePackageName;
private final boolean mDisableDecideChecker;
private final boolean mShouldPromptForSurvey;

// Mutable, with synchronized accessor and mutator
private SSLSocketFactory mSSLSocketFactory;
Expand Down
48 changes: 28 additions & 20 deletions src/main/java/com/mixpanel/android/surveys/SurveyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,34 @@ private void onStartSurvey() {
trackSurveyAttempted();
}

final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setTitle(R.string.com_mixpanel_android_survey_prompt_dialog_title);
alertBuilder.setMessage(R.string.com_mixpanel_android_survey_prompt_dialog_message);
alertBuilder.setPositiveButton(R.string.com_mixpanel_android_sure, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SurveyActivity.this.findViewById(R.id.com_mixpanel_android_activity_survey_id).setVisibility(View.VISIBLE);
mSurveyBegun = true;
showQuestion(mCurrentQuestion);
}
});
alertBuilder.setNegativeButton(R.string.com_mixpanel_android_no_thanks, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SurveyActivity.this.finish();
}
});
alertBuilder.setCancelable(false);
mDialog = alertBuilder.create();
mDialog.show();
if (MPConfig.getInstance(this).getShouldPromptForSurvey()) {
final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setTitle(R.string.com_mixpanel_android_survey_prompt_dialog_title);
alertBuilder.setMessage(R.string.com_mixpanel_android_survey_prompt_dialog_message);
alertBuilder.setPositiveButton(R.string.com_mixpanel_android_sure, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startSurvey();
}
});
alertBuilder.setNegativeButton(R.string.com_mixpanel_android_no_thanks, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SurveyActivity.this.finish();
}
});
alertBuilder.setCancelable(false);
mDialog = alertBuilder.create();
mDialog.show();
} else {
startSurvey();
}
}

private void startSurvey() {
SurveyActivity.this.findViewById(R.id.com_mixpanel_android_activity_survey_id).setVisibility(View.VISIBLE);
mSurveyBegun = true;
showQuestion(mCurrentQuestion);
}

@Override
Expand Down

0 comments on commit dff7f0d

Please sign in to comment.