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

make survey prompt optional via metadata flag #290

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
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