Move "Report" to CallDetailActivity.

- Delete old report button/handling code.
+ Convert menu click listeners into single onMenuItemClick method.
+ Add and populate objectId on PhoneCallDetails, to be able to
tell from the CallDetailActivity whether to enable reporting.

Change-Id: Ie4b9a3c1835792cbba04dc826f71fd2e53071400
diff --git a/res/layout/call_log_list_item_actions.xml b/res/layout/call_log_list_item_actions.xml
index 569048b..d4c9706 100644
--- a/res/layout/call_log_list_item_actions.xml
+++ b/res/layout/call_log_list_item_actions.xml
@@ -98,18 +98,4 @@
 
     </LinearLayout>
 
-    <LinearLayout
-        android:id="@+id/report_action"
-        style="@style/CallLogActionStyle">
-
-        <ImageView
-            style="@style/CallLogActionIconStyle"
-            android:src="@drawable/ic_report_problem_24dp" />
-
-        <TextView
-            style="@style/CallLogActionTextStyle"
-            android:text="@string/call_log_action_report" />
-
-    </LinearLayout>
-
 </LinearLayout>
diff --git a/res/menu/call_details_options.xml b/res/menu/call_details_options.xml
index b98ec9e..f08b4fa 100644
--- a/res/menu/call_details_options.xml
+++ b/res/menu/call_details_options.xml
@@ -18,17 +18,17 @@
     <item android:id="@+id/menu_trash"
         android:icon="@drawable/ic_delete_24dp"
         android:showAsAction="ifRoom"
-        android:title="@string/recentCalls_trashVoicemail"
-        android:onClick="onMenuTrashVoicemail" />
+        android:title="@string/recentCalls_trashVoicemail" />
 
     <item android:id="@+id/menu_remove_from_call_log"
         android:icon="@drawable/ic_delete_24dp"
         android:showAsAction="ifRoom"
-        android:title="@string/recentCalls_removeFromRecentList"
-        android:onClick="onMenuRemoveFromCallLog" />
+        android:title="@string/recentCalls_removeFromRecentList" />
 
     <item android:id="@+id/menu_edit_number_before_call"
-        android:title="@string/recentCalls_editNumberBeforeCall"
-        android:onClick="onMenuEditNumberBeforeCall" />
+        android:title="@string/recentCalls_editNumberBeforeCall" />
+
+    <item android:id="@+id/menu_report"
+        android:title="@string/call_detail_menu_report" />
 
 </menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b852be8..648d5e8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -47,6 +47,10 @@
         <xliff:g id="name">%s</xliff:g>
     </string>
 
+    <!-- Text for a menu item to report a call as having been incorrectly identified.
+         [CHAR LIMIT=30] -->
+    <string name="call_detail_menu_report">Report inaccurate number</string>
+
     <!-- Menu item used to copy a number from the call log to the dialer so it can be edited before calling it -->
     <string name="recentCalls_editNumberBeforeCall">Edit number before call</string>
 
@@ -631,21 +635,10 @@
         Call details for <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g>
     </string>
 
-    <!-- Description for the "report" action for an entry in the call log. This action reports that
-         the phone number lookup performed for the entry was inaccurate. [CHAR LIMIT=NONE] -->
-    <string name="description_report_action">
-        Report <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g>
-    </string>
-
     <!-- Toast message which appears when a call log entry is deleted.
          [CHAR LIMIT=NONE] -->
     <string name="toast_entry_removed">Deleted from call history</string>
 
-    <!-- Button text for the "report" button displayed underneath an entry in the call log.
-         Tapping causes the call log entry to be reported to Google as a bad id.
-         [CHAR LIMIT=30] -->
-    <string name="call_log_action_report">Report</string>
-
     <!-- String used as a header in the call log above calls which occurred today.
          [CHAR LIMIT=65] -->
     <string name="call_log_header_today">Today</string>
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index 15ba5df..b851372 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -70,7 +70,8 @@
  * This activity can be either started with the URI of a single call log entry, or with the
  * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
  */
