diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-04-18 03:01:22 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-04-18 03:01:22 +0000 |
commit | e24966c56456d4f0239ea5bef9c4ae0ef4c27cad (patch) | |
tree | 16ebff1ec0ab1caf3331d0609a892e45bad32d25 /java/com/android/dialer/spam | |
parent | d92873ffb4f8563294924c7dcf2d8bf840b4ebb5 (diff) | |
parent | 6dfdbbbd85d702c638188ab6be39df4d6621f2d1 (diff) |
Merge "Add spam blocking promotion after showing spam dialog in after-call notification"
Diffstat (limited to 'java/com/android/dialer/spam')
-rw-r--r-- | java/com/android/dialer/spam/promo/SpamBlockingPromoDialogFragment.java | 20 | ||||
-rw-r--r-- | java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java | 81 |
2 files changed, 70 insertions, 31 deletions
diff --git a/java/com/android/dialer/spam/promo/SpamBlockingPromoDialogFragment.java b/java/com/android/dialer/spam/promo/SpamBlockingPromoDialogFragment.java index 0ea17d395..ea54728a6 100644 --- a/java/com/android/dialer/spam/promo/SpamBlockingPromoDialogFragment.java +++ b/java/com/android/dialer/spam/promo/SpamBlockingPromoDialogFragment.java @@ -19,7 +19,9 @@ package com.android.dialer.spam.promo; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; +import android.content.DialogInterface; import android.os.Bundle; +import android.support.annotation.Nullable; /** Dialog for spam blocking on-boarding promotion. */ public class SpamBlockingPromoDialogFragment extends DialogFragment { @@ -29,16 +31,32 @@ public class SpamBlockingPromoDialogFragment extends DialogFragment { /** Called when dialog positive button is pressed. */ protected OnEnableListener positiveListener; - public static DialogFragment newInstance(OnEnableListener positiveListener) { + /** Called when the dialog is dismissed. */ + @Nullable protected DialogInterface.OnDismissListener dismissListener; + + public static DialogFragment newInstance( + OnEnableListener positiveListener, + @Nullable DialogInterface.OnDismissListener dismissListener) { SpamBlockingPromoDialogFragment fragment = new SpamBlockingPromoDialogFragment(); fragment.positiveListener = positiveListener; + fragment.dismissListener = dismissListener; return fragment; } @Override + public void onDismiss(DialogInterface dialog) { + if (dismissListener != null) { + dismissListener.onDismiss(dialog); + } + super.onDismiss(dialog); + } + + @Override public void onPause() { // The dialog is dismissed onPause, i.e. rotation. dismiss(); + dismissListener = null; + positiveListener = null; super.onPause(); } diff --git a/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java b/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java index 56143ce7f..b5bdd74b7 100644 --- a/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java +++ b/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java @@ -18,14 +18,16 @@ package com.android.dialer.spam.promo; import android.app.FragmentManager; import android.content.Context; +import android.content.DialogInterface.OnDismissListener; import android.preference.PreferenceManager; -import android.support.annotation.VisibleForTesting; import android.support.design.widget.Snackbar; import android.view.View; +import android.widget.Toast; import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; import com.android.dialer.spam.SpamSettings; +import com.android.dialer.spam.SpamSettings.ModifySettingListener; /** Helper class for showing spam blocking on-boarding promotions. */ public class SpamBlockingPromoHelper { @@ -42,25 +44,6 @@ public class SpamBlockingPromoHelper { this.spamSettings = spamSettings; } - /** Shows a spam blocking promo dialog with on complete snackbar if all the prerequisites meet. */ - public void showSpamBlockingPromoDialog(View view, FragmentManager fragmentManager) { - if (!shouldShowSpamBlockingPromo()) { - return; - } - - updateLastShowSpamTimestamp(); - Logger.get(context).logImpression(DialerImpression.Type.SPAM_BLOCKING_CALL_LOG_PROMO_SHOWN); - SpamBlockingPromoDialogFragment.newInstance( - () -> { - Logger.get(context) - .logImpression( - DialerImpression.Type.SPAM_BLOCKING_ENABLED_THROUGH_CALL_LOG_PROMO); - spamSettings.modifySpamBlockingSetting( - true, success -> showModifySettingOnCompleteSnackbar(view, success)); - }) - .show(fragmentManager, SpamBlockingPromoDialogFragment.SPAM_BLOCKING_PROMO_DIALOG_TAG); - } - /** * Returns true if we should show a spam blocking promo. * @@ -70,8 +53,7 @@ public class SpamBlockingPromoHelper { * * @return true if we should show a spam blocking promo. */ - @VisibleForTesting - boolean shouldShowSpamBlockingPromo() { + public boolean shouldShowSpamBlockingPromo() { if (!ConfigProviderBindings.get(context).getBoolean(ENABLE_SPAM_BLOCKING_PROMO, false) || !spamSettings.isSpamEnabled() || !spamSettings.isSpamBlockingEnabledByFlag() @@ -88,6 +70,40 @@ public class SpamBlockingPromoHelper { return lastShowMillis == 0 || System.currentTimeMillis() - lastShowMillis > showPeriodMillis; } + /** + * Shows a spam blocking promo dialog. + * + * @param fragmentManager the fragment manager to show the dialog. + * @param modifySettingListener the listener called after spam blocking setting is modified. + * @param onDismissListener the listener called when the dialog is dismissed. + */ + public void showSpamBlockingPromoDialog( + FragmentManager fragmentManager, + ModifySettingListener modifySettingListener, + OnDismissListener onDismissListener) { + updateLastShowSpamTimestamp(); + Logger.get(context).logImpression(DialerImpression.Type.SPAM_BLOCKING_CALL_LOG_PROMO_SHOWN); + SpamBlockingPromoDialogFragment.newInstance( + () -> { + Logger.get(context) + .logImpression( + DialerImpression.Type.SPAM_BLOCKING_ENABLED_THROUGH_CALL_LOG_PROMO); + spamSettings.modifySpamBlockingSetting( + true, + success -> { + if (!success) { + Logger.get(context) + .logImpression( + DialerImpression.Type + .SPAM_BLOCKING_MODIFY_FAILURE_THROUGH_CALL_LOG_PROMO); + } + modifySettingListener.onComplete(success); + }); + }, + onDismissListener) + .show(fragmentManager, SpamBlockingPromoDialogFragment.SPAM_BLOCKING_PROMO_DIALOG_TAG); + } + private void updateLastShowSpamTimestamp() { PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()) .edit() @@ -96,16 +112,12 @@ public class SpamBlockingPromoHelper { } /** - * Shows a modify setting on complete snackbar and a link to redirect to setting page + * Shows a modify setting on complete snackbar and a link to redirect to setting page. * - * @param view the view to attach on-complete notice snackbar - * @param success whether the modify setting operation succceeds + * @param view the view to attach on-complete notice snackbar. + * @param success whether the modify setting operation succceeds. */ - private void showModifySettingOnCompleteSnackbar(View view, boolean success) { - if (!success) { - Logger.get(context) - .logImpression(DialerImpression.Type.SPAM_BLOCKING_MODIFY_FAILURE_THROUGH_CALL_LOG_PROMO); - } + public void showModifySettingOnCompleteSnackbar(View view, boolean success) { String snackBarText = success ? context.getString(R.string.spam_blocking_settings_enable_complete_text) @@ -118,4 +130,13 @@ public class SpamBlockingPromoHelper { context.getResources().getColor(R.color.dialer_snackbar_action_text_color)) .show(); } + + /** Shows a modify setting on complete toast message. */ + public void showModifySettingOnCompleteToast(boolean success) { + String toastText = + success + ? context.getString(R.string.spam_blocking_settings_enable_complete_text) + : context.getString(R.string.spam_blocking_settings_enable_error_text); + Toast.makeText(context, toastText, Toast.LENGTH_LONG).show(); + } } |