Merge "Introduces a Listener for CallLogQueryHandler."
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index f059292..046988b 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -72,7 +72,8 @@
 /**
  * Displays a list of call log entries.
  */
-public class CallLogFragment extends ListFragment implements ViewPagerVisibilityListener {
+public class CallLogFragment extends ListFragment implements ViewPagerVisibilityListener,
+        CallLogQueryHandler.Listener {
     private static final String TAG = "CallLogFragment";
 
     /** The size of the cache of contact info. */
@@ -829,7 +830,7 @@
 
         mVoiceMailNumber = ((TelephonyManager) getActivity().getSystemService(
                 Context.TELEPHONY_SERVICE)).getVoiceMailNumber();
-        mCallLogQueryHandler = new CallLogQueryHandler(this);
+        mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(), this);
 
         mCurrentCountryIso = ContactsUtils.getCurrentCountryIso(getActivity());
 
@@ -837,6 +838,7 @@
     }
 
     /** Called by the CallLogQueryHandler when the list of calls has been fetched or updated. */
+    @Override
     public void onCallsFetched(Cursor cursor) {
         if (getActivity() == null || getActivity().isFinishing()) {
             return;
@@ -856,6 +858,7 @@
     /**
      * Called by {@link CallLogQueryHandler} after a successful query to voicemail status provider.
      */
+    @Override
     public void onVoicemailStatusFetched(Cursor statusCursor) {
         if (getActivity() == null || getActivity().isFinishing()) {
             return;
@@ -1092,12 +1095,12 @@
 
     @Override
     public void onListItemClick(ListView l, View v, int position, long id) {
-        Intent intent = new Intent(getActivity(), CallDetailActivity.class);
         Cursor cursor = (Cursor) mAdapter.getItem(position);
         if (CallLogQuery.isSectionHeader(cursor)) {
             // Do nothing when a header is clicked.
             return;
         }
+        Intent intent = new Intent(getActivity(), CallDetailActivity.class);
         if (mAdapter.isGroupHeader(position)) {
             // We want to restore the position in the cursor at the end.
             int currentPosition = cursor.getPosition();
diff --git a/src/com/android/contacts/calllog/CallLogQueryHandler.java b/src/com/android/contacts/calllog/CallLogQueryHandler.java
index fdf55b9..d2905c1 100644
--- a/src/com/android/contacts/calllog/CallLogQueryHandler.java
+++ b/src/com/android/contacts/calllog/CallLogQueryHandler.java
@@ -21,6 +21,7 @@
 import com.android.contacts.voicemail.VoicemailStatusHelperImpl;
 
 import android.content.AsyncQueryHandler;
+import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.database.Cursor;
 import android.database.MatrixCursor;
@@ -54,7 +55,7 @@
     /** The token for the query to fetch voicemail status messages. */
     private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 56;
 
-    private final WeakReference<CallLogFragment> mFragment;
+    private final WeakReference<Listener> mListener;
 
     /** The cursor containing the new calls, or null if they have not yet been fetched. */
     @GuardedBy("this") private Cursor mNewCallsCursor;
@@ -91,9 +92,9 @@
         return new CatchingWorkerHandler(looper);
     }
 
-    public CallLogQueryHandler(CallLogFragment fragment) {
-        super(fragment.getActivity().getContentResolver());
-        mFragment = new WeakReference<CallLogFragment>(fragment);
+    public CallLogQueryHandler(ContentResolver contentResolver, Listener listener) {
+        super(contentResolver);
+        mListener = new WeakReference<Listener>(listener);
     }
 
     /** Creates a cursor that contains a single row and maps the section to the given value. */
@@ -268,16 +269,28 @@
      * Updates the adapter in the call log fragment to show the new cursor data.
      */
     private void updateAdapterData(Cursor combinedCursor) {
-        final CallLogFragment fragment = mFragment.get();
-        if (fragment != null) {
-            fragment.onCallsFetched(combinedCursor);
+        final Listener listener = mListener.get();
+        if (listener != null) {
+            listener.onCallsFetched(combinedCursor);
         }
     }
 
     private void updateVoicemailStatus(Cursor statusCursor) {
-        final CallLogFragment fragment = mFragment.get();
-        if (fragment != null) {
-            fragment.onVoicemailStatusFetched(statusCursor);
+        final Listener listener = mListener.get();
+        if (listener != null) {
+            listener.onVoicemailStatusFetched(statusCursor);
         }
     }
-}
\ No newline at end of file
+
+    /** Listener to completion of various queries. */
+    public interface Listener {
+        /** Called when {@link CallLogQueryHandler#fetchVoicemailStatus()} completes. */
+        void onVoicemailStatusFetched(Cursor statusCursor);
+
+        /**
+         * Called when {@link CallLogQueryHandler#fetchAllCalls()} or
+         * {@link CallLogQueryHandler#fetchVoicemailOnly()} complete.
+         */
+        void onCallsFetched(Cursor combinedCursor);
+    }
+}