-public class CallDetailActivity extends Activity {
+public class CallDetailActivity extends Activity
+        implements MenuItem.OnMenuItemClickListener {
     private static final String TAG = "CallDetail";
 
      /** A long array extra containing ids of call log entries to display. */
@@ -152,8 +153,8 @@
 
             mHasEditNumberBeforeCallOption =
                     canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber;
-            mHasTrashOption = hasVoicemail();
-            mHasRemoveFromCallLogOption = !hasVoicemail();
+            mHasReportMenuOption = mContactInfoHelper.canReportAsInvalid(
+                    firstDetails.sourceType, firstDetails.objectId);
             invalidateOptionsMenu();
 
             ListView historyList = (ListView) findViewById(R.id.history);
@@ -208,7 +209,7 @@
     private View mCallButton;
     private ContactInfoHelper mContactInfoHelper;
 
-    private String mNumber;
+    protected String mNumber;
     private boolean mIsVoicemailNumber;
     private String mDefaultCountryIso;
 
@@ -222,10 +223,7 @@
 
     /** Whether we should show "edit number before call" in the options menu. */
     private boolean mHasEditNumberBeforeCallOption;
-    /** Whether we should show "trash" in the options menu. */
-    private boolean mHasTrashOption;
-    /** Whether we should show "remove from call log" in the options menu. */
-    private boolean mHasRemoveFromCallLogOption;
+    private boolean mHasReportMenuOption;
 
     @Override
     protected void onCreate(Bundle icicle) {
@@ -270,7 +268,10 @@
     @Override
     public void onResume() {
         super.onResume();
+        getCallDetails();
+    }
 
+    public void getCallDetails() {
         CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
     }
 
@@ -327,30 +328,44 @@
     public boolean onPrepareOptionsMenu(Menu menu) {
         // This action deletes all elements in the group from the call log.
         // We don't have this action for voicemails, because you can just use the trash button.
-        menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption);
-        menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption);
-        menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption);
+        menu.findItem(R.id.menu_remove_from_call_log)
+                .setVisible(!hasVoicemail())
+                .setOnMenuItemClickListener(this);
+        menu.findItem(R.id.menu_edit_number_before_call)
+                .setVisible(mHasEditNumberBeforeCallOption)
+                .setOnMenuItemClickListener(this);
+        menu.findItem(R.id.menu_trash)
+                .setVisible(hasVoicemail())
+                .setOnMenuItemClickListener(this);
+        menu.findItem(R.id.menu_report)
+                .setVisible(mHasReportMenuOption)
+                .setOnMenuItemClickListener(this);
         return super.onPrepareOptionsMenu(menu);
     }
 
-    public void onMenuRemoveFromCallLog(MenuItem menuItem) {
-        final StringBuilder callIds = new StringBuilder();
-        for (Uri callUri : getCallLogEntryUris()) {
-            if (callIds.length() != 0) {
-                callIds.append(",");
-            }
-            callIds.append(ContentUris.parseId(callUri));
+    @Override
+    public boolean onMenuItemClick(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.menu_remove_from_call_log:
+                final StringBuilder callIds = new StringBuilder();
+                for (Uri callUri : getCallLogEntryUris()) {
+                    if (callIds.length() != 0) {
+                        callIds.append(",");
+                    }
+                    callIds.append(ContentUris.parseId(callUri));
+                }
+                CallLogAsyncTaskUtil.deleteCalls(
+                        this, callIds.toString(), mCallLogAsyncTaskListener);
+                break;
+            case R.id.menu_edit_number_before_call:
+                startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)));
+                break;
+            case R.id.menu_trash:
+                CallLogAsyncTaskUtil.deleteVoicemail(
+                        this, mVoicemailUri, mCallLogAsyncTaskListener);
+                break;
         }
