Introduces a Listener for CallLogQueryHandler.
Change-Id: Ib009a1a20a708ee94e203cae1dc5a3307f10e1fb
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 9f64815..2d28bda 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. */
@@ -836,7 +837,7 @@
mVoiceMailNumber = ((TelephonyManager) getActivity().getSystemService(
Context.TELEPHONY_SERVICE)).getVoiceMailNumber();
- mCallLogQueryHandler = new CallLogQueryHandler(this);
+ mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(), this);
mCurrentCountryIso = ContactsUtils.getCurrentCountryIso(getActivity());
@@ -844,6 +845,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;
@@ -863,6 +865,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;
@@ -1099,12 +1102,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);
+ }
+}