From 486ee39d0791d290411290af6d2e54f37436b09f Mon Sep 17 00:00:00 2001 From: Gilles Franck Mevaa Date: Tue, 16 Feb 2016 14:10:03 -0800 Subject: DO NOT MERGE: Listener of spam events Getting rid of the Manager to have the ButtonRenderer directly communicate changes to an event listener. Implementation changes in ag/863096. Cherry picking to nyc-dev to fix build. Change-Id: I8061116f0b91e3f5a6a3a6eac09fe2171ebcbd5c --- res/drawable/blocked_contact.xml | 2 +- res/values/colors.xml | 2 +- res/values/strings.xml | 3 + src/com/android/dialer/calllog/CallLogAdapter.java | 28 +++++++++- .../dialer/calllog/CallLogListItemViewHolder.java | 54 +++++++++++++----- .../service/ExtendedBlockingButtonRenderer.java | 64 +++++++++++++++++++--- .../dialer/service/ExtendedBlockingManager.java | 38 ------------- src/com/android/dialerbind/ObjectFactory.java | 9 +-- 8 files changed, 129 insertions(+), 71 deletions(-) delete mode 100644 src/com/android/dialer/service/ExtendedBlockingManager.java diff --git a/res/drawable/blocked_contact.xml b/res/drawable/blocked_contact.xml index 2e7343710..0957585b4 100644 --- a/res/drawable/blocked_contact.xml +++ b/res/drawable/blocked_contact.xml @@ -25,7 +25,7 @@ - diff --git a/res/values/colors.xml b/res/values/colors.xml index 75d05ac99..38fd6b39a 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -124,7 +124,7 @@ #D8D8D8 - #afafaf + @android:color/holo_red_dark @color/dialtacts_primary_text_color @color/dialtacts_secondary_text_color #616161 diff --git a/res/values/strings.xml b/res/values/strings.xml index ed88b960f..6d2bd5ef5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -995,4 +995,7 @@ Phone app does not have permission to write to system settings. + + + Blocked diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index af77d8621..372c7bd9b 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -35,6 +35,8 @@ import android.telecom.PhoneAccountHandle; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import android.text.TextUtils; +import android.util.ArrayMap; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.AccessibilityDelegate; @@ -54,18 +56,20 @@ import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.filterednumber.BlockNumberDialogFragment.Callback; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; +import com.android.dialer.service.ExtendedBlockingButtonRenderer; import com.android.dialer.util.PhoneNumberUtil; import com.android.dialer.voicemail.VoicemailPlaybackPresenter; -import com.android.incallui.CallerInfo; import java.util.HashMap; +import java.util.Map; /** * Adapter class to fill in data for the Call Log. */ public class CallLogAdapter extends GroupingListAdapter implements CallLogGroupBuilder.GroupCreator, - VoicemailPlaybackPresenter.OnVoicemailDeletedListener { + VoicemailPlaybackPresenter.OnVoicemailDeletedListener, + ExtendedBlockingButtonRenderer.Listener { /** Interface used to initiate a refresh of the content. */ public interface CallFetcher { @@ -93,6 +97,7 @@ public class CallLogAdapter extends GroupingListAdapter protected final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter; private final CallFetcher mCallFetcher; private final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; + private final Map mBlockedNumberCache = new ArrayMap<>(); protected ContactInfoCache mContactInfoCache; @@ -293,6 +298,24 @@ public class CallLogAdapter extends GroupingListAdapter } } + @Override + public void onBlockedNumber(String number,String countryIso) { + String cacheKey = PhoneNumberUtils.formatNumberToE164(number, countryIso); + if (!TextUtils.isEmpty(cacheKey)) { + mBlockedNumberCache.put(cacheKey, true); + notifyDataSetChanged(); + } + } + + @Override + public void onUnblockedNumber( String number, String countryIso) { + String cacheKey = PhoneNumberUtils.formatNumberToE164(number, countryIso); + if (!TextUtils.isEmpty(cacheKey)) { + mBlockedNumberCache.put(cacheKey, false); + notifyDataSetChanged(); + } + } + /** * Requery on background thread when {@link Cursor} changes. */ @@ -364,6 +387,7 @@ public class CallLogAdapter extends GroupingListAdapter CallLogListItemViewHolder viewHolder = CallLogListItemViewHolder.create( view, mContext, + this, mExpandCollapseListener, mCallLogCache, mCallLogListItemHelper, diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index e60dd2728..cfc937547 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -27,9 +27,11 @@ import android.provider.ContactsContract.CommonDataKinds.Phone; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.telecom.PhoneAccountHandle; +import android.telephony.PhoneNumberUtils; import android.text.BidiFormatter; import android.text.TextDirectionHeuristics; import android.text.TextUtils; +import android.util.Log; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; @@ -63,8 +65,9 @@ import com.android.dialer.voicemail.VoicemailPlaybackPresenter; import com.android.dialerbind.ObjectFactory; import com.google.common.collect.Lists; -import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Set; /** * This is an object containing references to views contained by the call log list item. This @@ -74,7 +77,7 @@ import java.util.List; */ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, MenuItem.OnMenuItemClickListener, - View.OnCreateContextMenuListener { + View.OnCreateContextMenuListener { /** The root view of the call log list item */ public final View rootView; @@ -196,23 +199,29 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder */ public ContactInfo info; + /** + * Whether the current log entry is a blocked number or not. Used in updatePhoto() + */ + public boolean isBlocked; + private final Context mContext; private final CallLogCache mCallLogCache; private final CallLogListItemHelper mCallLogListItemHelper; private final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter; private final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; + private final BlockNumberDialogFragment.Callback mFilteredNumberDialogCallback; private final int mPhotoSize; - private ViewStub mExtendedBlockingViewStub; - private ExtendedBlockingButtonRenderer mExtendedBlockingButtonRenderer; + private final ExtendedBlockingButtonRenderer mExtendedBlockingButtonRenderer; private View.OnClickListener mExpandCollapseListener; private boolean mVoicemailPrimaryActionButtonClicked; private CallLogListItemViewHolder( Context context, + ExtendedBlockingButtonRenderer.Listener eventListener, View.OnClickListener expandCollapseListener, CallLogCache callLogCache, CallLogListItemHelper callLogListItemHelper, @@ -244,7 +253,6 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder this.dayGroupHeader = dayGroupHeader; this.primaryActionButtonView = primaryActionButtonView; this.workIconView = (ImageView) rootView.findViewById(R.id.work_profile_icon); - Resources resources = mContext.getResources(); mPhotoSize = mContext.getResources().getDimensionPixelSize(R.dimen.contact_photo_size); @@ -259,20 +267,23 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder primaryActionButtonView.setOnClickListener(this); primaryActionView.setOnClickListener(mExpandCollapseListener); primaryActionView.setOnCreateContextMenuListener(this); + mExtendedBlockingButtonRenderer = + ObjectFactory.newExtendedBlockingButtonRenderer(mContext, eventListener); } public static CallLogListItemViewHolder create( View view, Context context, + ExtendedBlockingButtonRenderer.Listener eventListener, View.OnClickListener expandCollapseListener, CallLogCache callLogCache, CallLogListItemHelper callLogListItemHelper, VoicemailPlaybackPresenter voicemailPlaybackPresenter, FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler, BlockNumberDialogFragment.Callback filteredNumberDialogCallback) { - return new CallLogListItemViewHolder( context, + eventListener, expandCollapseListener, callLogCache, callLogListItemHelper, @@ -415,8 +426,6 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder mExtendedBlockingViewStub = (ViewStub) actionsView.findViewById(R.id.extended_blocking_actions_container); - mExtendedBlockingButtonRenderer = ObjectFactory - .newExtendedBlockingButtonRenderer(mContext, mExtendedBlockingViewStub); } bindActionButtons(); @@ -556,13 +565,22 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder callWithNoteButtonView, detailsButtonView, voicemailPlaybackView); - List blockedNumberVisibleViews = new ArrayList<>(); + + List blockedNumberVisibleViews = Lists.newArrayList(detailsButtonView); List extendedBlockingVisibleViews = Lists.newArrayList(detailsButtonView); - mExtendedBlockingButtonRenderer.setCompleteListItemViews(completeLogListItems); - mExtendedBlockingButtonRenderer.setFilteredNumberViews(blockedNumberVisibleViews); - mExtendedBlockingButtonRenderer.setExtendedFilteredViews(extendedBlockingVisibleViews); - mExtendedBlockingButtonRenderer.render(number, countryIso); + ExtendedBlockingButtonRenderer.ViewHolderInfo viewHolderInfo = + new ExtendedBlockingButtonRenderer.ViewHolderInfo( + completeLogListItems, + extendedBlockingVisibleViews, + blockedNumberVisibleViews, + number, + countryIso, + nameOrNumber.toString(), + displayNumber); + mExtendedBlockingButtonRenderer.setViewHolderInfo(viewHolderInfo); + + mExtendedBlockingButtonRenderer.render(mExtendedBlockingViewStub); } } @@ -607,6 +625,13 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder public void updatePhoto() { quickContactView.assignContactUri(info.lookupUri); + if (isBlocked && !TextUtils.isEmpty(number) /* maybe a private number ? */) { + quickContactView.setImageDrawable(mContext.getDrawable(R.drawable.blocked_contact)); + phoneCallDetailsViews.callLocationAndDate.setText( + mContext.getString(R.string.blocked_number_call_log_label)); + return; + } + final boolean isVoicemail = mCallLogCache.isVoicemailNumber(accountHandle, number); int contactType = ContactPhotoManager.TYPE_DEFAULT; if (isVoicemail) { @@ -670,6 +695,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder CallLogListItemViewHolder viewHolder = new CallLogListItemViewHolder( context, + null, null /* expandCollapseListener */, callLogCache, new CallLogListItemHelper(phoneCallDetailsHelper, resources, callLogCache), @@ -689,4 +715,4 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder return viewHolder; } -} +} \ No newline at end of file diff --git a/src/com/android/dialer/service/ExtendedBlockingButtonRenderer.java b/src/com/android/dialer/service/ExtendedBlockingButtonRenderer.java index 9ce844776..5ff373288 100644 --- a/src/com/android/dialer/service/ExtendedBlockingButtonRenderer.java +++ b/src/com/android/dialer/service/ExtendedBlockingButtonRenderer.java @@ -1,6 +1,24 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.android.dialer.service; +import android.support.annotation.Nullable; import android.view.View; +import android.view.ViewStub; import java.util.List; @@ -9,15 +27,47 @@ import java.util.List; */ public interface ExtendedBlockingButtonRenderer { - /** - * Renders buttons for a phone number. - */ - void render(String number, String countryIso); + final class ViewHolderInfo { - void setCompleteListItemViews(List views); + public final List completeListItemViews; + public final List extendedBlockedViews; + public final List blockedNumberViews; + public final String phoneNumber; + public final String countryIso; + public final String nameOrNumber; + public final String displayNumber; - void setExtendedFilteredViews(List views); + public ViewHolderInfo( + /* All existing views amongst the list item actions, even if invisible */ + List completeListItemViews, + /* Views that should be seen if the number is in the blacklist */ + List extendedBlockedViews, + /* Views that should be seen if the number is in the extended blacklist */ + List blockedNumberViews, + String phoneNumber, + String countryIso, + String nameOrNumber, + String displayNumber) { - void setFilteredNumberViews(List views); + this.completeListItemViews = completeListItemViews; + this.extendedBlockedViews = extendedBlockedViews; + this.blockedNumberViews = blockedNumberViews; + this.phoneNumber = phoneNumber; + this.countryIso = countryIso; + this.nameOrNumber = nameOrNumber; + this.displayNumber = displayNumber; + } + } + + interface Listener { + void onBlockedNumber(String number, @Nullable String countryIso); + void onUnblockedNumber(String number, @Nullable String countryIso); + } + + /** + * Renders buttons for a phone number. + */ + void render(ViewStub viewStub); + void setViewHolderInfo(ViewHolderInfo info); } diff --git a/src/com/android/dialer/service/ExtendedBlockingManager.java b/src/com/android/dialer/service/ExtendedBlockingManager.java deleted file mode 100644 index 3257a72c5..000000000 --- a/src/com/android/dialer/service/ExtendedBlockingManager.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.service; - -import android.support.annotation.Nullable; - -/** - * Manager of extended blocking events. It notifies all listeners of all blocking-related events. - */ -public interface ExtendedBlockingManager { - - interface ButtonRendererListener { - void onBlockedNumber(String number, @Nullable String countryIso); - void onUnblockedNumber(String number, @Nullable String countryIso); - } - - void addButtonRendererListener(@Nullable ButtonRendererListener listener); - - void removeButtonRendererListener(@Nullable ButtonRendererListener listener); - - void notifyOnBlockedNumber(String number, @Nullable String countryIso); - - void notifyOnUnblockedNumber(String number, @Nullable String countryIso); -} diff --git a/src/com/android/dialerbind/ObjectFactory.java b/src/com/android/dialerbind/ObjectFactory.java index 51b8fbc44..31255a26d 100644 --- a/src/com/android/dialerbind/ObjectFactory.java +++ b/src/com/android/dialerbind/ObjectFactory.java @@ -27,7 +27,6 @@ import com.android.dialer.calllog.ContactInfoHelper; import com.android.dialer.list.RegularSearchFragment; import com.android.dialer.logging.Logger; import com.android.dialer.service.CachedNumberLookupService; -import com.android.dialer.service.ExtendedBlockingManager; import com.android.dialer.service.ExtendedBlockingButtonRenderer; import com.android.dialer.voicemail.VoicemailPlaybackPresenter; @@ -47,13 +46,7 @@ public class ObjectFactory { @Nullable public static ExtendedBlockingButtonRenderer newExtendedBlockingButtonRenderer( - Context context, - ViewStub stub) { - return null; - } - - @Nullable - public static ExtendedBlockingManager getExtendedBlockingManager() { + Context context, ExtendedBlockingButtonRenderer.Listener listener) { return null; } -- cgit v1.2.3