-
-        CallLogAsyncTaskUtil.deleteCalls(this, callIds.toString(), mCallLogAsyncTaskListener);
-    }
-
-    public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
-        startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)));
-    }
-
-    public void onMenuTrashVoicemail(MenuItem menuItem) {
-        CallLogAsyncTaskUtil.deleteVoicemail(this, mVoicemailUri, mCallLogAsyncTaskListener);
+        return true;
     }
 
     private void closeSystemDialogs() {
diff --git a/src/com/android/dialer/PhoneCallDetails.java b/src/com/android/dialer/PhoneCallDetails.java
index 68fdadc..add6315 100644
--- a/src/com/android/dialer/PhoneCallDetails.java
+++ b/src/com/android/dialer/PhoneCallDetails.java
@@ -60,6 +60,7 @@
     public CharSequence numberLabel;
     // The URI of the contact associated with this phone call.
     public Uri contactUri;
+
     /**
      * The photo URI of the picture of the contact that is associated with this phone call or
      * null if there is none.
@@ -71,6 +72,9 @@
     // The source type of the contact associated with this call.
     public int sourceType;
 
+    // The object id type of the contact associated with this call.
+    public String objectId;
+
     // The unique identifier for the account associated with the call.
     public PhoneAccountHandle accountHandle;
 
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index daa7350..69fbb03 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -59,11 +59,6 @@
         public void fetchCalls();
     }
 
-    /** Implements onClickListener for the report button. */
-    public interface OnReportButtonClickListener {
-        public void onReportButtonClick(String number);
-    }
-
     private static final int VIEW_TYPE_SHOW_CALL_HISTORY_LIST_ITEM = 10;
     private static final int NO_EXPANDED_LIST_ITEM = -1;
 
@@ -71,7 +66,6 @@
     private final ContactInfoHelper mContactInfoHelper;
     private final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter;
     private final CallFetcher mCallFetcher;
-    private final OnReportButtonClickListener mOnReportButtonClickListener;
     private ViewTreeObserver mViewTreeObserver = null;
 
     protected ContactInfoCache mContactInfoCache;
@@ -143,7 +137,7 @@
 
             if (viewHolder.getAdapterPosition() == mCurrentlyExpandedPosition) {
                 // Hide actions, if the clicked item is the expanded item.
-                viewHolder.showActions(false, mOnReportButtonClickListener);
+                viewHolder.showActions(false);
                 mCurrentlyExpandedPosition = RecyclerView.NO_POSITION;
                 mCurrentlyExpandedRowId = NO_EXPANDED_LIST_ITEM;
             } else {
@@ -160,7 +154,7 @@
             notifyItemChanged(mCurrentlyExpandedPosition);
         }
         // Show the actions for the clicked list item.
-        viewHolder.showActions(true, mOnReportButtonClickListener);
+        viewHolder.showActions(true);
         mCurrentlyExpandedPosition = viewHolder.getAdapterPosition();
         mCurrentlyExpandedRowId = viewHolder.rowId;
     }
@@ -207,8 +201,7 @@
             CallFetcher callFetcher,
             ContactInfoHelper contactInfoHelper,
             VoicemailPlaybackPresenter voicemailPlaybackPresenter,
-            boolean isShowingRecentsTab,
-            OnReportButtonClickListener onReportButtonClickListener) {
+            boolean isShowingRecentsTab) {
         super(context);
 
         mContext = context;
@@ -216,7 +209,6 @@
         mContactInfoHelper = contactInfoHelper;
         mVoicemailPlaybackPresenter = voicemailPlaybackPresenter;
         mIsShowingRecentsTab = isShowingRecentsTab;
-        mOnReportButtonClickListener = onReportButtonClickListener;
 
         mContactInfoCache = new ContactInfoCache(
                 mContactInfoHelper, mOnContactInfoChangedListener);
@@ -394,6 +386,7 @@
             details.numberLabel = info.label;
             details.photoUri = info.photoUri;
             details.sourceType = info.sourceType;
+            details.objectId = info.objectId;
         }
 
         CallLogListItemViewHolder views = (CallLogListItemViewHolder) viewHolder;
@@ -408,11 +401,6 @@
         // Stash away the Ids of the calls so that we can support deleting a row in the call log.
         views.callIds = getCallIds(c, count);
 
-        // The entry can only be reported as invalid if it has a valid ID and the source of the
-        // entry supports marking entries as invalid.
-        views.canBeReportedAsInvalid = mContactInfoHelper.canReportAsInvalid(
-                info.sourceType, info.objectId);
-
         // Default case: an item in the call log.
         views.primaryActionView.setVisibility(View.VISIBLE);
 
@@ -431,7 +419,7 @@
         if (mCurrentlyExpandedRowId == views.rowId) {
             mCurrentlyExpandedPosition = position;
         }
-        views.showActions(mCurrentlyExpandedPosition == position, mOnReportButtonClickListener);
+        views.showActions(mCurrentlyExpandedPosition == position);
         views.updateCallButton();
 
         String nameForDefaultImage = null;
diff --git a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
index 97fc324..812e1a7 100644
--- a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
+++ b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
@@ -170,9 +170,10 @@
             details.numberLabel = info.label;
             details.photoUri = info.photoUri;
             details.sourceType = info.sourceType;
