diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-03-08 20:26:43 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-03-08 20:26:43 +0000 |
commit | e67eb83476525df47dce254c5c267191668bf042 (patch) | |
tree | f432cab51154071587b7d7fcf55c93796103d368 /java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java | |
parent | d2186758f163f0808379cfdce56223032ed8b437 (diff) | |
parent | e987eb096f40ab987690e9bd10b058ef2dfe2de3 (diff) |
Merge "Implement logic for blocking a number from the new call log's bottom sheet."
Diffstat (limited to 'java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java')
-rw-r--r-- | java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java index f24bb1c06..6b8f81908 100644 --- a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java +++ b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java @@ -21,7 +21,10 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.widget.Toast; +import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; +import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumber; +import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam; +import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForReportingNotSpam; import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnConfirmListener; import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnSpamDialogClickListener; import com.android.dialer.common.Assert; @@ -31,7 +34,6 @@ import com.android.dialer.logging.Logger; import com.android.dialer.protos.ProtoParsers; import com.android.dialer.spam.Spam; import com.android.dialer.spam.SpamComponent; -import java.util.Locale; /** * A {@link BroadcastReceiver} that shows an appropriate dialog upon receiving notifications from @@ -39,6 +41,7 @@ import java.util.Locale; */ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver { + static final String ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER = "show_dialog_to_block_number"; static final String ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM = "show_dialog_to_block_number_and_optionally_report_spam"; static final String ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM = "show_dialog_to_report_not_spam"; @@ -51,6 +54,7 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver { public static IntentFilter getIntentFilter() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM); + intentFilter.addAction(ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER); intentFilter.addAction(ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM); return intentFilter; } @@ -66,6 +70,9 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver { String action = intent.getAction(); switch (Assert.isNotNull(action)) { + case ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER: + showDialogToBlockNumber(context, intent); + break; case ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM: showDialogToBlockNumberAndOptionallyReportSpam(context, intent); break; @@ -87,6 +94,8 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver { intent, EXTRA_DIALOG_INFO, BlockReportSpamDialogInfo.getDefaultInstance()); Spam spam = SpamComponent.get(context).spam(); + FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler = + new FilteredNumberAsyncQueryHandler(context); // Set up the positive listener for the dialog. OnSpamDialogClickListener onSpamDialogClickListener = @@ -111,19 +120,16 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver { dialogInfo.getContactSource()); } - // TODO(a bug): Block the number. - Toast.makeText( - context, - String.format( - Locale.ENGLISH, - "TODO: " + "Block number %s.", - dialogInfo.getNormalizedNumber()), - Toast.LENGTH_SHORT) - .show(); + filteredNumberAsyncQueryHandler.blockNumber( + unused -> + Logger.get(context) + .logImpression(DialerImpression.Type.USER_ACTION_BLOCKED_NUMBER), + dialogInfo.getNormalizedNumber(), + dialogInfo.getCountryIso()); }; // Create and show the dialog. - BlockReportSpamDialogs.BlockReportSpamDialogFragment.newInstance( + DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam.newInstance( dialogInfo.getNormalizedNumber(), spam.isDialogReportSpamCheckedByDefault(), onSpamDialogClickListener, @@ -131,6 +137,35 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver { .show(fragmentManager, BlockReportSpamDialogs.BLOCK_REPORT_SPAM_DIALOG_TAG); } + private void showDialogToBlockNumber(Context context, Intent intent) { + LogUtil.enterBlock("ShowBlockReportSpamDialogReceiver.showDialogToBlockNumber"); + + Assert.checkArgument(intent.hasExtra(EXTRA_DIALOG_INFO)); + BlockReportSpamDialogInfo dialogInfo = + ProtoParsers.getTrusted( + intent, EXTRA_DIALOG_INFO, BlockReportSpamDialogInfo.getDefaultInstance()); + + FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler = + new FilteredNumberAsyncQueryHandler(context); + + // Set up the positive listener for the dialog. + OnConfirmListener onConfirmListener = + () -> { + LogUtil.i("ShowBlockReportSpamDialogReceiver.showDialogToBlockNumber", "block number"); + filteredNumberAsyncQueryHandler.blockNumber( + unused -> + Logger.get(context) + .logImpression(DialerImpression.Type.USER_ACTION_BLOCKED_NUMBER), + dialogInfo.getNormalizedNumber(), + dialogInfo.getCountryIso()); + }; + + // Create and show the dialog. + DialogFragmentForBlockingNumber.newInstance( + dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null) + .show(fragmentManager, BlockReportSpamDialogs.BLOCK_DIALOG_TAG); + } + private void showDialogToReportNotSpam(Context context, Intent intent) { LogUtil.enterBlock("ShowBlockReportSpamDialogReceiver.showDialogToReportNotSpam"); @@ -158,7 +193,7 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver { }; // Create & show the dialog. - BlockReportSpamDialogs.ReportNotSpamDialogFragment.newInstance( + DialogFragmentForReportingNotSpam.newInstance( dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null) .show(fragmentManager, BlockReportSpamDialogs.NOT_SPAM_DIALOG_TAG); } |