summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/contactactions/SharedModules.java
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2018-02-12 09:58:34 -0800
committerCopybara-Service <copybara-piper@google.com>2018-02-14 17:47:47 -0800
commit86135a2f4d9b6dc5facf5e33e554c23a31824c41 (patch)
tree0947e18c2998df21d07ca68fceff35fae87185cd /java/com/android/dialer/contactactions/SharedModules.java
parent70f98d3997c42c7d4e3b3e3920659aca78820d14 (diff)
Add bottom sheet options for blocked and/or spam numbers in the new call log.
Bug: 70989605 Test: ModulesTest PiperOrigin-RevId: 185392711 Change-Id: I709a1e307925f1c99d2740ed52dc2b7784bca986
Diffstat (limited to 'java/com/android/dialer/contactactions/SharedModules.java')
-rw-r--r--java/com/android/dialer/contactactions/SharedModules.java156
1 files changed, 144 insertions, 12 deletions
diff --git a/java/com/android/dialer/contactactions/SharedModules.java b/java/com/android/dialer/contactactions/SharedModules.java
index 7e72863aa..6d97fcb61 100644
--- a/java/com/android/dialer/contactactions/SharedModules.java
+++ b/java/com/android/dialer/contactactions/SharedModules.java
@@ -20,14 +20,15 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.ContactsContract;
-import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
+import android.widget.Toast;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.clipboard.ClipboardUtils;
import com.android.dialer.util.IntentUtil;
import com.android.dialer.util.UriUtils;
import java.util.List;
+import java.util.Locale;
/**
* Modules for the bottom sheet that are shared between NewVoicemailFragment and NewCallLogFragment
@@ -37,10 +38,15 @@ public class SharedModules {
public static void maybeAddModuleForAddingToContacts(
Context context,
List<ContactActionModule> modules,
- @NonNull DialerPhoneNumber number,
- @Nullable String name,
- @Nullable String lookupUri) {
- // TODO(zachh): Only show this for non-spam/blocked numbers.
+ DialerPhoneNumber number,
+ String name,
+ String lookupUri,
+ boolean isBlocked,
+ boolean isSpam) {
+ // Skip showing the menu item for a spam/blocked number.
+ if (isBlocked || isSpam) {
+ return;
+ }
// Skip showing the menu item for existing contacts.
if (isExistingContact(lookupUri)) {
@@ -83,22 +89,148 @@ public class SharedModules {
}
public static void maybeAddModuleForSendingTextMessage(
- Context context, List<ContactActionModule> modules, String originalNumber) {
+ Context context,
+ List<ContactActionModule> modules,
+ String normalizedNumber,
+ boolean isBlocked) {
+ // Don't show the option to send a text message if the number is blocked.
+ if (isBlocked) {
+ return;
+ }
+
// TODO(zachh): There are some conditions where this module should not be shown; consider
- // voicemail, business numbers, blocked numbers, spam numbers, etc.
- if (!TextUtils.isEmpty(originalNumber)) {
+ // voicemail, business numbers, etc.
+
+ if (!TextUtils.isEmpty(normalizedNumber)) {
modules.add(
new IntentModule(
context,
- IntentUtil.getSendSmsIntent(originalNumber),
+ IntentUtil.getSendSmsIntent(normalizedNumber),
R.string.send_a_message,
R.drawable.quantum_ic_message_vd_theme_24));
}
}
+ public static void addModulesHandlingBlockedOrSpamNumber(
+ Context context,
+ List<ContactActionModule> modules,
+ String normalizedNumber,
+ boolean isBlocked,
+ boolean isSpam) {
+ // For a spam number, add two options:
+ // (1) "Not spam" and "Block", or
+ // (2) "Not spam" and "Unblock".
+ if (isSpam) {
+ addModuleForMarkingNumberAsNonSpam(context, modules, normalizedNumber);
+ addModuleForBlockingOrUnblockingNumber(context, modules, normalizedNumber, isBlocked);
+ return;
+ }
+
+ // For a blocked non-spam number, add "Unblock" option.
+ if (isBlocked) {
+ addModuleForBlockingOrUnblockingNumber(context, modules, normalizedNumber, isBlocked);
+ return;
+ }
+
+ // For a number that is neither a spam number nor blocked, add "Block/Report spam" option.
+ addModuleForBlockingNumberAndOptionallyReportingSpam(context, modules, normalizedNumber);
+ }
+
+ private static void addModuleForMarkingNumberAsNonSpam(
+ Context context, List<ContactActionModule> modules, String normalizedNumber) {
+ modules.add(
+ new ContactActionModule() {
+ @Override
+ public int getStringId() {
+ return R.string.not_spam;
+ }
+
+ @Override
+ public int getDrawableId() {
+ return R.drawable.quantum_ic_report_off_vd_theme_24;
+ }
+
+ @Override
+ public boolean onClick() {
+ // TODO(a bug): implement this method.
+ Toast.makeText(
+ context,
+ String.format(Locale.ENGLISH, "TODO: Report %s as non-spam", normalizedNumber),
+ Toast.LENGTH_SHORT)
+ .show();
+ return true; // Close the bottom sheet.
+ }
+ });
+ }
+
+ private static void addModuleForBlockingOrUnblockingNumber(
+ Context context,
+ List<ContactActionModule> modules,
+ String normalizedNumber,
+ boolean isBlocked) {
+ modules.add(
+ new ContactActionModule() {
+ @Override
+ public int getStringId() {
+ return isBlocked ? R.string.unblock_number : R.string.block_number;
+ }
+
+ @Override
+ public int getDrawableId() {
+ return isBlocked
+ ? R.drawable.ic_unblock // TODO(a bug): use a vector icon
+ : R.drawable.quantum_ic_block_vd_theme_24;
+ }
+
+ @Override
+ public boolean onClick() {
+ // TODO(a bug): implement this method.
+ Toast.makeText(
+ context,
+ String.format(
+ Locale.ENGLISH,
+ "TODO: " + (isBlocked ? "Unblock " : "Block ") + " number %s.",
+ normalizedNumber),
+ Toast.LENGTH_SHORT)
+ .show();
+ return true; // Close the bottom sheet.
+ }
+ });
+ }
+
+ private static void addModuleForBlockingNumberAndOptionallyReportingSpam(
+ Context context, List<ContactActionModule> modules, String normalizedNumber) {
+ modules.add(
+ new ContactActionModule() {
+ @Override
+ public int getStringId() {
+ return R.string.block_and_optionally_report_spam;
+ }
+
+ @Override
+ public int getDrawableId() {
+ return R.drawable.quantum_ic_block_vd_theme_24;
+ }
+
+ @Override
+ public boolean onClick() {
+ // TODO(a bug): implement this method.
+ Toast.makeText(
+ context,
+ String.format(
+ Locale.ENGLISH,
+ "TODO: Block and optionally report as spam %s.",
+ normalizedNumber),
+ Toast.LENGTH_SHORT)
+ .show();
+ return true; // Close the bottom sheet.
+ }
+ });
+ }
+
public static void maybeAddModuleForCopyingNumber(
- Context context, List<ContactActionModule> modules, String originalNumber) {
- if (TextUtils.isEmpty(originalNumber)) {
+ Context context, List<ContactActionModule> modules, String normalizedNumber) {
+ if (TextUtils.isEmpty(normalizedNumber)) {
return;
}
modules.add(
@@ -115,7 +247,7 @@ public class SharedModules {
@Override
public boolean onClick() {
- ClipboardUtils.copyText(context, null, originalNumber, true);
+ ClipboardUtils.copyText(context, null, normalizedNumber, true);
return false;
}
});