+            details.objectId = info.objectId;
 
             details.callTypes = new int[] {
-                    cursor.getInt(CallDetailQuery.CALL_TYPE_COLUMN_INDEX)
+                cursor.getInt(CallDetailQuery.CALL_TYPE_COLUMN_INDEX)
             };
             details.date = cursor.getLong(CallDetailQuery.DATE_COLUMN_INDEX);
             details.duration = cursor.getLong(CallDetailQuery.DURATION_COLUMN_INDEX);
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index d57d87a..6f9767c 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -64,12 +64,9 @@
  * (all, missed or voicemails), specify it in the constructor.
  */
 public class CallLogFragment extends Fragment
-        implements CallLogQueryHandler.Listener, CallLogAdapter.OnReportButtonClickListener,
-        CallLogAdapter.CallFetcher {
+        implements CallLogQueryHandler.Listener, CallLogAdapter.CallFetcher {
     private static final String TAG = "CallLogFragment";
 
-    private static final String REPORT_DIALOG_TAG = "report_dialog";
-
     /**
      * ID of the empty loader to defer other fragments.
      */
@@ -278,8 +275,7 @@
                 this,
                 new ContactInfoHelper(getActivity(), currentCountryIso),
                 mVoicemailPlaybackPresenter,
-                isShowingRecentsTab,
-                this);
+                isShowingRecentsTab);
         mRecyclerView.setAdapter(mAdapter);
 
         fetchCalls();
@@ -445,20 +441,4 @@
             CallLogNotificationsHelper.updateVoicemailNotifications(getActivity());
         }
     }
-
-    public void onBadDataReported(String number) {
-        if (number == null) {
-            return;
-        }
-        mAdapter.invalidateCache();
-        mAdapter.notifyDataSetChanged();
-    }
-
-    public void onReportButtonClick(String number) {
-        DialogFragment df = ObjectFactory.getReportDialogFragment(number);
-        if (df != null) {
-            df.setTargetFragment(this, 0);
-            df.show(getActivity().getFragmentManager(), REPORT_DIALOG_TAG);
-        }
-    }
 }
diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java
index 6e3e8b5..d088107 100644
--- a/src/com/android/dialer/calllog/CallLogListItemHelper.java
+++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java
@@ -104,10 +104,6 @@
         views.detailsButtonView.setContentDescription(
                 TextUtils.expandTemplate(
                         mResources.getString(R.string.description_details_action), nameOrNumber));
-
-        views.reportButtonView.setContentDescription(
-                TextUtils.expandTemplate(
-                        mResources.getString(R.string.description_report_action), nameOrNumber));
     }
 
     /**
diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
index 5125247..987bcb8 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
@@ -77,7 +77,6 @@
     public View addToExistingContactButtonView;
     public View sendMessageView;
     public View detailsButtonView;
-    public View reportButtonView;
 
     /**
      * The row Id for the first call associated with the call log entry.  Used as a key for the
@@ -129,12 +128,6 @@
     public CharSequence nameOrNumber;
 
     /**
-     * Whether or not the contact info can be marked as invalid from the source where
-     * it was obtained.
-     */
-    public boolean canBeReportedAsInvalid;
-
-    /**
      * The contact info for the contact displayed in this list item.
      */
     public ContactInfo info;
@@ -222,8 +215,7 @@
      *
      * @param callLogItem The call log list item view.
      */
