diff options
Diffstat (limited to 'src/com/android')
5 files changed, 225 insertions, 45 deletions
diff --git a/src/com/android/dialer/calllog/BlockReportSpamListener.java b/src/com/android/dialer/calllog/BlockReportSpamListener.java new file mode 100644 index 000000000..bda4ee538 --- /dev/null +++ b/src/com/android/dialer/calllog/BlockReportSpamListener.java @@ -0,0 +1,158 @@ +package com.android.dialer.calllog; + +import android.app.AlertDialog; +import android.content.ContentValues; +import android.content.Context; +import android.content.DialogInterface; +import android.net.Uri; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.CheckBox; + +import com.android.dialer.database.FilteredNumberAsyncQueryHandler; +import com.android.dialer.service.ExtendedCallInfoService; +import com.android.dialer.R; + +/** + * Listener to show dialogs for block and report spam actions. + */ +public class BlockReportSpamListener implements CallLogListItemViewHolder.OnClickListener { + + private final Context mContext; + private final RecyclerView.Adapter mAdapter; + private final ExtendedCallInfoService mExtendedCallInfoService; + private final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; + + public BlockReportSpamListener(Context context, RecyclerView.Adapter adapter, + ExtendedCallInfoService extendedCallInfoService, + FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler) { + mContext = context; + mAdapter = adapter; + mExtendedCallInfoService = extendedCallInfoService; + mFilteredNumberAsyncQueryHandler = filteredNumberAsyncQueryHandler; + } + + @Override + public void onBlockReportSpam(String displayNumber, final String number, + final String countryIso, final int callType) { + final View dialogView = View.inflate(mContext, R.layout.block_report_spam_dialog, null); + + AlertDialog.Builder alertDialogBuilder = createDialogBuilder(); + alertDialogBuilder + .setView(dialogView) + .setTitle(mContext.getString( + R.string.block_report_number_alert_title, displayNumber)) + .setPositiveButton(mContext.getString(R.string.block_number_ok), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + CheckBox isSpamCheckbox = (CheckBox) dialogView + .findViewById(R.id.report_number_as_spam_action); + if (isSpamCheckbox.isChecked()) { + mExtendedCallInfoService.reportSpam( + number, countryIso, callType); + } + mFilteredNumberAsyncQueryHandler.blockNumber( + new FilteredNumberAsyncQueryHandler.OnBlockNumberListener() { + @Override + public void onBlockComplete(Uri uri) { + mAdapter.notifyDataSetChanged(); + } + }, + number, + countryIso); + } + }); + alertDialogBuilder.show(); + } + + @Override + public void onBlock(String displayNumber, final String number, final String countryIso, + final int callType) { + AlertDialog.Builder alertDialogBuilder = createDialogBuilder(); + alertDialogBuilder + .setTitle(mContext.getString( + R.string.block_report_number_alert_title, displayNumber)) + .setMessage(R.string.block_number_alert_details) + .setPositiveButton(mContext.getString(R.string.block_number_ok), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mExtendedCallInfoService.reportSpam(number, countryIso, callType); + mFilteredNumberAsyncQueryHandler.blockNumber( + new FilteredNumberAsyncQueryHandler.OnBlockNumberListener() { + @Override + public void onBlockComplete(Uri uri) { + mAdapter.notifyDataSetChanged(); + } + }, + number, + countryIso); + } + }); + alertDialogBuilder.show(); + } + + @Override + public void onUnblock(String displayNumber, final String number, final String countryIso, + final Integer blockId, final boolean isSpam, final int callType) { + AlertDialog.Builder alertDialogBuilder = createDialogBuilder(); + if (isSpam) { + alertDialogBuilder.setMessage(R.string.unblock_number_alert_details); + } + alertDialogBuilder + .setTitle(mContext.getString( + R.string.unblock_report_number_alert_title, displayNumber)) + .setPositiveButton(R.string.unblock_number_ok, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (isSpam) { + mExtendedCallInfoService.reportNotSpam( + number, countryIso, callType); + } + mFilteredNumberAsyncQueryHandler.unblock( + new FilteredNumberAsyncQueryHandler.OnUnblockNumberListener() { + @Override + public void onUnblockComplete(int rows, ContentValues values) { + mAdapter.notifyDataSetChanged(); + } + }, + blockId); + } + }); + alertDialogBuilder.show(); + } + + @Override + public void onReportNotSpam(String displayNumber, final String number, final String countryIso, + final int callType) { + AlertDialog.Builder alertDialogBuilder = createDialogBuilder(); + alertDialogBuilder + .setTitle(mContext.getString( + R.string.report_not_spam_alert_title, displayNumber)) + .setMessage(R.string.report_not_spam_alert_details) + .setPositiveButton(R.string.report_not_spam_alert_button, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mExtendedCallInfoService.reportNotSpam( + number, countryIso, callType); + mAdapter.notifyDataSetChanged(); + } + }); + alertDialogBuilder.show(); + } + + private AlertDialog.Builder createDialogBuilder() { + return new AlertDialog.Builder(mContext) + .setCancelable(true) + .setNegativeButton(mContext.getString(android.R.string.cancel), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + } +} diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index e826867ab..506dafdf8 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -16,14 +16,15 @@ package com.android.dialer.calllog; -import com.android.dialer.compat.FilteredNumberCompat; import com.android.dialer.filterednumber.BlockNumberDialogFragment; import com.android.dialer.service.ExtendedCallInfoService; import com.android.dialerbind.ObjectFactory; import com.google.common.annotations.VisibleForTesting; -import android.app.Activity; +import android.app.AlertDialog; +import android.content.ContentValues; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; @@ -44,6 +45,7 @@ import android.view.View; import android.view.View.AccessibilityDelegate; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; +import android.widget.CheckBox; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.compat.CompatUtils; @@ -70,8 +72,7 @@ import java.util.HashMap; */ public class CallLogAdapter extends GroupingListAdapter implements CallLogGroupBuilder.GroupCreator, - VoicemailPlaybackPresenter.OnVoicemailDeletedListener, - CallLogListItemViewHolder.OnClickListener { + VoicemailPlaybackPresenter.OnVoicemailDeletedListener { // Types of activities the call log adapter is used for public static final int ACTIVITY_TYPE_CALL_LOG = 1; @@ -140,6 +141,7 @@ public class CallLogAdapter extends GroupingListAdapter public void onChangeFilteredNumberUndo() { } }; + private CallLogListItemViewHolder.OnClickListener mBlockReportSpamListener; /** * Hashmap, keyed by call Id, used to track the day group for a call. As call log entries are @@ -319,6 +321,8 @@ public class CallLogAdapter extends GroupingListAdapter maybeShowVoicemailPromoCard(); mExtendedCallInfoService = ObjectFactory.newExtendedCallInfoService(context); + mBlockReportSpamListener = new BlockReportSpamListener(mContext, this, + mExtendedCallInfoService, mFilteredNumberAsyncQueryHandler); setHasStableIds(true); } @@ -336,36 +340,6 @@ public class CallLogAdapter extends GroupingListAdapter } } - @Override - public void onBlockReportSpam(String number, String countryIso, String displayNumber) { - mExtendedCallInfoService.reportSpam(number, countryIso); - notifyDataSetChanged(); - } - - @Override - public void onBlock(String number, String countryIso, String displayNumber) { - FilteredNumberCompat - .showBlockNumberDialogFlow(mContext.getContentResolver(), null, number, - countryIso, displayNumber, R.id.floating_action_button_container, - ((Activity) mContext).getFragmentManager(), - mBlockedNumberDialogCallback); - } - - @Override - public void onUnblock(String number, String countryIso, Integer blockId, String displayNumber) { - FilteredNumberCompat - .showBlockNumberDialogFlow(mContext.getContentResolver(), blockId, number, - countryIso, displayNumber, R.id.floating_action_button_container, - ((Activity) mContext).getFragmentManager(), - mBlockedNumberDialogCallback); - } - - @Override - public void onReportNotSpam(String number, String countryIso, String displayNumber) { - mExtendedCallInfoService.reportNotSpam(number, countryIso); - notifyDataSetChanged(); - } - /** * Requery on background thread when {@link Cursor} changes. */ @@ -442,7 +416,7 @@ public class CallLogAdapter extends GroupingListAdapter CallLogListItemViewHolder viewHolder = CallLogListItemViewHolder.create( view, mContext, - this, + mBlockReportSpamListener, mExpandCollapseListener, mCallLogCache, mCallLogListItemHelper, diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 53e6fbba8..aaa9dc83b 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -54,6 +54,7 @@ import com.android.dialer.calllog.calllogcache.CallLogCache; import com.android.dialer.compat.FilteredNumberCompat; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.filterednumber.BlockNumberDialogFragment; +import com.android.dialer.filterednumber.BlockedNumbersMigrator; import com.android.dialer.filterednumber.FilteredNumbersUtil; import com.android.dialer.logging.Logger; import com.android.dialer.logging.ScreenEvent; @@ -73,10 +74,12 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder View.OnCreateContextMenuListener { public interface OnClickListener { - void onBlockReportSpam(String number, String countryIso, String displayNumber); - void onBlock(String number, String countryIso, String displayNumber); - void onUnblock(String number, String countryIso, Integer blockId, String displayNumber); - void onReportNotSpam(String number, String countryIso, String displayNumber); + void onBlockReportSpam( + String displayNumber, String number, String countryIso, int callType); + void onBlock(String displayNumber, String number, String countryIso, int callType); + void onUnblock(String displayNumber, String number, String countryIso, Integer blockId, + boolean isSpam, int callType); + void onReportNotSpam(String displayNumber, String number, String countryIso, int callType); } /** The root view of the call log list item */ @@ -672,13 +675,25 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder numberType, /* phone number type (e.g. mobile) in second line of contact view */ accountHandle); } else if (view.getId() == R.id.block_report_action) { - mBlockReportListener.onBlockReportSpam(number, countryIso, displayNumber); + maybeShowBlockNumberMigrationDialog(new BlockedNumbersMigrator.Listener() { + @Override + public void onComplete() { + mBlockReportListener.onBlockReportSpam( + displayNumber, number, countryIso, callType); + } + }); } else if (view.getId() == R.id.block_action) { - mBlockReportListener.onBlock(number, countryIso, displayNumber); + maybeShowBlockNumberMigrationDialog(new BlockedNumbersMigrator.Listener() { + @Override + public void onComplete() { + mBlockReportListener.onBlock(displayNumber, number, countryIso, callType); + } + }); } else if (view.getId() == R.id.unblock_action) { - mBlockReportListener.onUnblock(number, countryIso, blockId, displayNumber); + mBlockReportListener.onUnblock( + displayNumber, number, countryIso, blockId, isSpam, callType); } else if (view.getId() == R.id.report_not_spam_action) { - mBlockReportListener.onReportNotSpam(number, countryIso, displayNumber); + mBlockReportListener.onReportNotSpam(displayNumber, number, countryIso, callType); } else { final IntentProvider intentProvider = (IntentProvider) view.getTag(); if (intentProvider != null) { @@ -691,6 +706,14 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder } } + private void maybeShowBlockNumberMigrationDialog(BlockedNumbersMigrator.Listener listener) { + if (!FilteredNumberCompat.maybeShowBlockNumberMigrationDialog( + mContext.getContentResolver(), + ((Activity) mContext).getFragmentManager(), listener)) { + listener.onComplete(); + } + } + @NeededForTesting public static CallLogListItemViewHolder createForTest(Context context) { Resources resources = context.getResources(); diff --git a/src/com/android/dialer/compat/FilteredNumberCompat.java b/src/com/android/dialer/compat/FilteredNumberCompat.java index 91563dc0d..ea994c977 100644 --- a/src/com/android/dialer/compat/FilteredNumberCompat.java +++ b/src/com/android/dialer/compat/FilteredNumberCompat.java @@ -238,6 +238,27 @@ public class FilteredNumberCompat { } /** + * Shows block number migration dialog if necessary. + * + * @param fragmentManager The {@link FragmentManager} used to show fragments. + * @param listener The {@link BlockedNumbersMigrator.Listener} to call when migration is + * complete. + * @return boolean True if migration dialog is shown. + */ + public static boolean maybeShowBlockNumberMigrationDialog( + ContentResolver contentResolver, FragmentManager fragmentManager, + BlockedNumbersMigrator.Listener listener) { + if (shouldShowMigrationDialog(true)) { + Log.i(TAG, "maybeShowBlockNumberMigrationDialog - showing migration dialog"); + MigrateBlockedNumbersDialogFragment + .newInstance(new BlockedNumbersMigrator(contentResolver), listener) + .show(fragmentManager, "MigrateBlockedNumbers"); + return true; + } + return false; + } + + /** * Shows the flow of {@link android.app.DialogFragment}s for blocking or unblocking numbers. * * @param blockId The id into the blocked numbers database. diff --git a/src/com/android/dialer/service/ExtendedCallInfoService.java b/src/com/android/dialer/service/ExtendedCallInfoService.java index 412cece74..0bf5badd3 100644 --- a/src/com/android/dialer/service/ExtendedCallInfoService.java +++ b/src/com/android/dialer/service/ExtendedCallInfoService.java @@ -44,13 +44,17 @@ public interface ExtendedCallInfoService { * Reports number as spam. * @param number The number to be reported. * @param countryIso The country ISO of the number. + * @param callType Whether the type of call is missed, voicemail, etc. Example of this is + * {@link android.provider.CallLog.Calls#VOICEMAIL_TYPE}. */ - void reportSpam(String number, String countryIso); + void reportSpam(String number, String countryIso, int callType); /** * Reports number as not spam. * @param number The number to be reported. * @param countryIso The country ISO of the number. + * @param callType Whether the type of call is missed, voicemail, etc. Example of this is + * {@link android.provider.CallLog.Calls#VOICEMAIL_TYPE}. */ - void reportNotSpam(String number, String countryIso); + void reportNotSpam(String number, String countryIso, int callType); } |