-    public void inflateActionViewStub(
-            final CallLogAdapter.OnReportButtonClickListener onReportButtonClickListener) {
+    public void inflateActionViewStub() {
         ViewStub stub = (ViewStub) rootView.findViewById(R.id.call_log_entry_actions_stub);
         if (stub != null) {
             actionsView = (ViewGroup) stub.inflate();
@@ -246,16 +238,6 @@
 
             detailsButtonView = actionsView.findViewById(R.id.details_action);
             detailsButtonView.setOnClickListener(mActionListener);
-
-            reportButtonView = actionsView.findViewById(R.id.report_action);
-            reportButtonView.setOnClickListener(new View.OnClickListener() {
-                @Override
-                public void onClick(View v) {
-                    if (onReportButtonClickListener != null) {
-                        onReportButtonClickListener.onReportButtonClick(number);
-                    }
-                }
-            });
         }
 
         bindActionButtons();
@@ -327,12 +309,6 @@
         detailsButtonView.setTag(
                 IntentProvider.getCallDetailIntentProvider(rowId, callIds, null));
 
-        if (canBeReportedAsInvalid && !info.isBadData) {
-            reportButtonView.setVisibility(View.VISIBLE);
-        } else {
-            reportButtonView.setVisibility(View.GONE);
-        }
-
         if (info != null && UriUtils.isEncodedContactUri(info.lookupUri)) {
             createNewContactButtonView.setTag(IntentProvider.getAddContactIntentProvider(
                     info.lookupUri, info.name, info.number, info.type, true /* isNewContact */));
@@ -356,13 +332,12 @@
      *
      * If the action views have never been shown yet for this view, inflate the view stub.
      */
-    public void showActions(boolean show,
-            final CallLogAdapter.OnReportButtonClickListener onReportButtonClickListener) {
+    public void showActions(boolean show) {
         expandVoicemailTranscriptionView(show);
 
         if (show) {
             // Inflate the view stub if necessary, and wire up the event handlers.
-            inflateActionViewStub(onReportButtonClickListener);
+            inflateActionViewStub();
 
             actionsView.setVisibility(View.VISIBLE);
             actionsView.setAlpha(1.0f);
@@ -438,7 +413,6 @@
                 new TextView(context),
                 new View(context));
         viewHolder.detailsButtonView = new TextView(context);
-        viewHolder.reportButtonView = new TextView(context);
         viewHolder.actionsView = new View(context);
         viewHolder.voicemailPlaybackView = new VoicemailPlaybackLayout(context);
 
diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
index 942a73f..3c9fa1d 100644
--- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
+++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
@@ -32,7 +32,6 @@
 import android.util.Log;
 
 import com.android.common.io.MoreCloseables;
-import com.android.dialer.CallDetailActivity;
 import com.android.dialer.R;
 import com.android.dialer.calllog.PhoneAccountUtils;
 import com.google.common.collect.Maps;
diff --git a/src/com/android/dialerbind/ObjectFactory.java b/src/com/android/dialerbind/ObjectFactory.java
index 43b237c..1a36b05 100644
--- a/src/com/android/dialerbind/ObjectFactory.java
+++ b/src/com/android/dialerbind/ObjectFactory.java
@@ -18,11 +18,9 @@
 
 import static com.android.dialer.calllog.CallLogAdapter.CallFetcher;
 
-import android.app.DialogFragment;
 import android.content.Context;
 
 import com.android.dialer.calllog.CallLogAdapter;
-import com.android.dialer.calllog.CallLogAdapter.OnReportButtonClickListener;
 import com.android.dialer.calllog.ContactInfoHelper;
 import com.android.dialer.service.CachedNumberLookupService;
 import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
@@ -49,18 +47,12 @@
             CallFetcher callFetcher,
             ContactInfoHelper contactInfoHelper,
             VoicemailPlaybackPresenter voicemailPlaybackPresenter,
-            boolean isShowingRecentsTab,
-            OnReportButtonClickListener onReportButtonClickListener) {
+            boolean isShowingRecentsTab) {
         return new CallLogAdapter(
                 context,
                 callFetcher,
                 contactInfoHelper,
                 voicemailPlaybackPresenter,
-                isShowingRecentsTab,
-                onReportButtonClickListener);
-    }
-
-    public static DialogFragment getReportDialogFragment(String number) {
-        return null;
+                isShowingRecentsTab);
     }
 }
diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java
index 14e0aaf..b4162e1 100644
--- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java
+++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java
@@ -204,7 +204,7 @@
     private static final class TestCallLogAdapter extends CallLogAdapter {
         public TestCallLogAdapter(Context context, CallFetcher callFetcher,
                 ContactInfoHelper contactInfoHelper) {
-            super(context, callFetcher, contactInfoHelper, null, false, null);
+            super(context, callFetcher, contactInfoHelper, null, false);
             mContactInfoCache = new TestContactInfoCache(
                     contactInfoHelper, mOnContactInfoChangedListener);
         }
diff --git a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java
index 3f66d58..df6719c 100644
--- a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java
+++ b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java
@@ -453,7 +453,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
-                viewHolder.inflateActionViewStub(null);
+                viewHolder.inflateActionViewStub();
             }
         });
         getInstrumentation().waitForIdleSync();